diff --git a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php index 069dba9d8..2466f745c 100644 --- a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php +++ b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php @@ -222,7 +222,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface * @var array|null * @ORM\Column(name="types", type="json", nullable=true) */ - private $types; + private ?array $thirdPartyTypes = []; /** * @ORM\Column(name="updated_at", type="datetime_immutable", nullable=true) @@ -303,18 +303,18 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface return $this; } - public function addType(?string $type): self + public function addThirdPartyTypes(?string $type): self { if (null === $type) { return $this; } - if (!in_array($type, $this->types ?? [], true)) { - $this->types[] = $type; + if (!in_array($type, $this->thirdPartyTypes ?? [], true)) { + $this->thirdPartyTypes[] = $type; } foreach ($this->children as $child) { - $child->addType($type); + $child->addThirdPartyTypes($type); } return $this; @@ -329,7 +329,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface } if (is_string($typeAndCategory)) { - $this->addType($typeAndCategory); + $this->addThirdPartyTypes($typeAndCategory); return $this; } @@ -473,16 +473,16 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface * * @return array|null */ - public function getTypes() + public function getThirdPartyTypes() { - return $this->types; + return $this->thirdPartyTypes ?? []; } public function getTypesAndCategories(): array { return array_merge( $this->getCategories()->toArray(), - $this->getTypes() ?? [] + $this->getThirdPartyTypes() ?? [] ); } @@ -574,18 +574,18 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface return $this; } - public function removeType(?string $type): self + public function removeThirdPartyTypes(?string $type): self { if (null === $type) { return $this; } - if (in_array($type, $this->types ?? [], true)) { - $this->types = array_filter($this->types, fn ($e) => !in_array($e, $this->types, true)); + if (in_array($type, $this->thirdPartyTypes ?? [], true)) { + $this->thirdPartyTypes = array_filter($this->thirdPartyTypes, fn ($e) => !in_array($e, $this->thirdPartyTypes, true)); } foreach ($this->children as $child) { - $child->removeType($type); + $child->removeThirdPartyTypes($type); } return $this; @@ -600,7 +600,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface } if (is_string($typeAndCategory)) { - $this->removeType($typeAndCategory); + $this->removeThirdPartyTypes($typeAndCategory); return $this; } @@ -799,13 +799,13 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface * * @return ThirdParty */ - public function setTypes(?array $type = null) + public function setThirdPartyTypes(?array $type = []) { // remove all keys from the input data - $this->types = array_values($type); + $this->thirdPartyTypes = array_values($type); foreach ($this->children as $child) { - $child->setTypes($type); + $child->setThirdPartyTypes($type); } return $this; @@ -814,7 +814,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface public function setTypesAndCategories(array $typesAndCategories): self { $types = array_filter($typesAndCategories, static fn ($item) => !$item instanceof ThirdPartyCategory); - $this->setTypes($types); + $this->setThirdPartyTypes($types); // handle categories foreach ($typesAndCategories as $t) { diff --git a/src/Bundle/ChillThirdPartyBundle/Tests/Entity/ThirdPartyTest.php b/src/Bundle/ChillThirdPartyBundle/Tests/Entity/ThirdPartyTest.php index 0ec7d065e..4dc6dbc55 100644 --- a/src/Bundle/ChillThirdPartyBundle/Tests/Entity/ThirdPartyTest.php +++ b/src/Bundle/ChillThirdPartyBundle/Tests/Entity/ThirdPartyTest.php @@ -35,8 +35,8 @@ final class ThirdPartyTest extends TestCase $this->assertTrue($tp->getCategories()->contains($cat2)); $this->assertCount(2, $tp->getCategories()); - $this->assertCount(1, $tp->getTypes()); - $this->assertContains('type', $tp->getTypes()); + $this->assertCount(1, $tp->getThirdPartyTypes()); + $this->assertContains('type', $tp->getThirdPartyTypes()); $this->assertCount(3, $tp->getTypesAndCategories()); $this->assertContains($cat1, $tp->getTypesAndCategories()); @@ -54,8 +54,8 @@ final class ThirdPartyTest extends TestCase $this->assertFalse($tp->getCategories()->contains($cat2)); $this->assertCount(1, $tp->getCategories()); - $this->assertCount(0, $tp->getTypes()); - $this->assertNotContains('type', $tp->getTypes()); + $this->assertCount(0, $tp->getThirdPartyTypes()); + $this->assertNotContains('type', $tp->getThirdPartyTypes()); $this->assertCount(1, $tp->getTypesAndCategories()); $this->assertContains($cat1, $tp->getTypesAndCategories()); @@ -77,9 +77,9 @@ final class ThirdPartyTest extends TestCase $this->assertTrue($tp->getCategories()->contains($cat2)); $this->assertCount(2, $tp->getCategories()); - $this->assertCount(2, $tp->getTypes()); - $this->assertContains('type1', $tp->getTypes()); - $this->assertContains('type2', $tp->getTypes()); + $this->assertCount(2, $tp->getThirdPartyTypes()); + $this->assertContains('type1', $tp->getThirdPartyTypes()); + $this->assertContains('type2', $tp->getThirdPartyTypes()); $this->assertCount(4, $tp->getTypesAndCategories()); $this->assertContains($cat1, $tp->getTypesAndCategories()); @@ -93,9 +93,9 @@ final class ThirdPartyTest extends TestCase $this->assertFalse($tp->getCategories()->contains($cat2)); $this->assertCount(1, $tp->getCategories()); - $this->assertCount(1, $tp->getTypes()); - $this->assertContains('type1', $tp->getTypes()); - $this->assertNotContains('type2', $tp->getTypes()); + $this->assertCount(1, $tp->getThirdPartyTypes()); + $this->assertContains('type1', $tp->getThirdPartyTypes()); + $this->assertNotContains('type2', $tp->getThirdPartyTypes()); $this->assertCount(2, $tp->getTypesAndCategories()); $this->assertContains($cat1, $tp->getTypesAndCategories()); diff --git a/src/Bundle/ChillThirdPartyBundle/Tests/Serializer/Normalizer/ThirdPartyJsonDenormalizerTest.php b/src/Bundle/ChillThirdPartyBundle/Tests/Serializer/Normalizer/ThirdPartyJsonDenormalizerTest.php new file mode 100644 index 000000000..811b55136 --- /dev/null +++ b/src/Bundle/ChillThirdPartyBundle/Tests/Serializer/Normalizer/ThirdPartyJsonDenormalizerTest.php @@ -0,0 +1,43 @@ +normalizer = self::$container->get(DenormalizerInterface::class); + } + + public function testDenormalizeContact() + { + $str = <<normalizer->denormalize(json_decode($str, true), ThirdParty::class, 'json', [ + 'groups' => ['write'] + ]); + + $this->assertInstanceOf(ThirdParty::class, $actual); + $this->assertEquals('badaboum', $actual->getName()); + $this->assertEquals('badaboum@email.com', $actual->getEmail()); + $this->assertEquals(ThirdParty::KIND_CONTACT, $actual->getKind()); + } + +} diff --git a/src/Bundle/ChillThirdPartyBundle/Tests/Serializer/Normalizer/ThirdpartyDocGenNormalizerTest.php b/src/Bundle/ChillThirdPartyBundle/Tests/Serializer/Normalizer/ThirdpartyDocGenNormalizerTest.php index 0b8169d69..cc2b7b33b 100644 --- a/src/Bundle/ChillThirdPartyBundle/Tests/Serializer/Normalizer/ThirdpartyDocGenNormalizerTest.php +++ b/src/Bundle/ChillThirdPartyBundle/Tests/Serializer/Normalizer/ThirdpartyDocGenNormalizerTest.php @@ -44,8 +44,6 @@ final class ThirdpartyDocGenNormalizerTest extends KernelTestCase $actual = $this->normalizer->normalize($thirdparty, 'docgen', ['groups' => ['docgen:read']]); - var_dump($actual); - $this->assertIsArray($actual); } }