Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lung committed Mar 12, 2024
1 parent 8faadb1 commit 5ac7b95
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 72 deletions.
4 changes: 2 additions & 2 deletions src/Event/EventType/Cej/EventTypeCej.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function getPrice(Participant $participant): int
}

$price = match (true) {
$participant instanceof PatrolLeader => (count($participant->patrolParticipants) * 250) + 250,
$participant instanceof PatrolLeader => ($participant->getPatrolParticipantsCount() * 250) + 250,
$participant instanceof Ist => 150,
default => throw new \Exception('Unknown participant class'),
};
Expand All @@ -66,7 +66,7 @@ protected function getPrice(Participant $participant): int
private function getPriceForCzechia(Participant $participant): int
{
return match (true) {
$participant instanceof PatrolLeader => (count($participant->patrolParticipants) + 1) * 6600,
$participant instanceof PatrolLeader => ($participant->getPatrolParticipantsCount() + 1) * 6600,
$participant instanceof Ist => 4100,
default => throw new \Exception('Unknown participant class'),
};
Expand Down
2 changes: 1 addition & 1 deletion src/Event/EventType/Navigamus/EventTypeNavigamus.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function getPrice(Participant $participant): int

return match (true) {
$participant instanceof Ist => 900,
$participant instanceof PatrolLeader => (count($participant->patrolParticipants) + 1) * $patrolPrice,
$participant instanceof PatrolLeader => ($participant->getPatrolParticipantsCount() + 1) * $patrolPrice,
default => throw new \Exception('Unknown participant class'),
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/Export/ExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ public function paidContactDataToCSV(Event $event, User $adminUser): array
(string)$participant->id, // 0
$participant->role?->value ?? '',
match (true) {
$participant instanceof PatrolLeader => (string)count($participant->patrolParticipants),
$participant instanceof TroopLeader => (string)count($participant->troopParticipants),
$participant instanceof PatrolLeader => (string)$participant->getPatrolParticipantsCount(),
$participant instanceof TroopLeader => (string)$participant->getTroopParticipantsCount(),
default => '',
},
$this->translator->trans($participant->contingent ?? ''),
Expand Down
59 changes: 0 additions & 59 deletions tests/Event/EventType/Cej/EventTypeCejTest.php

This file was deleted.

14 changes: 10 additions & 4 deletions tests/Functional/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ class ApiTest extends AppTestCase
{
private const string TEST_EVENT_PREFIX_URL = '/v3/event/test-event-slug';
private const string TEST_PREFIX_URL = '/v3';

public function tearDown(): void
{
restore_error_handler();
restore_exception_handler();
}

#[DataProvider('provideRoutes')]
public function testRoutesWithoutAuth(
Expand Down Expand Up @@ -45,28 +51,28 @@ public static function provideRoutes(): array
return [
'invalid entry code' => [
'POST',
self::TEST_PREFIX_URL . '/entry/randomEntryCode',
self::TEST_PREFIX_URL . '/entry/code/randomEntryCode',
sprintf('{"eventSecret": "%s"}', $eventSecret),
403,
'{"status":"unvalid","reason":"participant not found"}'
],
'invalid event secret' => [
'POST',
self::TEST_PREFIX_URL . '/entry/randomEntryCode',
self::TEST_PREFIX_URL . '/entry/code/randomEntryCode',
'{"eventSecret": "randomSecret"}',
403,
'{"status":"unvalid","reason":"unvalid event secret"}'
],
'first enter' => [
'POST',
self::TEST_PREFIX_URL . '/entry/' . $validEntryCode,
self::TEST_PREFIX_URL . '/entry/code/' . $validEntryCode,
sprintf('{"eventSecret": "%s"}', $eventSecret),
200,
'{}'
],
'second enter' => [
'POST',
self::TEST_PREFIX_URL . '/entry/' . $validEntryCode,
self::TEST_PREFIX_URL . '/entry/code/' . $validEntryCode,
sprintf('{"eventSecret": "%s"}', $eventSecret),
200,
'{}'
Expand Down
33 changes: 29 additions & 4 deletions tests/Unit/Payment/PaymentServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,57 @@
namespace Tests\Unit\Payment;

use kissj\BankPayment\BankPaymentRepository;
use kissj\BankPayment\Banks;
use kissj\BankPayment\BankServiceProvider;
use kissj\FlashMessages\FlashMessagesBySession;
use kissj\Logging\Sentry\SentryCollector;
use kissj\Mailer\Mailer;
use kissj\Mailer\MailerSettings;
use kissj\Participant\ParticipantRepository;
use kissj\Payment\PaymentRepository;
use kissj\Payment\QrCodeService;
use kissj\User\LoginTokenRepository;
use kissj\User\UserRepository;
use kissj\User\UserService;
use Monolog\Logger;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Sentry\State\Hub;
use Slim\Views\Twig;
use Symfony\Contracts\Translation\TranslatorInterface;

class PaymentServiceTest extends TestCase
{
public function testGenerateVariableNumber(): void
{
$mailerMock = new Mailer(
\Mockery::mock(Twig::class),
\Mockery::mock(MailerSettings::class),
\Mockery::mock(QrCodeService::class),
\Mockery::mock(TranslatorInterface::class),
\Mockery::mock(Logger::class),
);
$paymentService = new PaymentServiceExposed(
\Mockery::mock(BankServiceProvider::class),
new BankServiceProvider(
new Banks(),
\Mockery::mock(ContainerInterface::class),
),
\Mockery::mock(BankPaymentRepository::class),
\Mockery::mock(PaymentRepository::class),
\Mockery::mock(ParticipantRepository::class),
\Mockery::mock(UserService::class),
new UserService(
\Mockery::mock(LoginTokenRepository::class),
\Mockery::mock(ParticipantRepository::class),
\Mockery::mock(UserRepository::class),
$mailerMock,
),
\Mockery::mock(FlashMessagesBySession::class),
\Mockery::mock(Mailer::class),
$mailerMock,
\Mockery::mock(TranslatorInterface::class),
\Mockery::mock(Logger::class),
\Mockery::mock(SentryCollector::class),
new SentryCollector(
\Mockery::mock(Hub::class),
),
);

for ($i = 0; $i < 100; $i++) {
Expand Down

0 comments on commit 5ac7b95

Please sign in to comment.