From 95975fae5507ad0a8072c6cb6402409826e48fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 20 Jun 2025 17:35:19 +0200 Subject: [PATCH] fix cs --- .../Phonenumber/PhonenumberHelperTest.php | 80 +++++++------- .../Controller/FindCallerControllerTest.php | 42 ++++---- .../ReplaceMotiveControllerTest.php | 36 +++---- .../SetAddresseesControllerTest.php | 52 ++++----- .../Normalizer/TicketNormalizerTest.php | 102 +++++++++--------- 5 files changed, 156 insertions(+), 156 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Tests/Phonenumber/PhonenumberHelperTest.php b/src/Bundle/ChillMainBundle/Tests/Phonenumber/PhonenumberHelperTest.php index 556fa9fde..cae0cdd48 100644 --- a/src/Bundle/ChillMainBundle/Tests/Phonenumber/PhonenumberHelperTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Phonenumber/PhonenumberHelperTest.php @@ -26,6 +26,26 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; */ final class PhonenumberHelperTest extends KernelTestCase { + /** + * @dataProvider formatPhonenumbers + */ + public function testFormatPhonenumbers(string $defaultCarrierCode, string $phoneNumber, string $expected) + { + $util = PhoneNumberUtil::getInstance(); + + $subject = new PhonenumberHelper( + new ArrayAdapter(), + new ParameterBag([ + 'chill_main.phone_helper' => [ + 'default_carrier_code' => $defaultCarrierCode, + ], + ]), + new NullLogger() + ); + + $this->assertEquals($expected, $subject->format($util->parse($phoneNumber))); + } + public static function formatPhonenumbers() { yield [ @@ -53,6 +73,26 @@ final class PhonenumberHelperTest extends KernelTestCase ]; } + /** + * @dataProvider providePhoneNumbersToParse + */ + public function testParsePhonenumbers(string $defaultCarrierCode, string $phoneNumber, PhoneNumber $expected): void + { + $subject = new PhonenumberHelper( + new ArrayAdapter(), + new ParameterBag([ + 'chill_main.phone_helper' => [ + 'default_carrier_code' => $defaultCarrierCode, + ], + ]), + new NullLogger() + ); + + $actual = $subject->parse($phoneNumber); + + self::assertTrue($expected->equals($actual)); + } + public static function providePhoneNumbersToParse(): iterable { $util = PhoneNumberUtil::getInstance(); @@ -75,44 +115,4 @@ final class PhonenumberHelperTest extends KernelTestCase $util->parse('+33228858040', 'FR'), ]; } - - /** - * @dataProvider formatPhonenumbers - */ - public function testFormatPhonenumbers(string $defaultCarrierCode, string $phoneNumber, string $expected) - { - $util = PhoneNumberUtil::getInstance(); - - $subject = new PhonenumberHelper( - new ArrayAdapter(), - new ParameterBag([ - 'chill_main.phone_helper' => [ - 'default_carrier_code' => $defaultCarrierCode, - ], - ]), - new NullLogger() - ); - - $this->assertEquals($expected, $subject->format($util->parse($phoneNumber))); - } - - /** - * @dataProvider providePhoneNumbersToParse - */ - public function testParsePhonenumbers(string $defaultCarrierCode, string $phoneNumber, PhoneNumber $expected): void - { - $subject = new PhonenumberHelper( - new ArrayAdapter(), - new ParameterBag([ - 'chill_main.phone_helper' => [ - 'default_carrier_code' => $defaultCarrierCode, - ], - ]), - new NullLogger() - ); - - $actual = $subject->parse($phoneNumber); - - self::assertTrue($expected->equals($actual)); - } } diff --git a/src/Bundle/ChillTicketBundle/tests/Controller/FindCallerControllerTest.php b/src/Bundle/ChillTicketBundle/tests/Controller/FindCallerControllerTest.php index 301b8f4ac..997017e97 100644 --- a/src/Bundle/ChillTicketBundle/tests/Controller/FindCallerControllerTest.php +++ b/src/Bundle/ChillTicketBundle/tests/Controller/FindCallerControllerTest.php @@ -50,6 +50,27 @@ class FindCallerControllerTest extends TestCase self::assertEqualsCanonicalizing($expected, $actual); } + public static function provideFindCaller(): iterable + { + yield [ + '32486540600', + [], + ['found' => false, 'name' => null], + ]; + + yield [ + '32486540600', + [new Person()], + ['found' => true, 'name' => 'pppp'], + ] + ; + yield [ + '32486540600', + [new Person(), new Person()], + ['found' => true, 'name' => 'multiple'], + ]; + } + public function testFindCallerWithoutCallerArgument(): void { self::expectException(BadRequestHttpException::class); @@ -83,27 +104,6 @@ class FindCallerControllerTest extends TestCase $controller->findCaller($request); } - public static function provideFindCaller(): iterable - { - yield [ - '32486540600', - [], - ['found' => false, 'name' => null], - ]; - - yield [ - '32486540600', - [new Person()], - ['found' => true, 'name' => 'pppp'], - ] - ; - yield [ - '32486540600', - [new Person(), new Person()], - ['found' => true, 'name' => 'multiple'], - ]; - } - private function buildController(array $personsFound): FindCallerController { $phonenumberHelper = diff --git a/src/Bundle/ChillTicketBundle/tests/Controller/ReplaceMotiveControllerTest.php b/src/Bundle/ChillTicketBundle/tests/Controller/ReplaceMotiveControllerTest.php index dcf6a2318..95c8ec5f4 100644 --- a/src/Bundle/ChillTicketBundle/tests/Controller/ReplaceMotiveControllerTest.php +++ b/src/Bundle/ChillTicketBundle/tests/Controller/ReplaceMotiveControllerTest.php @@ -70,6 +70,24 @@ class ReplaceMotiveControllerTest extends KernelTestCase self::assertEquals(201, $response->getStatusCode()); } + public static function generateMotiveId(): iterable + { + self::bootKernel(); + $em = self::getContainer()->get(EntityManagerInterface::class); + + $motive = $em->createQuery('SELECT m FROM '.Motive::class.' m ') + ->setMaxResults(1) + ->getOneOrNullResult(); + + if (null === $motive) { + throw new \RuntimeException('the motive table seems to be empty'); + } + + self::ensureKernelShutdown(); + + yield [$motive->getId()]; + } + private function buildController(): ReplaceMotiveController { $security = $this->prophesize(Security::class); @@ -92,22 +110,4 @@ class ReplaceMotiveControllerTest extends KernelTestCase $entityManager->reveal(), ); } - - public static function generateMotiveId(): iterable - { - self::bootKernel(); - $em = self::getContainer()->get(EntityManagerInterface::class); - - $motive = $em->createQuery('SELECT m FROM '.Motive::class.' m ') - ->setMaxResults(1) - ->getOneOrNullResult(); - - if (null === $motive) { - throw new \RuntimeException('the motive table seems to be empty'); - } - - self::ensureKernelShutdown(); - - yield [$motive->getId()]; - } } diff --git a/src/Bundle/ChillTicketBundle/tests/Controller/SetAddresseesControllerTest.php b/src/Bundle/ChillTicketBundle/tests/Controller/SetAddresseesControllerTest.php index af0d48e87..1455f711f 100644 --- a/src/Bundle/ChillTicketBundle/tests/Controller/SetAddresseesControllerTest.php +++ b/src/Bundle/ChillTicketBundle/tests/Controller/SetAddresseesControllerTest.php @@ -85,6 +85,32 @@ class SetAddresseesControllerTest extends KernelTestCase self::assertGreaterThan(0, count($asArray['violations'])); } + public static function getContentData(): iterable + { + self::bootKernel(); + $entityManager = self::getContainer()->get(EntityManagerInterface::class); + + $userGroup = $entityManager->createQuery('SELECT ug FROM '.UserGroup::class.' ug ') + ->setMaxResults(1)->getOneOrNullResult(); + + if (null === $userGroup) { + throw new \RuntimeException('User group not existing in database'); + } + + $user = $entityManager->createQuery('SELECT u FROM '.User::class.' u') + ->setMaxResults(1)->getOneOrNullResult(); + + if (null === $user) { + throw new \RuntimeException('User not existing in database'); + } + + self::ensureKernelShutdown(); + + yield [[['type' => 'user', 'id' => $user->getId()]]]; + yield [[['type' => 'user', 'id' => $user->getId()], ['type' => 'user_group', 'id' => $userGroup->getId()]]]; + yield [[['type' => 'user_group', 'id' => $userGroup->getId()]]]; + } + /** * @dataProvider getContentDataUnique */ @@ -149,32 +175,6 @@ class SetAddresseesControllerTest extends KernelTestCase yield [['type' => 'user_group', 'id' => $userGroup->getId()]]; } - public static function getContentData(): iterable - { - self::bootKernel(); - $entityManager = self::getContainer()->get(EntityManagerInterface::class); - - $userGroup = $entityManager->createQuery('SELECT ug FROM '.UserGroup::class.' ug ') - ->setMaxResults(1)->getOneOrNullResult(); - - if (null === $userGroup) { - throw new \RuntimeException('User group not existing in database'); - } - - $user = $entityManager->createQuery('SELECT u FROM '.User::class.' u') - ->setMaxResults(1)->getOneOrNullResult(); - - if (null === $user) { - throw new \RuntimeException('User not existing in database'); - } - - self::ensureKernelShutdown(); - - yield [[['type' => 'user', 'id' => $user->getId()]]]; - yield [[['type' => 'user', 'id' => $user->getId()], ['type' => 'user_group', 'id' => $userGroup->getId()]]]; - yield [[['type' => 'user_group', 'id' => $userGroup->getId()]]]; - } - private function buildController(bool $willSave, bool $isValid): SetAddresseesController { $user = new User(); diff --git a/src/Bundle/ChillTicketBundle/tests/Serializer/Normalizer/TicketNormalizerTest.php b/src/Bundle/ChillTicketBundle/tests/Serializer/Normalizer/TicketNormalizerTest.php index 415fc15fb..035ce95a6 100644 --- a/src/Bundle/ChillTicketBundle/tests/Serializer/Normalizer/TicketNormalizerTest.php +++ b/src/Bundle/ChillTicketBundle/tests/Serializer/Normalizer/TicketNormalizerTest.php @@ -59,6 +59,57 @@ class TicketNormalizerTest extends KernelTestCase } } + public static function provideTickets(): iterable + { + yield [ + // this a nearly empty ticket + new Ticket(), + [ + 'type' => 'ticket_ticket', + 'id' => null, + 'externalRef' => '', + 'currentPersons' => [], + 'currentAddressees' => [], + 'currentInputs' => [], + 'currentMotive' => null, + 'history' => [], + ], + ]; + + // ticket with more features + $ticket = new Ticket(); + $ticket->setExternalRef('2134'); + $personHistory = new PersonHistory(new Person(), $ticket, new \DateTimeImmutable('2024-04-01T12:00:00')); + $ticketHistory = new MotiveHistory(new Motive(), $ticket, new \DateTimeImmutable('2024-04-01T12:02:00')); + $comment = new Comment('blabla test', $ticket); + $comment->setCreatedAt(new \DateTimeImmutable('2024-04-01T12:04:00')); + $comment->setCreatedBy(new User()); + $addresseeHistory = new AddresseeHistory(new User(), new \DateTimeImmutable('2024-04-01T12:05:00'), $ticket); + $addresseeHistory->setEndDate(new \DateTimeImmutable('2024-04-01T12:06:00')); + new AddresseeHistory(new UserGroup(), new \DateTimeImmutable('2024-04-01T12:07:00'), $ticket); + + yield [ + $ticket, + [ + 'type' => 'ticket_ticket', + 'id' => null, + 'externalRef' => '2134', + 'currentPersons' => ['embedded'], + 'currentAddressees' => ['embedded'], + 'currentInputs' => [], + 'currentMotive' => ['type' => 'motive', 'id' => 0], + 'history' => [ + ['event_type' => 'add_person'], + ['event_type' => 'set_motive'], + ['event_type' => 'add_comment'], + ['event_type' => 'add_addressee'], + ['event_type' => 'remove_addressee'], + ['event_type' => 'add_addressee'], + ], + ], + ]; + } + private function buildNormalizer(): TicketNormalizer { $normalizer = $this->prophesize(NormalizerInterface::class); @@ -120,55 +171,4 @@ class TicketNormalizerTest extends KernelTestCase return $ticketNormalizer; } - - public static function provideTickets(): iterable - { - yield [ - // this a nearly empty ticket - new Ticket(), - [ - 'type' => 'ticket_ticket', - 'id' => null, - 'externalRef' => '', - 'currentPersons' => [], - 'currentAddressees' => [], - 'currentInputs' => [], - 'currentMotive' => null, - 'history' => [], - ], - ]; - - // ticket with more features - $ticket = new Ticket(); - $ticket->setExternalRef('2134'); - $personHistory = new PersonHistory(new Person(), $ticket, new \DateTimeImmutable('2024-04-01T12:00:00')); - $ticketHistory = new MotiveHistory(new Motive(), $ticket, new \DateTimeImmutable('2024-04-01T12:02:00')); - $comment = new Comment('blabla test', $ticket); - $comment->setCreatedAt(new \DateTimeImmutable('2024-04-01T12:04:00')); - $comment->setCreatedBy(new User()); - $addresseeHistory = new AddresseeHistory(new User(), new \DateTimeImmutable('2024-04-01T12:05:00'), $ticket); - $addresseeHistory->setEndDate(new \DateTimeImmutable('2024-04-01T12:06:00')); - new AddresseeHistory(new UserGroup(), new \DateTimeImmutable('2024-04-01T12:07:00'), $ticket); - - yield [ - $ticket, - [ - 'type' => 'ticket_ticket', - 'id' => null, - 'externalRef' => '2134', - 'currentPersons' => ['embedded'], - 'currentAddressees' => ['embedded'], - 'currentInputs' => [], - 'currentMotive' => ['type' => 'motive', 'id' => 0], - 'history' => [ - ['event_type' => 'add_person'], - ['event_type' => 'set_motive'], - ['event_type' => 'add_comment'], - ['event_type' => 'add_addressee'], - ['event_type' => 'remove_addressee'], - ['event_type' => 'add_addressee'], - ], - ], - ]; - } }