diff --git a/src/Event/EventType/Cej/EventTypeCej.php b/src/Event/EventType/Cej/EventTypeCej.php index d9351d46..a0831dbb 100755 --- a/src/Event/EventType/Cej/EventTypeCej.php +++ b/src/Event/EventType/Cej/EventTypeCej.php @@ -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'), }; @@ -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'), }; diff --git a/src/Event/EventType/Navigamus/EventTypeNavigamus.php b/src/Event/EventType/Navigamus/EventTypeNavigamus.php index 0ebb779c..01890a96 100755 --- a/src/Event/EventType/Navigamus/EventTypeNavigamus.php +++ b/src/Event/EventType/Navigamus/EventTypeNavigamus.php @@ -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'), }; } diff --git a/src/Export/ExportService.php b/src/Export/ExportService.php index cd5b59de..2912b31b 100755 --- a/src/Export/ExportService.php +++ b/src/Export/ExportService.php @@ -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 ?? ''), diff --git a/tests/Event/EventType/Cej/EventTypeCejTest.php b/tests/Event/EventType/Cej/EventTypeCejTest.php deleted file mode 100644 index f2cf2176..00000000 --- a/tests/Event/EventType/Cej/EventTypeCejTest.php +++ /dev/null @@ -1,59 +0,0 @@ -eventTypeCej = new EventTypeCej(); - } - - #[DataProvider('provideGetPrice')] - public function testTransformPayment( - int $expectedPrice, - Participant $participant, - Payment $payment, - ): void { - $this->assertSame($expectedPrice, $this->eventTypeCej->transformPayment($payment, $participant)); - } - - /** - * @return array> - */ - public static function provideGetPrice(): array - { - self::markTestSkipped('TODO make adding participants work'); - - $teamMember = new Participant(); - $teamMember->contingent = EventTypeCej::CONTINGENT_TEAM; - - $ist = new Ist(); - $ist->contingent = EventTypeCej::CONTINGENT_CZECHIA; - - $pps = []; - for ($i = 0; $i < 9; $i++) { - $pps[] = new PatrolParticipant(); - } - - $pl = new PatrolLeader(); - $pl->contingent = EventTypeCej::CONTINGENT_CZECHIA; - $pl->patrolParticipants = $pps; - - return [ - 'team member' => [1450, $teamMember], - 'ist' => [2900, $ist], - ]; - } -} diff --git a/tests/Functional/ApiTest.php b/tests/Functional/ApiTest.php index c92bbb9c..af766acd 100644 --- a/tests/Functional/ApiTest.php +++ b/tests/Functional/ApiTest.php @@ -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( @@ -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, '{}' diff --git a/tests/Unit/Payment/PaymentServiceTest.php b/tests/Unit/Payment/PaymentServiceTest.php index b8aabc75..1d6bf5be 100755 --- a/tests/Unit/Payment/PaymentServiceTest.php +++ b/tests/Unit/Payment/PaymentServiceTest.php @@ -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++) {