diff --git a/src/Metadata/Driver/AnnotationDriver.php b/src/Metadata/Driver/AnnotationDriver.php index 1a8cb0d07..a04d5591f 100644 --- a/src/Metadata/Driver/AnnotationDriver.php +++ b/src/Metadata/Driver/AnnotationDriver.php @@ -73,7 +73,10 @@ public function __construct(Reader $reader, PropertyNamingStrategyInterface $nam public function loadMetadataForClass(\ReflectionClass $class): ?BaseClassMetadata { $classMetadata = new ClassMetadata($name = $class->name); - $classMetadata->fileResources[] = $class->getFilename(); + $fileResource = $class->getFilename(); + if (false !== $fileResource) { + $classMetadata->fileResources[] = $fileResource; + } $propertiesMetadata = []; $propertiesAnnotations = []; diff --git a/src/Metadata/Driver/NullDriver.php b/src/Metadata/Driver/NullDriver.php index 3d8057abb..fbbf750f0 100644 --- a/src/Metadata/Driver/NullDriver.php +++ b/src/Metadata/Driver/NullDriver.php @@ -13,7 +13,10 @@ class NullDriver implements DriverInterface public function loadMetadataForClass(\ReflectionClass $class): ?BaseClassMetadata { $classMetadata = new ClassMetadata($name = $class->name); - $classMetadata->fileResources[] = $class->getFilename(); + $fileResource = $class->getFilename(); + if (false !== $fileResource) { + $classMetadata->fileResources[] = $fileResource; + } return $classMetadata; } diff --git a/src/Metadata/Driver/XmlDriver.php b/src/Metadata/Driver/XmlDriver.php index b2c0390c7..c894c9ccf 100644 --- a/src/Metadata/Driver/XmlDriver.php +++ b/src/Metadata/Driver/XmlDriver.php @@ -56,7 +56,10 @@ protected function loadMetadataFromFile(\ReflectionClass $class, string $path): $elem = reset($elems); $metadata->fileResources[] = $path; - $metadata->fileResources[] = $class->getFileName(); + $fileResource = $class->getFilename(); + if (false !== $fileResource) { + $metadata->fileResources[] = $fileResource; + } $exclusionPolicy = strtoupper((string) $elem->attributes()->{'exclusion-policy'}) ?: 'NONE'; $exclude = $elem->attributes()->exclude; $excludeAll = null !== $exclude ? 'true' === strtolower((string) $exclude) : false; diff --git a/src/Metadata/Driver/YamlDriver.php b/src/Metadata/Driver/YamlDriver.php index c083370c6..20b2e81a7 100644 --- a/src/Metadata/Driver/YamlDriver.php +++ b/src/Metadata/Driver/YamlDriver.php @@ -48,7 +48,11 @@ protected function loadMetadataFromFile(\ReflectionClass $class, string $file): $config = $config[$name]; $metadata = new ClassMetadata($name); $metadata->fileResources[] = $file; - $metadata->fileResources[] = $class->getFileName(); + $fileResource = $class->getFilename(); + if (false !== $fileResource) { + $metadata->fileResources[] = $fileResource; + } + $exclusionPolicy = isset($config['exclusion_policy']) ? strtoupper($config['exclusion_policy']) : 'NONE'; $excludeAll = isset($config['exclude']) ? (bool) $config['exclude'] : false; $classAccessType = $config['access_type'] ?? PropertyMetadata::ACCESS_TYPE_PROPERTY; diff --git a/tests/Metadata/Driver/AnnotationDriverTest.php b/tests/Metadata/Driver/AnnotationDriverTest.php index b9be6866f..8bba7acf7 100644 --- a/tests/Metadata/Driver/AnnotationDriverTest.php +++ b/tests/Metadata/Driver/AnnotationDriverTest.php @@ -14,4 +14,9 @@ protected function getDriver() { return new AnnotationDriver(new AnnotationReader(), new IdenticalPropertyNamingStrategy()); } + + public function testCanDefineMetadataForInternalClass() + { + $this->markTestSkipped('Can not define annotation metadata for internal classes'); + } } diff --git a/tests/Metadata/Driver/BaseDriverTest.php b/tests/Metadata/Driver/BaseDriverTest.php index bf686a6ea..1516fae86 100644 --- a/tests/Metadata/Driver/BaseDriverTest.php +++ b/tests/Metadata/Driver/BaseDriverTest.php @@ -271,6 +271,17 @@ public function testLoadXmlDiscriminatorWithNamespaces() self::assertFalse($m->xmlDiscriminatorAttribute); } + public function testCanDefineMetadataForInternalClass() + { + /** @var ClassMetadata $m */ + $m = $this->getDriver()->loadMetadataForClass(new \ReflectionClass(\PDOStatement::class)); + + self::assertNotNull($m); + self::assertSame('int', $m->propertyMetadata['queryString']->type['name']); + + self::assertCount(1, $m->fileResources); + } + public function testLoadXmlDiscriminatorWithAttributeNamespaces() { /** @var ClassMetadata $m */ diff --git a/tests/Metadata/Driver/XmlDriverTest.php b/tests/Metadata/Driver/XmlDriverTest.php index b50193690..7a2802253 100644 --- a/tests/Metadata/Driver/XmlDriverTest.php +++ b/tests/Metadata/Driver/XmlDriverTest.php @@ -96,6 +96,7 @@ protected function getDriver() return new XmlDriver(new FileLocator([ 'JMS\Serializer\Tests\Fixtures' => __DIR__ . '/xml' . $append, + '' => __DIR__ . '/xml/_' . $append, ]), new IdenticalPropertyNamingStrategy()); } } diff --git a/tests/Metadata/Driver/YamlDriverTest.php b/tests/Metadata/Driver/YamlDriverTest.php index 614eeb4a8..a2a48264d 100644 --- a/tests/Metadata/Driver/YamlDriverTest.php +++ b/tests/Metadata/Driver/YamlDriverTest.php @@ -76,6 +76,7 @@ private function getDriverForSubDir($subDir = null) { return new YamlDriver(new FileLocator([ 'JMS\Serializer\Tests\Fixtures' => __DIR__ . '/yml' . ($subDir ? '/' . $subDir : ''), + '' => __DIR__ . '/yml/_' . ($subDir ? '/' . $subDir : ''), ]), new IdenticalPropertyNamingStrategy()); } diff --git a/tests/Metadata/Driver/xml/_/PDOStatement.xml b/tests/Metadata/Driver/xml/_/PDOStatement.xml new file mode 100644 index 000000000..63c13efb1 --- /dev/null +++ b/tests/Metadata/Driver/xml/_/PDOStatement.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/Metadata/Driver/yml/_/PDOStatement.yml b/tests/Metadata/Driver/yml/_/PDOStatement.yml new file mode 100644 index 000000000..9f2a91e14 --- /dev/null +++ b/tests/Metadata/Driver/yml/_/PDOStatement.yml @@ -0,0 +1,5 @@ +PDOStatement: + properties: + queryString: + type: int +