diff --git a/src/Metadata/Property/Factory/ExtractorPropertyMetadataFactory.php b/src/Metadata/Property/Factory/ExtractorPropertyMetadataFactory.php index e8e13f2256..dad8945003 100644 --- a/src/Metadata/Property/Factory/ExtractorPropertyMetadataFactory.php +++ b/src/Metadata/Property/Factory/ExtractorPropertyMetadataFactory.php @@ -50,10 +50,7 @@ public function create(string $resourceClass, string $property, array $options = } } - if ( - !property_exists($resourceClass, $property) && !interface_exists($resourceClass) - || null === ($propertyMetadata = $this->extractor->getProperties()[$resourceClass][$property] ?? null) - ) { + if (null === ($propertyMetadata = $this->extractor->getProperties()[$resourceClass][$property] ?? null)) { return $this->handleNotFound($parentPropertyMetadata, $resourceClass, $property); } diff --git a/src/Metadata/Tests/Property/Factory/ExtractorPropertyMetadataFactoryTest.php b/src/Metadata/Tests/Property/Factory/ExtractorPropertyMetadataFactoryTest.php new file mode 100644 index 0000000000..ce35b84c66 --- /dev/null +++ b/src/Metadata/Tests/Property/Factory/ExtractorPropertyMetadataFactoryTest.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Metadata\Tests\Property\Factory; + +use ApiPlatform\Metadata\Extractor\PropertyExtractorInterface; +use ApiPlatform\Metadata\Property\Factory\ExtractorPropertyMetadataFactory; +use ApiPlatform\Metadata\Tests\Fixtures\ApiResource\Comment; +use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; + +final class ExtractorPropertyMetadataFactoryTest extends TestCase +{ + use ProphecyTrait; + + public function testCreateVirtualPropertyFromExtractor(): void + { + $extractorProphecy = $this->prophesize(PropertyExtractorInterface::class); + $extractorProphecy->getProperties()->willReturn([ + Comment::class => [ + 'admin' => [ + 'security' => 'user.isAdmin() === true', + ], + ], + ]); + + $factory = new ExtractorPropertyMetadataFactory($extractorProphecy->reveal()); + $metadata = $factory->create(Comment::class, 'admin'); + + self::assertSame('user.isAdmin() === true', $metadata->getSecurity()); + } +}