* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\PropertyInfo\Tests\Extractor; use Doctrine\Common\Annotations\AnnotationReader; use PHPUnit\Framework\TestCase; use Symfony\Component\PropertyInfo\Extractor\SerializerExtractor; use Symfony\Component\PropertyInfo\Tests\Fixtures\AdderRemoverDummy; use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy; use Symfony\Component\PropertyInfo\Tests\Fixtures\IgnorePropertyDummy; use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory; use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader; use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader; /** * @author Kévin Dunglas */ class SerializerExtractorTest extends TestCase { private SerializerExtractor $extractor; protected function setUp(): void { if (class_exists(AttributeLoader::class)) { $classMetadataFactory = new ClassMetadataFactory(new AttributeLoader()); } else { $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())); } $this->extractor = new SerializerExtractor($classMetadataFactory); } public function testGetProperties() { $this->assertEquals( ['collection'], $this->extractor->getProperties(Dummy::class, ['serializer_groups' => ['a']]) ); } public function testGetPropertiesWithIgnoredProperties() { $this->assertSame(['visibleProperty'], $this->extractor->getProperties(IgnorePropertyDummy::class, ['serializer_groups' => ['a']])); } public function testGetPropertiesWithAnyGroup() { $this->assertSame(['analyses', 'feet'], $this->extractor->getProperties(AdderRemoverDummy::class, ['serializer_groups' => null])); } public function testGetPropertiesWithNonExistentClassReturnsNull() { $this->assertSame(null, $this->extractor->getProperties('NonExistent')); } }