normalizer = self::getContainer()->get(NormalizerInterface::class); $this->phoneNumberUtil = PhoneNumberUtil::getInstance(); } public function testAvoidRecursionWithNullParent() { $thirdparty = new ThirdParty(); $thirdparty ->setAcronym('ABCD') ->setName('test') ->setCivility((new Civility())->setName(['fr' => 'Monsieur'])->setAbbreviation(['fr' => 'M.'])) ->setEmail('info@cl.coop') ->addTypesAndCategories('kind') ->addTypesAndCategories((new ThirdPartyCategory())->setName(['fr' => 'category'])) ->setParent(new ThirdParty()); $actual = $this->normalizer->normalize($thirdparty, 'docgen', ['groups' => ['docgen:read']]); $this->assertIsArray($actual); $this->assertArrayHasKey('parent', $actual); $this->assertIsArray($actual['parent']); $this->assertArrayNotHasKey('parent', $actual['parent']); // check that other keys exists for parent $this->assertArrayHasKey('acronym', $actual['parent']); $this->assertEquals('', $actual['parent']['acronym']); $thirdparty = new ThirdParty(); $thirdparty ->setAcronym('ABCD') ->setName('test') ->setCivility((new Civility())->setName(['fr' => 'Monsieur'])->setAbbreviation(['fr' => 'M.'])) ->setEmail('info@cl.coop') ->addTypesAndCategories('kind') ->addTypesAndCategories((new ThirdPartyCategory())->setName(['fr' => 'category'])); $actual = $this->normalizer->normalize($thirdparty, 'docgen', ['groups' => ['docgen:read']]); $this->assertIsArray($actual); $this->assertArrayHasKey('parent', $actual); $this->assertIsArray($actual['parent']); $this->assertArrayNotHasKey('parent', $actual['parent']); // check that other keys exists for parent $this->assertArrayHasKey('acronym', $actual['parent']); $this->assertEquals('', $actual['parent']['acronym']); $actual = $this->normalizer->normalize(null, 'docgen', ['groups' => ['docgen:read'], 'docgen:expects' => ThirdParty::class]); $this->assertIsArray($actual); $this->assertArrayHasKey('parent', $actual); $this->assertIsArray($actual['parent']); $this->assertArrayNotHasKey('parent', $actual['parent']); // check that other keys exists for parent $this->assertArrayHasKey('acronym', $actual['parent']); $this->assertEquals('', $actual['parent']['acronym']); } public function testNormalize() { $thirdparty = new ThirdParty(); $thirdparty ->setAcronym('ABCD') ->setName('test') ->setCivility((new Civility())->setName(['fr' => 'Monsieur'])->setAbbreviation(['fr' => 'M.'])) ->setEmail('info@cl.coop') ->setTelephone($this->phoneNumberUtil->parse('+32486123456', 'BE')) ->addTypesAndCategories('kind') ->addTypesAndCategories((new ThirdPartyCategory())->setName(['fr' => 'category'])); $actual = $this->normalizer->normalize($thirdparty, 'docgen', ['groups' => ['docgen:read']]); $this->assertIsArray($actual); $this->assertArrayHasKey('telephone', $actual); $this->assertEquals('0486 12 34 56', $actual['telephone']); } }