diff --git a/composer.json b/composer.json index 6cee2b40a1..6fe60193d1 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,6 @@ }, "require-dev": { "ext-bcmath": "*", - "doctrine/annotations": "^1.12 || ^2.0", "doctrine/coding-standard": "^14.0", "doctrine/orm": "^3.2", "jmikola/geojson": "^1.0", @@ -57,11 +56,7 @@ "symfony/uid": "^5.4 || ^6.0 || ^7.0 || ^8.0", "symfony/var-dumper": "^5.4 || ^6.0 || ^7.0 || ^8.0" }, - "conflict": { - "doctrine/annotations": "<1.12 || >=3.0" - }, "suggest": { - "doctrine/annotations": "For annotation mapping support", "ext-bcmath": "Decimal128 type support", "symfony/var-dumper": "To enable the odm:query command" }, diff --git a/docs/en/reference/annotations-reference.rst b/docs/en/reference/annotations-reference.rst index adbaea13f9..b042210048 100644 --- a/docs/en/reference/annotations-reference.rst +++ b/docs/en/reference/annotations-reference.rst @@ -2,11 +2,7 @@ Attributes Reference ===================== -Doctrine Annotations are deprecated and replaced by native PHP attributes. -All the attributes listed on :doc:`Attributes Reference ` -can be used as annotations. - -Support for annotations will be removed in Doctrine MongoDB ODM 3.0. +Doctrine Annotations replaced by native PHP attributes, see :doc:`Attributes Reference `. If you are still using annotations, you can migrate your code to attributes by following the guide below: diff --git a/src/Configuration.php b/src/Configuration.php index 63747d4b69..ab30197880 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -5,13 +5,11 @@ namespace Doctrine\ODM\MongoDB; use Composer\InstalledVersions; -use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Cache\Cache; use Doctrine\Common\Cache\Psr6\CacheAdapter; use Doctrine\Common\Cache\Psr6\DoctrineProvider; use Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory; use Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactoryInterface; -use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver; use Doctrine\ODM\MongoDB\PersistentCollection\DefaultPersistentCollectionFactory; use Doctrine\ODM\MongoDB\PersistentCollection\DefaultPersistentCollectionGenerator; use Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionFactory; @@ -254,18 +252,6 @@ public function setMetadataDriverImpl(MappingDriver $driverImpl): void $this->attributes['metadataDriverImpl'] = $driverImpl; } - /** - * Add a new default annotation driver with a correctly configured annotation reader. - * - * @param string[] $paths - */ - public function newDefaultAnnotationDriver(array $paths = []): AnnotationDriver - { - $reader = new AnnotationReader(); - - return new AnnotationDriver($reader, $paths); - } - /** * Gets the cache driver implementation that is used for the mapping metadata. */ diff --git a/src/Mapping/Annotations/AlsoLoad.php b/src/Mapping/Annotations/AlsoLoad.php index e847775cf7..dbb07bc15c 100644 --- a/src/Mapping/Annotations/AlsoLoad.php +++ b/src/Mapping/Annotations/AlsoLoad.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Loads data from a different field if the original field is not set - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD)] final class AlsoLoad implements Annotation diff --git a/src/Mapping/Annotations/ChangeTrackingPolicy.php b/src/Mapping/Annotations/ChangeTrackingPolicy.php index 059f24e66b..c97f330903 100644 --- a/src/Mapping/Annotations/ChangeTrackingPolicy.php +++ b/src/Mapping/Annotations/ChangeTrackingPolicy.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Specifies the change tracking policy for a document - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_CLASS)] final class ChangeTrackingPolicy implements Annotation diff --git a/src/Mapping/Annotations/DefaultDiscriminatorValue.php b/src/Mapping/Annotations/DefaultDiscriminatorValue.php index 45faeea0e6..c635fdd199 100644 --- a/src/Mapping/Annotations/DefaultDiscriminatorValue.php +++ b/src/Mapping/Annotations/DefaultDiscriminatorValue.php @@ -5,14 +5,10 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Specifies a default discriminator value to be used when the discriminator * field is not set in a document - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY)] final class DefaultDiscriminatorValue implements Annotation diff --git a/src/Mapping/Annotations/DiscriminatorField.php b/src/Mapping/Annotations/DiscriminatorField.php index ae57be43fe..c736f1ca57 100644 --- a/src/Mapping/Annotations/DiscriminatorField.php +++ b/src/Mapping/Annotations/DiscriminatorField.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Specify a field name to store a discriminator value - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_CLASS)] final class DiscriminatorField implements Annotation diff --git a/src/Mapping/Annotations/DiscriminatorMap.php b/src/Mapping/Annotations/DiscriminatorMap.php index 644e244432..ab4d4ed635 100644 --- a/src/Mapping/Annotations/DiscriminatorMap.php +++ b/src/Mapping/Annotations/DiscriminatorMap.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Specify a map of discriminator values and classes - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY)] final class DiscriminatorMap implements Annotation diff --git a/src/Mapping/Annotations/DiscriminatorValue.php b/src/Mapping/Annotations/DiscriminatorValue.php index 069e0cffe6..94ae1cadb6 100644 --- a/src/Mapping/Annotations/DiscriminatorValue.php +++ b/src/Mapping/Annotations/DiscriminatorValue.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Use the specified discriminator for this class - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_CLASS)] final class DiscriminatorValue implements Annotation diff --git a/src/Mapping/Annotations/Document.php b/src/Mapping/Annotations/Document.php index 746bdcbdb6..1db3ee4b86 100644 --- a/src/Mapping/Annotations/Document.php +++ b/src/Mapping/Annotations/Document.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Identifies a class as a document that can be stored in the database - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_CLASS)] final class Document extends AbstractDocument diff --git a/src/Mapping/Annotations/EmbedMany.php b/src/Mapping/Annotations/EmbedMany.php index e693929c9a..914007bcde 100644 --- a/src/Mapping/Annotations/EmbedMany.php +++ b/src/Mapping/Annotations/EmbedMany.php @@ -5,15 +5,11 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\Utility\CollectionHelper; /** * Embeds multiple documents - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_PROPERTY)] final class EmbedMany extends AbstractField diff --git a/src/Mapping/Annotations/EmbedOne.php b/src/Mapping/Annotations/EmbedOne.php index 6a260ec0e2..3f3d91b54e 100644 --- a/src/Mapping/Annotations/EmbedOne.php +++ b/src/Mapping/Annotations/EmbedOne.php @@ -5,14 +5,10 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; /** * Embeds a single document - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_PROPERTY)] final class EmbedOne extends AbstractField diff --git a/src/Mapping/Annotations/EmbeddedDocument.php b/src/Mapping/Annotations/EmbeddedDocument.php index 5b68f7a5a6..11488ebfcf 100644 --- a/src/Mapping/Annotations/EmbeddedDocument.php +++ b/src/Mapping/Annotations/EmbeddedDocument.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Identifies a class as a document that can be embedded but not stored by itself - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_CLASS)] final class EmbeddedDocument extends AbstractDocument diff --git a/src/Mapping/Annotations/Encrypt.php b/src/Mapping/Annotations/Encrypt.php index 1f7fbc90e4..769a9df3db 100644 --- a/src/Mapping/Annotations/Encrypt.php +++ b/src/Mapping/Annotations/Encrypt.php @@ -6,7 +6,6 @@ use Attribute; use DateTimeInterface; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\BSON\UTCDateTime; @@ -15,9 +14,6 @@ * Defines an encrypted field mapping. * * @see https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query/#configure-encrypted-fields-for-optimal-search-and-storage - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY)] final class Encrypt implements Annotation diff --git a/src/Mapping/Annotations/Field.php b/src/Mapping/Annotations/Field.php index 39c22362b7..19518bbf57 100644 --- a/src/Mapping/Annotations/Field.php +++ b/src/Mapping/Annotations/Field.php @@ -6,13 +6,9 @@ use Attribute; use BackedEnum; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Specifies a generic field mapping - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_PROPERTY)] final class Field extends AbstractField diff --git a/src/Mapping/Annotations/File.php b/src/Mapping/Annotations/File.php index 2421cfe53a..3f39626eb4 100644 --- a/src/Mapping/Annotations/File.php +++ b/src/Mapping/Annotations/File.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Identifies a class as a GridFS file that can be stored in the database - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_CLASS)] final class File extends AbstractDocument diff --git a/src/Mapping/Annotations/File/ChunkSize.php b/src/Mapping/Annotations/File/ChunkSize.php index 0043be358a..30a8f4732f 100644 --- a/src/Mapping/Annotations/File/ChunkSize.php +++ b/src/Mapping/Annotations/File/ChunkSize.php @@ -5,13 +5,8 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations\File; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\ODM\MongoDB\Mapping\Annotations\AbstractField; -/** - * @Annotation - * @NamedArgumentConstructor - */ #[Attribute(Attribute::TARGET_PROPERTY)] final class ChunkSize extends AbstractField { diff --git a/src/Mapping/Annotations/File/Filename.php b/src/Mapping/Annotations/File/Filename.php index 260a78afd3..97f8728649 100644 --- a/src/Mapping/Annotations/File/Filename.php +++ b/src/Mapping/Annotations/File/Filename.php @@ -5,13 +5,8 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations\File; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\ODM\MongoDB\Mapping\Annotations\AbstractField; -/** - * @Annotation - * @NamedArgumentConstructor - */ #[Attribute(Attribute::TARGET_PROPERTY)] final class Filename extends AbstractField { diff --git a/src/Mapping/Annotations/File/Length.php b/src/Mapping/Annotations/File/Length.php index b960ae29bc..69238a8076 100644 --- a/src/Mapping/Annotations/File/Length.php +++ b/src/Mapping/Annotations/File/Length.php @@ -5,13 +5,8 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations\File; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\ODM\MongoDB\Mapping\Annotations\AbstractField; -/** - * @Annotation - * @NamedArgumentConstructor - */ #[Attribute(Attribute::TARGET_PROPERTY)] final class Length extends AbstractField { diff --git a/src/Mapping/Annotations/File/Metadata.php b/src/Mapping/Annotations/File/Metadata.php index 16c06265ce..2f2dc330b6 100644 --- a/src/Mapping/Annotations/File/Metadata.php +++ b/src/Mapping/Annotations/File/Metadata.php @@ -5,14 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations\File; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\ODM\MongoDB\Mapping\Annotations\AbstractField; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; -/** - * @Annotation - * @NamedArgumentConstructor - */ #[Attribute(Attribute::TARGET_PROPERTY)] final class Metadata extends AbstractField { diff --git a/src/Mapping/Annotations/File/UploadDate.php b/src/Mapping/Annotations/File/UploadDate.php index 1454fe993d..40b591ae77 100644 --- a/src/Mapping/Annotations/File/UploadDate.php +++ b/src/Mapping/Annotations/File/UploadDate.php @@ -5,13 +5,8 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations\File; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\ODM\MongoDB\Mapping\Annotations\AbstractField; -/** - * @Annotation - * @NamedArgumentConstructor - */ #[Attribute(Attribute::TARGET_PROPERTY)] final class UploadDate extends AbstractField { diff --git a/src/Mapping/Annotations/HasLifecycleCallbacks.php b/src/Mapping/Annotations/HasLifecycleCallbacks.php index aaa8dd6e31..75401d8ed3 100644 --- a/src/Mapping/Annotations/HasLifecycleCallbacks.php +++ b/src/Mapping/Annotations/HasLifecycleCallbacks.php @@ -9,8 +9,6 @@ /** * Must be set on a document class to instruct Doctrine to check for lifecycle * callback annotations on public methods. - * - * @Annotation */ #[Attribute(Attribute::TARGET_CLASS)] final class HasLifecycleCallbacks implements Annotation diff --git a/src/Mapping/Annotations/Id.php b/src/Mapping/Annotations/Id.php index ab48d9d8b2..021921c911 100644 --- a/src/Mapping/Annotations/Id.php +++ b/src/Mapping/Annotations/Id.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Special field mapping to map document identifiers - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_PROPERTY)] final class Id extends AbstractField diff --git a/src/Mapping/Annotations/Index.php b/src/Mapping/Annotations/Index.php index 378a67a3fc..a220b736e5 100644 --- a/src/Mapping/Annotations/Index.php +++ b/src/Mapping/Annotations/Index.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Defines an index on a field - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)] final class Index extends AbstractIndex diff --git a/src/Mapping/Annotations/InheritanceType.php b/src/Mapping/Annotations/InheritanceType.php index 45c14f1460..7e799df74a 100644 --- a/src/Mapping/Annotations/InheritanceType.php +++ b/src/Mapping/Annotations/InheritanceType.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Specifies which inheritance type to use for a document - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_CLASS)] final class InheritanceType implements Annotation diff --git a/src/Mapping/Annotations/Lock.php b/src/Mapping/Annotations/Lock.php index ac5bd5ee48..72d7132e40 100644 --- a/src/Mapping/Annotations/Lock.php +++ b/src/Mapping/Annotations/Lock.php @@ -8,8 +8,6 @@ /** * Specifies a field to use for pessimistic locking - * - * @Annotation */ #[Attribute(Attribute::TARGET_PROPERTY)] final class Lock implements Annotation diff --git a/src/Mapping/Annotations/MappedSuperclass.php b/src/Mapping/Annotations/MappedSuperclass.php index 8b1ebe9bff..928ecf6be4 100644 --- a/src/Mapping/Annotations/MappedSuperclass.php +++ b/src/Mapping/Annotations/MappedSuperclass.php @@ -5,14 +5,10 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Specifies a parent class that other documents may extend to inherit mapping * information - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_CLASS)] final class MappedSuperclass extends AbstractDocument diff --git a/src/Mapping/Annotations/PostLoad.php b/src/Mapping/Annotations/PostLoad.php index fe09676f82..faf7420a35 100644 --- a/src/Mapping/Annotations/PostLoad.php +++ b/src/Mapping/Annotations/PostLoad.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Marks a method as a postLoad lifecycle callback - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_METHOD)] final class PostLoad implements Annotation diff --git a/src/Mapping/Annotations/PostPersist.php b/src/Mapping/Annotations/PostPersist.php index c0436d1279..29e51f10a5 100644 --- a/src/Mapping/Annotations/PostPersist.php +++ b/src/Mapping/Annotations/PostPersist.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Marks a method as a postPersist lifecycle callback - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_METHOD)] final class PostPersist implements Annotation diff --git a/src/Mapping/Annotations/PostRemove.php b/src/Mapping/Annotations/PostRemove.php index dbdb6ee11a..c1b6fe2173 100644 --- a/src/Mapping/Annotations/PostRemove.php +++ b/src/Mapping/Annotations/PostRemove.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Marks a method as a postRemove lifecycle callback - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_METHOD)] final class PostRemove implements Annotation diff --git a/src/Mapping/Annotations/PostUpdate.php b/src/Mapping/Annotations/PostUpdate.php index d4180be0d2..8e7e43ed03 100644 --- a/src/Mapping/Annotations/PostUpdate.php +++ b/src/Mapping/Annotations/PostUpdate.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Marks a method as a postUpdate lifecycle callback - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_METHOD)] final class PostUpdate implements Annotation diff --git a/src/Mapping/Annotations/PreFlush.php b/src/Mapping/Annotations/PreFlush.php index 671d0ad3a5..d0df1d1632 100644 --- a/src/Mapping/Annotations/PreFlush.php +++ b/src/Mapping/Annotations/PreFlush.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Marks a method as a preFlush lifecycle callback - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_METHOD)] final class PreFlush implements Annotation diff --git a/src/Mapping/Annotations/PreLoad.php b/src/Mapping/Annotations/PreLoad.php index 301ae03185..548c714df4 100644 --- a/src/Mapping/Annotations/PreLoad.php +++ b/src/Mapping/Annotations/PreLoad.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Marks a method as a preLoad lifecycle callback - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_METHOD)] final class PreLoad implements Annotation diff --git a/src/Mapping/Annotations/PrePersist.php b/src/Mapping/Annotations/PrePersist.php index a83245f37f..998dea4eeb 100644 --- a/src/Mapping/Annotations/PrePersist.php +++ b/src/Mapping/Annotations/PrePersist.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Marks a method as a prePersist lifecycle callback - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_METHOD)] final class PrePersist implements Annotation diff --git a/src/Mapping/Annotations/PreRemove.php b/src/Mapping/Annotations/PreRemove.php index de11425c9a..0c5effc10f 100644 --- a/src/Mapping/Annotations/PreRemove.php +++ b/src/Mapping/Annotations/PreRemove.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Marks a method as a preRemove lifecycle callback - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_METHOD)] final class PreRemove implements Annotation diff --git a/src/Mapping/Annotations/PreUpdate.php b/src/Mapping/Annotations/PreUpdate.php index 1b75ac781d..869659a5c6 100644 --- a/src/Mapping/Annotations/PreUpdate.php +++ b/src/Mapping/Annotations/PreUpdate.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Marks a method as a preUpdate lifecycle callback - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_METHOD)] final class PreUpdate implements Annotation diff --git a/src/Mapping/Annotations/QueryResultDocument.php b/src/Mapping/Annotations/QueryResultDocument.php index 7039daf809..4d73ce9486 100644 --- a/src/Mapping/Annotations/QueryResultDocument.php +++ b/src/Mapping/Annotations/QueryResultDocument.php @@ -5,12 +5,7 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; -/** - * @Annotation - * @NamedArgumentConstructor - */ #[Attribute(Attribute::TARGET_CLASS)] final class QueryResultDocument extends AbstractDocument { diff --git a/src/Mapping/Annotations/ReadPreference.php b/src/Mapping/Annotations/ReadPreference.php index 536f292e8b..cf4434368d 100644 --- a/src/Mapping/Annotations/ReadPreference.php +++ b/src/Mapping/Annotations/ReadPreference.php @@ -5,12 +5,7 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; -/** - * @Annotation - * @NamedArgumentConstructor - */ #[Attribute(Attribute::TARGET_CLASS)] final class ReadPreference implements Annotation { diff --git a/src/Mapping/Annotations/ReferenceMany.php b/src/Mapping/Annotations/ReferenceMany.php index a4afe8c9ec..e9251694fb 100644 --- a/src/Mapping/Annotations/ReferenceMany.php +++ b/src/Mapping/Annotations/ReferenceMany.php @@ -5,15 +5,11 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\Utility\CollectionHelper; /** * Specifies a one-to-many relationship to a different document - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_PROPERTY)] final class ReferenceMany extends AbstractField diff --git a/src/Mapping/Annotations/ReferenceOne.php b/src/Mapping/Annotations/ReferenceOne.php index 7e89191fe8..3e1f1ef624 100644 --- a/src/Mapping/Annotations/ReferenceOne.php +++ b/src/Mapping/Annotations/ReferenceOne.php @@ -5,14 +5,10 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; /** * Specifies a one-to-one relationship to a different document - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_PROPERTY)] final class ReferenceOne extends AbstractField diff --git a/src/Mapping/Annotations/SearchIndex.php b/src/Mapping/Annotations/SearchIndex.php index 77b6fa47d6..d0c4da347d 100644 --- a/src/Mapping/Annotations/SearchIndex.php +++ b/src/Mapping/Annotations/SearchIndex.php @@ -5,7 +5,6 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; /** @@ -13,8 +12,6 @@ * * @see https://www.mongodb.com/docs/atlas/atlas-search/index-definitions/ * - * @Annotation - * @NamedArgumentConstructor * @phpstan-import-type SearchIndexStoredSource from ClassMetadata * @phpstan-import-type SearchIndexSynonym from ClassMetadata */ diff --git a/src/Mapping/Annotations/ShardKey.php b/src/Mapping/Annotations/ShardKey.php index 81ef9218ee..65f6f3820b 100644 --- a/src/Mapping/Annotations/ShardKey.php +++ b/src/Mapping/Annotations/ShardKey.php @@ -5,12 +5,7 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; -/** - * @Annotation - * @NamedArgumentConstructor - */ #[Attribute(Attribute::TARGET_CLASS)] final class ShardKey implements Annotation { diff --git a/src/Mapping/Annotations/TimeSeries.php b/src/Mapping/Annotations/TimeSeries.php index e4fe593eb4..2ae1f9a1d3 100644 --- a/src/Mapping/Annotations/TimeSeries.php +++ b/src/Mapping/Annotations/TimeSeries.php @@ -5,14 +5,10 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\ODM\MongoDB\Mapping\TimeSeries\Granularity; /** * Marks a document or superclass as a time series document - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_CLASS)] final class TimeSeries implements Annotation diff --git a/src/Mapping/Annotations/UniqueIndex.php b/src/Mapping/Annotations/UniqueIndex.php index 371fe66e25..c6cb423b44 100644 --- a/src/Mapping/Annotations/UniqueIndex.php +++ b/src/Mapping/Annotations/UniqueIndex.php @@ -5,13 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; /** * Specifies a unique index on a field - * - * @Annotation - * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)] final class UniqueIndex extends AbstractIndex diff --git a/src/Mapping/Annotations/Validation.php b/src/Mapping/Annotations/Validation.php index c773264b89..cde85b9f7e 100644 --- a/src/Mapping/Annotations/Validation.php +++ b/src/Mapping/Annotations/Validation.php @@ -5,37 +5,18 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; -/** - * @Annotation - * @NamedArgumentConstructor - * @Target({"CLASS"}) - */ #[Attribute(Attribute::TARGET_CLASS)] class Validation implements Annotation { /** @var string|null */ public $validator; - /** - * @var string|null - * @Enum({ - * ClassMetadata::SCHEMA_VALIDATION_ACTION_ERROR, - * ClassMetadata::SCHEMA_VALIDATION_ACTION_WARN, - * }) - */ + /** @var ClassMetadata::SCHEMA_VALIDATION_ACTION_ERROR|ClassMetadata::SCHEMA_VALIDATION_ACTION_WARN|null */ public $action; - /** - * @var string|null - * @Enum({ - * ClassMetadata::SCHEMA_VALIDATION_LEVEL_OFF, - * ClassMetadata::SCHEMA_VALIDATION_LEVEL_STRICT, - * ClassMetadata::SCHEMA_VALIDATION_LEVEL_MODERATE, - * }) - */ + /** @var ClassMetadata::SCHEMA_VALIDATION_LEVEL_OFF|ClassMetadata::SCHEMA_VALIDATION_LEVEL_STRICT|ClassMetadata::SCHEMA_VALIDATION_LEVEL_MODERATE|null */ public $level; public function __construct(?string $validator = null, ?string $action = null, ?string $level = null) diff --git a/src/Mapping/Annotations/VectorSearchIndex.php b/src/Mapping/Annotations/VectorSearchIndex.php index ed8f281504..e6f5b2c65a 100644 --- a/src/Mapping/Annotations/VectorSearchIndex.php +++ b/src/Mapping/Annotations/VectorSearchIndex.php @@ -5,7 +5,6 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; /** @@ -13,8 +12,6 @@ * * @see https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-type/ * - * @Annotation - * @NamedArgumentConstructor * @phpstan-import-type VectorSearchIndexField from ClassMetadata */ #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] diff --git a/src/Mapping/Annotations/Version.php b/src/Mapping/Annotations/Version.php index fe6da61a70..a71c5be4c4 100644 --- a/src/Mapping/Annotations/Version.php +++ b/src/Mapping/Annotations/Version.php @@ -8,8 +8,6 @@ /** * Specifies a field to use for optimistic locking - * - * @Annotation */ #[Attribute(Attribute::TARGET_PROPERTY)] final class Version implements Annotation diff --git a/src/Mapping/Annotations/View.php b/src/Mapping/Annotations/View.php index adab26dc92..7c2ab00b94 100644 --- a/src/Mapping/Annotations/View.php +++ b/src/Mapping/Annotations/View.php @@ -5,12 +5,7 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; -/** - * @Annotation - * @NamedArgumentConstructor - */ #[Attribute(Attribute::TARGET_CLASS)] final class View extends AbstractDocument { diff --git a/src/Mapping/Driver/AnnotationDriver.php b/src/Mapping/Driver/AnnotationDriver.php deleted file mode 100644 index d7c480d821..0000000000 --- a/src/Mapping/Driver/AnnotationDriver.php +++ /dev/null @@ -1,49 +0,0 @@ -reader = $reader; - } - - /** - * Factory method for the Annotation Driver - * - * @param string|string[]|ClassLocator $paths - */ - public static function create($paths = [], ?Reader $reader = null): AnnotationDriver - { - return new self($reader ?? new AnnotationReader(), $paths); - } -} diff --git a/src/Mapping/Driver/AttributeDriver.php b/src/Mapping/Driver/AttributeDriver.php index 31d86e84d3..7fae89101e 100644 --- a/src/Mapping/Driver/AttributeDriver.php +++ b/src/Mapping/Driver/AttributeDriver.php @@ -4,7 +4,6 @@ namespace Doctrine\ODM\MongoDB\Mapping\Driver; -use Doctrine\Common\Annotations\Reader; use Doctrine\ODM\MongoDB\Events; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\Mapping\Annotations\AbstractIndex; @@ -38,26 +37,12 @@ class AttributeDriver implements MappingDriver { use ColocatedMappingDriver; - /** - * @internal this property will be private in 3.0 - * - * @var Reader|AttributeReader - */ - protected $reader; + private AttributeReader $reader; /** @param string|string[]|ClassLocator|null $paths */ - public function __construct($paths = null, ?Reader $reader = null) + public function __construct($paths = null) { - if ($reader !== null) { - trigger_deprecation( - 'doctrine/mongodb-odm', - '2.7', - 'Passing a $reader parameter to %s is deprecated', - __METHOD__, - ); - } - - $this->reader = $reader ?? new AttributeReader(); + $this->reader = new AttributeReader(); if ($paths instanceof ClassLocator) { $this->classLocator = $paths; @@ -388,58 +373,33 @@ private function setShardKey(ClassMetadata $class, ODM\ShardKey $shardKey): void $class->setShardKey($shardKey->keys, $options); } - /** @return Reader|AttributeReader */ - public function getReader() - { - trigger_deprecation( - 'doctrine/mongodb-odm', - '2.4', - '%s is deprecated with no replacement', - __METHOD__, - ); - - return $this->reader; - } - /** * Factory method for the Attribute Driver * * @param string|string[]|ClassLocator $paths * - * @return AttributeDriver + * @return self */ - public static function create($paths = [], ?Reader $reader = null) + public static function create($paths = []) { - return new self($paths, $reader); + return new self($paths); } /** @return object[] */ private function getClassAttributes(ReflectionClass $class): array { - if ($this->reader instanceof AttributeReader) { - return $this->reader->getClassAttributes($class); - } - - return $this->reader->getClassAnnotations($class); + return $this->reader->getClassAttributes($class); } /** @return object[] */ private function getMethodAttributes(ReflectionMethod $method): array { - if ($this->reader instanceof AttributeReader) { - return $this->reader->getMethodAttributes($method); - } - - return $this->reader->getMethodAnnotations($method); + return $this->reader->getMethodAttributes($method); } /** @return object[] */ private function getPropertyAttributes(ReflectionProperty $property): array { - if ($this->reader instanceof AttributeReader) { - return $this->reader->getPropertyAttributes($property); - } - - return $this->reader->getPropertyAnnotations($property); + return $this->reader->getPropertyAttributes($property); } } diff --git a/tests/Documents/Card.php b/tests/Documents/Card.php index 6589303aaf..6d2be47303 100644 --- a/tests/Documents/Card.php +++ b/tests/Documents/Card.php @@ -6,31 +6,22 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -/** @ODM\Document */ #[ODM\Document] class Card { - /** @ODM\Id */ #[ODM\Id] public string $id; - /** @ODM\Field() */ #[ODM\Field()] public Suit $suit; - /** @ODM\Field() */ #[ODM\Field()] public ?SuitInt $suitInt; - /** @ODM\Field(type="string", enumType=Suit::class, nullable=true) */ #[ODM\Field(type: 'string', enumType: Suit::class, nullable: true)] public ?Suit $nullableSuit; - /** - * @ODM\Field(enumType=Suit::class) - * - * @var Suit[] - */ + /** @var Suit[] */ #[ODM\Field(enumType: Suit::class)] public array $suits; diff --git a/tests/Documents/CmsUser.php b/tests/Documents/CmsUser.php index 17a8a38f4a..ffdb1f89d2 100644 --- a/tests/Documents/CmsUser.php +++ b/tests/Documents/CmsUser.php @@ -8,71 +8,38 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -/** @ODM\Document */ #[ODM\Document] class CmsUser { - /** - * @ODM\Id - * - * @var string|null - */ + /** @var string|null */ #[ODM\Id] public $id; - /** - * @ODM\Field(type="string") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string')] public $status; - /** - * @ODM\Field(type="string") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string')] public $username; - /** - * @ODM\Field(type="string") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string')] public $name; - /** - * @ODM\ReferenceMany(targetDocument=CmsPhonenumber::class, mappedBy="user", cascade={"persist", "remove", "merge"}) - * - * @var Collection - */ + /** @var Collection */ #[ODM\ReferenceMany(targetDocument: CmsPhonenumber::class, mappedBy: 'user', cascade: ['persist', 'remove', 'merge'])] public $phonenumbers; - /** - * @ODM\ReferenceMany(targetDocument=CmsArticle::class) - * - * @var Collection - */ + /** @var Collection */ #[ODM\ReferenceMany(targetDocument: CmsArticle::class)] public $articles; - /** - * @ODM\ReferenceOne(targetDocument=CmsAddress::class, cascade={"persist"}) - * - * @var CmsAddress - */ + /** @var CmsAddress */ #[ODM\ReferenceOne(targetDocument: CmsAddress::class, cascade: ['persist'])] public $address; - /** - * @ODM\ReferenceMany(targetDocument=CmsGroup::class, cascade={"persist", "merge"}) - * - * @var Collection - */ + /** @var Collection */ #[ODM\ReferenceMany(targetDocument: CmsGroup::class, cascade: ['persist', 'merge'])] public $groups; diff --git a/tests/Documents/FileWithoutMetadata.php b/tests/Documents/FileWithoutMetadata.php index 806276b2bf..de73531fdb 100644 --- a/tests/Documents/FileWithoutMetadata.php +++ b/tests/Documents/FileWithoutMetadata.php @@ -13,11 +13,7 @@ class FileWithoutMetadata #[ODM\Id] private $id; - /** - * @ODM\File\Filename - * - * @var string|null - */ + /** @var string|null */ #[ODM\File\Filename] private $filename; diff --git a/tests/Documents/UserTyped.php b/tests/Documents/UserTyped.php index 2f04093c32..20ac520c5a 100644 --- a/tests/Documents/UserTyped.php +++ b/tests/Documents/UserTyped.php @@ -8,59 +8,39 @@ use DateTimeImmutable; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -/** @ODM\Document() */ #[ODM\Document] class UserTyped { - /** @ODM\Id */ #[ODM\Id] public string $id; - /** @ODM\Field */ #[ODM\Field] public string $username; - /** @ODM\Field */ #[ODM\Field] public DateTime $dateTime; - /** @ODM\Field */ #[ODM\Field] public DateTimeImmutable $dateTimeImmutable; - /** - * @ODM\Field - * - * @var mixed[] - */ + /** @var mixed[] */ #[ODM\Field] public array $array; - /** @ODM\Field */ #[ODM\Field] public bool $boolean; - /** @ODM\Field */ #[ODM\Field] public float $float; - /** @ODM\Field */ #[ODM\Field] public int $int; - /** - * @ODM\EmbedMany - * - * @var CustomCollection - */ + /** @var CustomCollection */ #[ODM\EmbedMany] public CustomCollection $embedMany; - /** - * @ODM\ReferenceMany - * - * @var CustomCollection - */ + /** @var CustomCollection */ #[ODM\ReferenceMany] public CustomCollection $referenceMany; } diff --git a/tests/Tests/Events/TransactionalLifecycleEventsTest.php b/tests/Tests/Events/TransactionalLifecycleEventsTest.php index d0567a57ea..30157e2011 100644 --- a/tests/Tests/Events/TransactionalLifecycleEventsTest.php +++ b/tests/Tests/Events/TransactionalLifecycleEventsTest.php @@ -196,7 +196,6 @@ public function __construct() public int $postRemove = 0; - /** @ODM\PreUpdate */ #[ODM\PreUpdate] public function preUpdate(Event\PreUpdateEventArgs $e): void { diff --git a/tests/Tests/Functional/EmbeddedTest.php b/tests/Tests/Functional/EmbeddedTest.php index cbd13de081..e5200ce89b 100644 --- a/tests/Tests/Functional/EmbeddedTest.php +++ b/tests/Tests/Functional/EmbeddedTest.php @@ -607,7 +607,7 @@ public function testReusedEmbeddedDocumentsAreClonedInFact(): void public function testEmbeddedDocumentWithDifferentFieldNameAnnotation(): void { - $test1 = new ChangeEmbeddedWithNameAnnotationTest(); + $test1 = new ChangeEmbeddedWithNameAttributeTest(); $embedded = new EmbeddedDocumentWithId(); $embedded->id = (string) new ObjectId(); @@ -624,7 +624,7 @@ public function testEmbeddedDocumentWithDifferentFieldNameAnnotation(): void $this->dm->flush(); - $test1Data = $this->dm->createQueryBuilder(ChangeEmbeddedWithNameAnnotationTest::class) + $test1Data = $this->dm->createQueryBuilder(ChangeEmbeddedWithNameAttributeTest::class) ->hydrate(false) ->field('id') ->equals($test1->id) @@ -667,7 +667,7 @@ class EmbeddedDocumentWithId } #[ODM\Document] -class ChangeEmbeddedWithNameAnnotationTest +class ChangeEmbeddedWithNameAttributeTest { /** @var string|null */ #[ODM\Id] diff --git a/tests/Tests/Functional/IndexesTest.php b/tests/Tests/Functional/IndexesTest.php index 255f861158..38ca81a562 100644 --- a/tests/Tests/Functional/IndexesTest.php +++ b/tests/Tests/Functional/IndexesTest.php @@ -81,9 +81,9 @@ public function testDiscriminatorIndexes(): void self::assertEquals(1, $indexes[0]['keys']['type']); } - public function testMultipleIndexAnnotations(): void + public function testMultipleIndexAttributes(): void { - $class = $this->dm->getClassMetadata(DocumentWithMultipleIndexAnnotations::class); + $class = $this->dm->getClassMetadata(DocumentWithMultipleIndexAttributes::class); $sm = $this->dm->getSchemaManager(); $indexes = $sm->getDocumentIndexes($class->name); @@ -460,7 +460,7 @@ class DocumentWithDiscriminatorIndex #[ODM\Index(keys: ['name' => 'asc'])] #[ODM\Index(keys: ['name' => 'desc'])] #[ODM\UniqueIndex(keys: ['name' => 'asc'], options: ['sparse' => true])] -class DocumentWithMultipleIndexAnnotations +class DocumentWithMultipleIndexAttributes { /** @var string|null */ #[ODM\Id] diff --git a/tests/Tests/Functional/Ticket/GH774Test.php b/tests/Tests/Functional/Ticket/GH774Test.php index 8d1836d558..be2501a7a5 100644 --- a/tests/Tests/Functional/Ticket/GH774Test.php +++ b/tests/Tests/Functional/Ticket/GH774Test.php @@ -36,11 +36,7 @@ protected static function createMetadataDriverImpl(): MappingDriver abstract class GH774AbstractThread { - /** - * @ODM\Id - * - * @var string|null - */ + /** @var string|null */ public $id; /** @var string|null */ diff --git a/tests/Tests/Functional/Ticket/MODM52Test.php b/tests/Tests/Functional/Ticket/MODM52Test.php index 472798bdaf..b9d9d505e3 100644 --- a/tests/Tests/Functional/Ticket/MODM52Test.php +++ b/tests/Tests/Functional/Ticket/MODM52Test.php @@ -36,7 +36,7 @@ public function testTest(): void } } -/** @ODM\MappedSuperClass */ + class MODM52Container { /** @var string|null */ diff --git a/tests/Tests/Mapping/AbstractAnnotationDriverTestCase.php b/tests/Tests/Mapping/AbstractAnnotationDriverTestCase.php deleted file mode 100644 index b90e6f54f4..0000000000 --- a/tests/Tests/Mapping/AbstractAnnotationDriverTestCase.php +++ /dev/null @@ -1,358 +0,0 @@ -dm->getClassMetadata(AnnotationDriverTestSuper::class); - $parent = $this->dm->getClassMetadata(AnnotationDriverTestParent::class); - $child = $this->dm->getClassMetadata(AnnotationDriverTestChild::class); - - self::assertFalse($super->hasField('id'), 'MappedSuperclass does not register its own public field'); - self::assertFalse($super->hasField('protected'), 'MappedSuperclass does not register its own protected field'); - self::assertTrue($super->hasField('private'), 'MappedSuperclass does register its own private field'); - self::assertFalse($super->isInheritedField('private'), 'MappedSuperclass does not inherit its own field'); - self::assertFalse($super->hasField('foo'), 'MappedSuperclass does not have field declared in child Document'); - self::assertFalse($super->hasField('bar'), 'MappedSuperclass does not have field declared in grandchild Document'); - - self::assertArrayNotHasKey('declared', $super->fieldMappings['private'], 'MappedSuperclass does not track "declared" for non-inherited field'); - - self::assertTrue($parent->hasField('id'), 'Document does have public field from MappedSuperclass parent'); - self::assertFalse($parent->isInheritedField('id'), 'Document does not inherit public field from MappedSuperclass parent'); - self::assertTrue($parent->hasField('protected'), 'Document does have protected field from MappedSuperclass parent'); - self::assertFalse($parent->isInheritedField('protected'), 'Document does not inherit protected field from MappedSuperclass parent'); - self::assertTrue($parent->hasField('private'), 'Document does have private field from MappedSuperclass parent'); - /* MappedSuperclass fields are never considered "inherited", but the - * field is still considered "declared" in the MappedSuperclass, since - * we need its ReflectionProperty to access it. This is a bit weird. - */ - self::assertFalse($parent->isInheritedField('private'), 'Document does not inherit private field from MappedSuperclass parent'); - self::assertTrue($parent->hasField('foo'), 'Document does register its own public field'); - self::assertFalse($parent->isInheritedField('foo'), 'Document does not inherit its own field'); - self::assertFalse($parent->hasField('bar'), 'Document does not have field declared in child Document'); - - self::assertArrayNotHasKey('declared', $parent->fieldMappings['id'], 'Document does not track "declared" for non-inherited public field from MappedSuperclass parent'); - self::assertArrayNotHasKey('declared', $parent->fieldMappings['protected'], 'Document does not track "declared" for non-inherited protected field from MappedSuperclass parent'); - self::assertEquals(AnnotationDriverTestSuper::class, $parent->fieldMappings['private']['declared'], 'Non-inherited private field from MappedSuperclass parent is declared in MappedSuperclass parent'); - self::assertArrayNotHasKey('declared', $parent->fieldMappings['foo'], 'Document does not track "declared" for its own public field'); - - self::assertTrue($child->hasField('id'), 'Document does have public field from MappedSuperclass grandparent'); - self::assertTrue($child->isInheritedField('id'), 'Document does inherit public field from MappedSuperclass grandparent'); - self::assertTrue($child->hasField('protected'), 'Document does have protected field from MappedSuperclass grandparent'); - self::assertTrue($child->isInheritedField('protected'), 'Document does inherit protected field from MappedSuperclass grandparent'); - self::assertTrue($child->hasField('private'), 'Document does have private field from MappedSuperclass grandparent'); - self::assertTrue($child->isInheritedField('private'), 'Document does inherit private field from MappedSuperclass grandparent'); - self::assertTrue($child->hasField('foo'), 'Document does have public field from Document parent'); - self::assertTrue($child->isInheritedField('foo'), 'Document field declared in Document parent is inherited'); - self::assertTrue($child->hasField('bar'), 'Document does register its own public field'); - self::assertFalse($child->isInheritedField('bar'), 'Document does not inherit its own field'); - - self::assertEquals(AnnotationDriverTestParent::class, $child->fieldMappings['id']['declared'], 'Inherited public field from MappedSuperclass grandparent is declared in Document parent'); - self::assertEquals(AnnotationDriverTestParent::class, $child->fieldMappings['protected']['declared'], 'Inherited protected field from MappedSuperclass grandparent is declared in Document parent'); - self::assertEquals(AnnotationDriverTestSuper::class, $child->fieldMappings['private']['declared'], 'Inherited private field from MappedSuperclass grandparent is declared in MappedSuperclass grandparent'); - self::assertEquals(AnnotationDriverTestParent::class, $child->fieldMappings['foo']['declared'], 'Inherited public field from Document parent is declared in Document parent'); - } - - public function testLoadMetadataForNonDocumentThrowsException(): void - { - $cm = new ClassMetadata('stdClass'); - $annotationDriver = static::loadDriver(); - - $this->expectException(MappingException::class); - $annotationDriver->loadMetadataForClass('stdClass', $cm); - } - - public function testColumnWithMissingTypeDefaultsToString(): void - { - $cm = new ClassMetadata(ColumnWithoutType::class); - $annotationDriver = static::loadDriver(); - - $annotationDriver->loadMetadataForClass(stdClass::class, $cm); - self::assertEquals('id', $cm->fieldMappings['id']['type']); - } - - public function testGetAllClassNamesReturnsAlreadyLoadedClassesIfAppropriate(): void - { - self::assertTrue(class_exists(CmsUser::class), 'Pre-load the class'); - $annotationDriver = $this->loadDriverForCMSDocuments(); - $classes = $annotationDriver->getAllClassNames(); - - self::assertContains(CmsUser::class, $classes); - } - - public function testGetClassNamesReturnsOnlyTheAppropriateClasses(): void - { - $extraneousClassName = ColumnWithoutType::class; - - $annotationDriver = $this->loadDriverForCMSDocuments(); - $classes = $annotationDriver->getAllClassNames(); - - self::assertNotContains($extraneousClassName, $classes); - } - - public function testEmbeddedClassCantHaveShardKey(): void - { - $this->expectException(MappingException::class); - $this->expectExceptionMessage('Embedded document can\'t have shard key'); - $this->dm->getClassMetadata(AnnotationDriverEmbeddedWithShardKey::class); - } - - public function testDocumentAnnotationCanSpecifyWriteConcern(): void - { - $cm = $this->dm->getClassMetadata(AnnotationDriverTestWriteConcernMajority::class); - self::assertSame('majority', $cm->writeConcern); - - $cm = $this->dm->getClassMetadata(AnnotationDriverTestWriteConcernUnacknowledged::class); - self::assertSame(0, $cm->writeConcern); - - $cm = $this->dm->getClassMetadata(ColumnWithoutType::class); - self::assertNull($cm->writeConcern); - } - - #[DataProvider('provideClassCanBeMappedByOneAbstractDocument')] - public function testClassCanBeMappedByOneAbstractDocument(object $wrong, string $messageRegExp): void - { - $this->expectException(MappingException::class); - $this->expectExceptionMessageMatches($messageRegExp); - - $cm = new ClassMetadata($wrong::class); - $driver = static::loadDriver(); - - $driver->loadMetadataForClass($wrong::class, $cm); - } - - public static function provideClassCanBeMappedByOneAbstractDocument(): ?Generator - { - yield [ - /** - * @ODM\Document() - * @ODM\EmbeddedDocument - */ - new #[ODM\Document] - #[ODM\EmbeddedDocument] - class () { - }, - '/as EmbeddedDocument because it was already mapped as Document\.$/', - ]; - - yield [ - /** - * @ODM\Document() - * @ODM\File - */ - new #[ODM\Document] - #[ODM\File] - class () { - }, - '/as File because it was already mapped as Document\.$/', - ]; - - yield [ - /** - * @ODM\Document() - * @ODM\QueryResultDocument - */ - new #[ODM\Document] - #[ODM\QueryResultDocument] - class () { - }, - '/as QueryResultDocument because it was already mapped as Document\.$/', - ]; - - yield [ - /** - * @ODM\Document() - * @ODM\View - */ - new #[ODM\Document] - #[ODM\View] - class () { - }, - '/as View because it was already mapped as Document\.$/', - ]; - - yield [ - /** - * @ODM\Document() - * @ODM\MappedSuperclass - */ - new #[ODM\Document] - #[ODM\MappedSuperclass] - class () { - }, - '/as MappedSuperclass because it was already mapped as Document\.$/', - ]; - - yield [ - /** - * @ODM\MappedSuperclass() - * @ODM\Document - */ - new #[ODM\MappedSuperclass] - #[ODM\Document] - class () { - }, - '/as Document because it was already mapped as MappedSuperclass\.$/', - ]; - } - - public function testWrongValueForValidationValidatorShouldThrowException(): void - { - $driver = static::loadDriver(); - $classMetadata = new ClassMetadata(WrongValueForValidationValidator::class); - $this->expectException(MappingException::class); - $this->expectExceptionMessage('The following schema validation error occurred while parsing the "validator" property of the "Doctrine\ODM\MongoDB\Tests\Mapping\WrongValueForValidationValidator" class: "Got parse error at "w", position 0: "SPECIAL_EXPECTED"" (code 0).'); - $driver->loadMetadataForClass($classMetadata->name, $classMetadata); - } - - protected function loadDriverForCMSDocuments(): MappingDriver - { - $annotationDriver = static::loadDriver([__DIR__ . '/../../Documents']); - assert($annotationDriver instanceof AnnotationDriver || $annotationDriver instanceof AttributeDriver); - - return $annotationDriver; - } -} - -/** @ODM\Document */ -#[ODM\Document] -class ColumnWithoutType -{ - /** - * @ODM\Id - * - * @var string|null - */ - #[ODM\Id] - public $id; -} - -/** @ODM\MappedSuperclass */ -#[ODM\MappedSuperclass] -class AnnotationDriverTestSuper -{ - /** - * @ODM\Id - * - * @var string|null - */ - #[ODM\Id] - public $id; - - /** - * @ODM\Field(type="string") - * - * @var string|null - */ - #[ODM\Field(type: 'string')] - protected $protected; - - /** - * @ODM\Field(type="string") - * - * @var string|null - */ - #[ODM\Field(type: 'string')] - private $private; -} - -/** @ODM\Document */ -#[ODM\Document] -class AnnotationDriverTestParent extends AnnotationDriverTestSuper -{ - /** - * @ODM\Field(type="string") - * - * @var string|null - */ - #[ODM\Field(type: 'string')] - public $foo; -} - -/** @ODM\Document */ -#[ODM\Document] -class AnnotationDriverTestChild extends AnnotationDriverTestParent -{ - /** - * @ODM\Field(type="string") - * - * @var string|null - */ - #[ODM\Field(type: 'string')] - public $bar; -} - -/** - * @ODM\EmbeddedDocument - * @ODM\ShardKey(keys={"foo"="asc"}) - */ -#[ODM\EmbeddedDocument] -#[ODM\ShardKey(keys: ['foo' => 'asc'])] -class AnnotationDriverEmbeddedWithShardKey -{ - /** - * @ODM\Field(type="string") - * - * @var string|null - */ - #[ODM\Field(type: 'string')] - public $foo; -} - -/** @ODM\Document(writeConcern="majority") */ -#[ODM\Document(writeConcern: 'majority')] -class AnnotationDriverTestWriteConcernMajority -{ - /** - * @ODM\Id - * - * @var string|null - */ - #[ODM\Id] - public $id; -} - -/** @ODM\Document(writeConcern=0) */ -#[ODM\Document(writeConcern: 0)] -class AnnotationDriverTestWriteConcernUnacknowledged -{ - /** - * @ODM\Id - * - * @var string|null - */ - #[ODM\Id] - public $id; -} - -/** @ODM\Validation(validator="wrong") */ -#[ODM\Validation(validator: 'wrong')] -class WrongValueForValidationValidator -{ - /** - * @ODM\Id - * - * @var string|null - */ - #[ODM\Id] - public $id; -} diff --git a/tests/Tests/Mapping/AbstractMappingDriverTestCase.php b/tests/Tests/Mapping/AbstractMappingDriverTestCase.php index 5d790898f9..a01721675c 100644 --- a/tests/Tests/Mapping/AbstractMappingDriverTestCase.php +++ b/tests/Tests/Mapping/AbstractMappingDriverTestCase.php @@ -728,57 +728,6 @@ public function testTimeSeriesDocumentWithBucket(): void } } -/** - * @ODM\Document(collection="cms_users", writeConcern=1, readOnly=true) - * @ODM\DiscriminatorField("discr") - * @ODM\DiscriminatorMap({"default"="Doctrine\ODM\MongoDB\Tests\Mapping\AbstractMappingDriverUser"}) - * @ODM\DefaultDiscriminatorValue("default") - * @ODM\HasLifecycleCallbacks - * @ODM\Index(keys={"createdAt"="asc"},expireAfterSeconds=3600) - * @ODM\Index(keys={"lock"="asc"},partialFilterExpression={"version"={"$gt"=1},"discr"={"$eq"="default"}}) - * @ODM\SearchIndex(dynamic=true, analyzer="lucene.standard", searchAnalyzer="lucene.standard", storedSource=true) - * @ODM\SearchIndex( - * name="usernameAndPhoneNumbers", - * fields={ - * "username"={ - * { - * "type"="string", - * "multi"={ - * "english"={"type"="string", "analyzer"="lucene.english"}, - * "french"={"type"="string", "analyzer"="lucene.french"}, - * }, - * }, - * {"type"="autocomplete"}, - * }, - * "embedded_phone_number"={"type"="embeddedDocuments", "dynamic"=true}, - * }, - * storedSource={"include"={"username"}}, - * synonyms={ - * {"name"="mySynonyms", "analyzer"="lucene.english", "source"={"collection"="synonyms"}}, - * }, - * ) - * @ODM\VectorSearchIndex( - * fields={ - * { - * "type"="vector", - * "path"="embedding", - * "numDimensions"=1536, - * "similarity"="euclidean", - * "quantization"="scalar", - * "hnswOptions"={"maxEdges"=16, "numEdgeCandidates"=200, }, - * }, - * {"type"="filter", "path"="name"}, - * {"type"="filter", "path"="email"}, - * }, - * name="embeddingIndex", - * ) - * @ODM\ShardKey(keys={"name"="asc"},unique=true,numInitialChunks=4096) - * @ODM\ReadPreference("primaryPreferred", tags={ - * { "dc"="east" }, - * { "dc"="west" }, - * { } - * }) - */ #[ODM\Document(collection: 'cms_users', writeConcern: 1, readOnly: true)] #[ODM\DiscriminatorField('discr')] #[ODM\DiscriminatorMap(['default' => AbstractMappingDriverUser::class])] @@ -832,149 +781,81 @@ public function testTimeSeriesDocumentWithBucket(): void #[ODM\ReadPreference('primaryPreferred', tags: [['dc' => 'east'], ['dc' => 'west'], []])] class AbstractMappingDriverUser { - /** - * @ODM\Id - * - * @var string|null - */ + /** @var string|null */ #[ODM\Id()] public $identifier; - /** - * @ODM\Version - * @ODM\Field(type="int") - * - * @var int|null - */ + /** @var int|null */ #[ODM\Version] #[ODM\Field(type: 'int')] public $version; - /** - * @ODM\Lock - * @ODM\Field(type="int") - * - * @var int|null - */ + /** @var int|null */ #[ODM\Lock] #[ODM\Field(type: 'int')] public $lock; - /** - * @ODM\Field(name="username", type="string") - * @ODM\UniqueIndex(order="desc") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(name: 'username', type: 'string')] #[ODM\UniqueIndex(order: 'desc')] public $name; - /** - * @ODM\Field(type="string") - * @ODM\UniqueIndex(order="desc") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string')] #[ODM\UniqueIndex(order: 'desc')] public $email; - /** - * @ODM\Field(type="int") - * @ODM\UniqueIndex(order="desc") - * - * @var int|null - */ + /** @var int|null */ #[ODM\Field(type: 'int')] #[ODM\UniqueIndex(order: 'desc')] public $mysqlProfileId; - /** - * @ODM\ReferenceOne(targetDocument=Address::class, cascade={"remove"}) - * - * @var Address|null - */ + /** @var Address|null */ #[ODM\ReferenceOne(targetDocument: Address::class, cascade: ['remove'])] public $address; - /** - * @ODM\ReferenceMany(collectionClass=PhonenumberCollection::class, cascade={"persist"}, discriminatorField="discr", discriminatorMap={"home"=HomePhonenumber::class, "work"=WorkPhonenumber::class}, defaultDiscriminatorValue="home") - * - * @var PhonenumberCollection - */ + /** @var PhonenumberCollection */ #[ODM\ReferenceMany(collectionClass: PhonenumberCollection::class, cascade: ['persist'], discriminatorField: 'discr', discriminatorMap: ['home' => HomePhonenumber::class, 'work' => WorkPhonenumber::class], defaultDiscriminatorValue: 'home')] public $phonenumbers; - /** - * @ODM\ReferenceMany(targetDocument=Group::class, cascade={"all"}) - * - * @var Collection - */ + /** @var Collection */ #[ODM\ReferenceMany(targetDocument: Group::class, cascade: ['all'])] public $groups; - /** - * @ODM\ReferenceMany(targetDocument=Phonenumber::class, collectionClass=PhonenumberCollection::class, name="more_phone_numbers") - * - * @var PhonenumberCollection - */ + /** @var PhonenumberCollection */ #[ODM\ReferenceMany(targetDocument: Phonenumber::class, collectionClass: PhonenumberCollection::class, name: 'more_phone_numbers')] public $morePhoneNumbers; - /** - * @ODM\EmbedMany(targetDocument=Phonenumber::class, name="embedded_phone_number") - * - * @var Collection - */ + /** @var Collection */ #[ODM\EmbedMany(targetDocument: Phonenumber::class, name: 'embedded_phone_number')] public $embeddedPhonenumber; - /** - * @ODM\EmbedMany(discriminatorField="discr", discriminatorMap={"home"=HomePhonenumber::class, "work"=WorkPhonenumber::class}, defaultDiscriminatorValue="home") - * - * @var Collection - */ + /** @var Collection */ #[ODM\EmbedMany(discriminatorField: 'discr', discriminatorMap: ['home' => HomePhonenumber::class, 'work' => WorkPhonenumber::class], defaultDiscriminatorValue: 'home')] public $otherPhonenumbers; - /** - * @ODM\Field(type="date") - * - * @var DateTime|null - */ + /** @var DateTime|null */ #[ODM\Field(type: 'date')] public $createdAt; - /** - * @ODM\Field(type="collection") - * - * @var string[] - */ + /** @var string[] */ #[ODM\Field(type: 'collection')] public $roles = []; - /** - * @ODM\Field(type="collection") - * - * @var int[] - */ + /** @var int[] */ #[ODM\Field(type: 'collection')] public $embedding = []; - /** @ODM\PrePersist */ #[ODM\PrePersist] public function doStuffOnPrePersist(): void { } - /** @ODM\PrePersist */ #[ODM\PrePersist] public function doOtherStuffOnPrePersistToo(): void { } - /** @ODM\PostPersist */ #[ODM\PostPersist] public function doStuffOnPostPersist(): void { @@ -1105,79 +986,47 @@ class InvalidMappingDocument public $id; } -/** @ODM\File(chunkSizeBytes=12345) */ + #[ODM\File(chunkSizeBytes: 12345)] class AbstractMappingDriverFile { - /** - * @ODM\Id - * - * @var string|null - */ + /** @var string|null */ #[ODM\Id] public $id; - /** - * @ODM\File\Length - * - * @var int|null - */ + /** @var int|null */ #[ODM\File\Length] public $size; - /** - * @ODM\File\ChunkSize - * - * @var int|null - */ + /** @var int|null */ #[ODM\File\ChunkSize] public $chunkSize; - /** - * @ODM\File\Filename - * - * @var string|null - */ + /** @var string|null */ #[ODM\File\Filename] public $name; - /** - * @ODM\File\Metadata(targetDocument=AbstractMappingDriverFileMetadata::class) - * - * @var AbstractMappingDriverFileMetadata|null - */ + /** @var AbstractMappingDriverFileMetadata|null */ #[ODM\File\Metadata(targetDocument: AbstractMappingDriverFileMetadata::class)] public $metadata; - /** - * @ODM\File\UploadDate - * - * @var DateTime|null - */ + /** @var DateTime|null */ #[ODM\File\UploadDate] public $uploadDate; } class AbstractMappingDriverFileMetadata { - /** - * @ODM\Field - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field] public $contentType; } -/** @ODM\File(repositoryClass=AbstractMappingDriverGridFSRepository::class) */ + #[ODM\File(repositoryClass: AbstractMappingDriverGridFSRepository::class)] class AbstractMappingDriverFileWithCustomRepository { - /** - * @ODM\Id - * - * @var string|null - */ + /** @var string|null */ #[ODM\Id] public $id; } @@ -1187,192 +1036,113 @@ class AbstractMappingDriverGridFSRepository extends DefaultGridFSRepository { } -/** @ODM\MappedSuperclass */ + #[ODM\MappedSuperclass] class AbstractMappingDriverSuperClass { - /** - * @ODM\Id - * - * @var string|null - */ + /** @var string|null */ #[ODM\Id] public $id; - /** - * @ODM\Field(type="string") - * - * @var string|int|null - */ + /** @var string|int|null */ #[ODM\Field(type: 'string')] protected $override; } -/** @ODM\Document */ + #[ODM\Document] class AbstractMappingDriverDuplicateDatabaseName extends AbstractMappingDriverSuperClass { - /** - * @ODM\Field(type="int") - * - * @var int|null - */ + /** @var int|null */ #[ODM\Field(type: 'int')] public $override; - /** - * @ODM\Field(type="string", name="baz") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string', name: 'baz')] public $foo; - /** - * @ODM\Field(type="string", name="baz") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string', name: 'baz')] public $bar; } -/** @ODM\Document */ + #[ODM\Document] class AbstractMappingDriverDuplicateDatabaseNameNotSaved extends AbstractMappingDriverSuperClass { - /** - * @ODM\Field(type="int") - * - * @var int|null - */ + /** @var int|null */ #[ODM\Field(type: 'int')] public $override; - /** - * @ODM\Field(type="string", name="baz") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string', name: 'baz')] public $foo; - /** - * @ODM\Field(type="string", name="baz", notSaved=true) - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string', name: 'baz', notSaved: true)] public $bar; } -/** @ODM\View(rootClass=AbstractMappingDriverUser::class) */ + #[ODM\View(rootClass: AbstractMappingDriverUser::class)] class AbstractMappingDriverViewWithoutRepository { - /** - * @ODM\Id - * - * @var string|null - */ + /** @var string|null */ #[ODM\Id] public $id; - /** - * @ODM\Field(type="string") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string')] public $name; } -/** @ODM\View(repositoryClass=DocumentRepository::class, rootClass=AbstractMappingDriverUser::class) */ + #[ODM\View(repositoryClass: DocumentRepository::class, rootClass: AbstractMappingDriverUser::class)] class AbstractMappingDriverViewWithWrongRepository { - /** - * @ODM\Id - * - * @var string|null - */ + /** @var string|null */ #[ODM\Id] public $id; - /** - * @ODM\Field(type="string") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string')] public $name; } -/** @ODM\View(repositoryClass=AbstractMappingDriverViewRepository::class) */ + #[ODM\View(repositoryClass: AbstractMappingDriverViewRepository::class)] class AbstractMappingDriverViewWithoutRootClass { - /** - * @ODM\Id - * - * @var string|null - */ + /** @var string|null */ #[ODM\Id] public $id; - /** - * @ODM\Field(type="string") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string')] public $name; } -/** @ODM\View(repositoryClass=AbstractMappingDriverViewRepository::class, rootClass="Doctrine\ODM\MongoDB\LolNo") */ + #[ODM\View(repositoryClass: AbstractMappingDriverViewRepository::class, rootClass: 'Doctrine\ODM\MongoDB\LolNo')] class AbstractMappingDriverViewWithNonExistingRootClass { - /** - * @ODM\Id - * - * @var string|null - */ + /** @var string|null */ #[ODM\Id] public $id; - /** - * @ODM\Field(type="string") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string')] public $name; } -/** - * @ODM\View( - * repositoryClass=AbstractMappingDriverViewRepository::class, - * rootClass=AbstractMappingDriverUser::class, - * view="user_name", - * ) - */ #[ODM\View(repositoryClass: AbstractMappingDriverViewRepository::class, rootClass: AbstractMappingDriverUser::class, view: 'user_name')] class AbstractMappingDriverView { - /** - * @ODM\Id - * - * @var string|null - */ + /** @var string|null */ #[ODM\Id] public $id; - /** - * @ODM\Field(type="string") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string')] public $name; } @@ -1391,52 +1161,37 @@ public function createViewAggregation(Builder $builder): void } } -/** - * @ODM\Document(collection="cms_users", writeConcern=1, readOnly=true) - * @ODM\TimeSeries(timeField="time", metaField="metadata", granularity=Granularity::Seconds, expireAfterSeconds=86400) - */ #[ODM\Document] #[ODM\TimeSeries(timeField: 'time', metaField: 'metadata', granularity: Granularity::Seconds, expireAfterSeconds: 86400)] class AbstractMappingDriverTimeSeriesDocumentWithGranularity { - /** @ODM\Id */ #[ODM\Id] public ?string $id = null; - /** @ODM\Field(type="date") */ #[ODM\Field(type: 'date')] public DateTime $time; - /** @ODM\Field */ #[ODM\Field] public string $metadata; - /** @ODM\Field(type="int") */ #[ODM\Field(type: 'int')] public int $value; } -/** - * @ODM\Document(collection="cms_users", writeConcern=1, readOnly=true) - * @ODM\TimeSeries(timeField="time", metaField="metadata", expireAfterSeconds=86400, bucketMaxSpanSeconds=10, bucketRoundingSeconds=15) - */ #[ODM\Document] #[ODM\TimeSeries(timeField: 'time', metaField: 'metadata', expireAfterSeconds: 86400, bucketMaxSpanSeconds: 10, bucketRoundingSeconds: 15)] class AbstractMappingDriverTimeSeriesDocumentWithBucket { - /** @ODM\Id */ #[ODM\Id] public ?string $id = null; - /** @ODM\Field(type="date") */ + #[ODM\Field(type: 'date')] public DateTime $time; - /** @ODM\Field */ #[ODM\Field] public string $metadata; - /** @ODM\Field(type="int") */ #[ODM\Field(type: 'int')] public int $value; } diff --git a/tests/Tests/Mapping/AnnotationDriverTest.php b/tests/Tests/Mapping/AnnotationDriverTest.php deleted file mode 100644 index 650bcabe72..0000000000 --- a/tests/Tests/Mapping/AnnotationDriverTest.php +++ /dev/null @@ -1,26 +0,0 @@ -dm->getClassMetadata(AttributeDriverTestSuper::class); + $parent = $this->dm->getClassMetadata(AttributeDriverTestParent::class); + $child = $this->dm->getClassMetadata(AttributeDriverTestChild::class); + + self::assertFalse($super->hasField('id'), 'MappedSuperclass does not register its own public field'); + self::assertFalse($super->hasField('protected'), 'MappedSuperclass does not register its own protected field'); + self::assertTrue($super->hasField('private'), 'MappedSuperclass does register its own private field'); + self::assertFalse($super->isInheritedField('private'), 'MappedSuperclass does not inherit its own field'); + self::assertFalse($super->hasField('foo'), 'MappedSuperclass does not have field declared in child Document'); + self::assertFalse($super->hasField('bar'), 'MappedSuperclass does not have field declared in grandchild Document'); + + self::assertArrayNotHasKey('declared', $super->fieldMappings['private'], 'MappedSuperclass does not track "declared" for non-inherited field'); + + self::assertTrue($parent->hasField('id'), 'Document does have public field from MappedSuperclass parent'); + self::assertFalse($parent->isInheritedField('id'), 'Document does not inherit public field from MappedSuperclass parent'); + self::assertTrue($parent->hasField('protected'), 'Document does have protected field from MappedSuperclass parent'); + self::assertFalse($parent->isInheritedField('protected'), 'Document does not inherit protected field from MappedSuperclass parent'); + self::assertTrue($parent->hasField('private'), 'Document does have private field from MappedSuperclass parent'); + /* MappedSuperclass fields are never considered "inherited", but the + * field is still considered "declared" in the MappedSuperclass, since + * we need its ReflectionProperty to access it. This is a bit weird. + */ + self::assertFalse($parent->isInheritedField('private'), 'Document does not inherit private field from MappedSuperclass parent'); + self::assertTrue($parent->hasField('foo'), 'Document does register its own public field'); + self::assertFalse($parent->isInheritedField('foo'), 'Document does not inherit its own field'); + self::assertFalse($parent->hasField('bar'), 'Document does not have field declared in child Document'); + + self::assertArrayNotHasKey('declared', $parent->fieldMappings['id'], 'Document does not track "declared" for non-inherited public field from MappedSuperclass parent'); + self::assertArrayNotHasKey('declared', $parent->fieldMappings['protected'], 'Document does not track "declared" for non-inherited protected field from MappedSuperclass parent'); + self::assertEquals(AttributeDriverTestSuper::class, $parent->fieldMappings['private']['declared'], 'Non-inherited private field from MappedSuperclass parent is declared in MappedSuperclass parent'); + self::assertArrayNotHasKey('declared', $parent->fieldMappings['foo'], 'Document does not track "declared" for its own public field'); + + self::assertTrue($child->hasField('id'), 'Document does have public field from MappedSuperclass grandparent'); + self::assertTrue($child->isInheritedField('id'), 'Document does inherit public field from MappedSuperclass grandparent'); + self::assertTrue($child->hasField('protected'), 'Document does have protected field from MappedSuperclass grandparent'); + self::assertTrue($child->isInheritedField('protected'), 'Document does inherit protected field from MappedSuperclass grandparent'); + self::assertTrue($child->hasField('private'), 'Document does have private field from MappedSuperclass grandparent'); + self::assertTrue($child->isInheritedField('private'), 'Document does inherit private field from MappedSuperclass grandparent'); + self::assertTrue($child->hasField('foo'), 'Document does have public field from Document parent'); + self::assertTrue($child->isInheritedField('foo'), 'Document field declared in Document parent is inherited'); + self::assertTrue($child->hasField('bar'), 'Document does register its own public field'); + self::assertFalse($child->isInheritedField('bar'), 'Document does not inherit its own field'); + + self::assertEquals(AttributeDriverTestParent::class, $child->fieldMappings['id']['declared'], 'Inherited public field from MappedSuperclass grandparent is declared in Document parent'); + self::assertEquals(AttributeDriverTestParent::class, $child->fieldMappings['protected']['declared'], 'Inherited protected field from MappedSuperclass grandparent is declared in Document parent'); + self::assertEquals(AttributeDriverTestSuper::class, $child->fieldMappings['private']['declared'], 'Inherited private field from MappedSuperclass grandparent is declared in MappedSuperclass grandparent'); + self::assertEquals(AttributeDriverTestParent::class, $child->fieldMappings['foo']['declared'], 'Inherited public field from Document parent is declared in Document parent'); + } + + public function testLoadMetadataForNonDocumentThrowsException(): void + { + $cm = new ClassMetadata('stdClass'); + $attributeDriver = static::loadDriver(); + + $this->expectException(MappingException::class); + $attributeDriver->loadMetadataForClass('stdClass', $cm); + } + + public function testColumnWithMissingTypeDefaultsToString(): void + { + $cm = new ClassMetadata(ColumnWithoutType::class); + $attributeDriver = static::loadDriver(); + + $attributeDriver->loadMetadataForClass(stdClass::class, $cm); + self::assertEquals('id', $cm->fieldMappings['id']['type']); + } + + public function testGetAllClassNamesReturnsAlreadyLoadedClassesIfAppropriate(): void + { + self::assertTrue(class_exists(CmsUser::class), 'Pre-load the class'); + $attributeDriver = $this->loadDriverForCMSDocuments(); + $classes = $attributeDriver->getAllClassNames(); + + self::assertContains(CmsUser::class, $classes); + } + + public function testGetClassNamesReturnsOnlyTheAppropriateClasses(): void + { + $extraneousClassName = ColumnWithoutType::class; + + $attributeDriver = $this->loadDriverForCMSDocuments(); + $classes = $attributeDriver->getAllClassNames(); + + self::assertNotContains($extraneousClassName, $classes); + } + + public function testEmbeddedClassCantHaveShardKey(): void + { + $this->expectException(MappingException::class); + $this->expectExceptionMessage('Embedded document can\'t have shard key'); + $this->dm->getClassMetadata(AttributeDriverEmbeddedWithShardKey::class); + } + + public function testDocumentAttributeCanSpecifyWriteConcern(): void + { + $cm = $this->dm->getClassMetadata(AttributeDriverTestWriteConcernMajority::class); + self::assertSame('majority', $cm->writeConcern); + + $cm = $this->dm->getClassMetadata(AttributeDriverTestWriteConcernUnacknowledged::class); + self::assertSame(0, $cm->writeConcern); + + $cm = $this->dm->getClassMetadata(ColumnWithoutType::class); + self::assertNull($cm->writeConcern); + } + + #[DataProvider('provideClassCanBeMappedByOneAbstractDocument')] + public function testClassCanBeMappedByOneAbstractDocument(object $wrong, string $messageRegExp): void + { + $this->expectException(MappingException::class); + $this->expectExceptionMessageMatches($messageRegExp); + + $cm = new ClassMetadata($wrong::class); + $driver = static::loadDriver(); + + $driver->loadMetadataForClass($wrong::class, $cm); + } + + public static function provideClassCanBeMappedByOneAbstractDocument(): ?Generator + { + yield [ + new #[ODM\Document] + #[ODM\EmbeddedDocument] + class () { + }, + '/as EmbeddedDocument because it was already mapped as Document\.$/', + ]; + + yield [ + new #[ODM\Document] + #[ODM\File] + class () { + }, + '/as File because it was already mapped as Document\.$/', + ]; + + yield [ + new #[ODM\Document] + #[ODM\QueryResultDocument] + class () { + }, + '/as QueryResultDocument because it was already mapped as Document\.$/', + ]; + + yield [ + new #[ODM\Document] + #[ODM\View] + class () { + }, + '/as View because it was already mapped as Document\.$/', + ]; + + yield [ + new #[ODM\Document] + #[ODM\MappedSuperclass] + class () { + }, + '/as MappedSuperclass because it was already mapped as Document\.$/', + ]; + + yield [ + new #[ODM\MappedSuperclass] + #[ODM\Document] + class () { + }, + '/as Document because it was already mapped as MappedSuperclass\.$/', + ]; + } + + public function testWrongValueForValidationValidatorShouldThrowException(): void + { + $driver = static::loadDriver(); + $classMetadata = new ClassMetadata(WrongValueForValidationValidator::class); + $this->expectException(MappingException::class); + $this->expectExceptionMessage('The following schema validation error occurred while parsing the "validator" property of the "Doctrine\ODM\MongoDB\Tests\Mapping\WrongValueForValidationValidator" class: "Got parse error at "w", position 0: "SPECIAL_EXPECTED"" (code 0).'); + $driver->loadMetadataForClass($classMetadata->name, $classMetadata); + } + + protected static function loadDriver(array $paths = []): AttributeDriver { if (class_exists(FileClassLocator::class)) { $paths = FileClassLocator::createFromDirectories($paths); @@ -20,4 +206,89 @@ protected static function loadDriver(array $paths = []): MappingDriver return AttributeDriver::create($paths); } + + protected function loadDriverForCMSDocuments(): AttributeDriver + { + return static::loadDriver([__DIR__ . '/../../Documents']); + } +} + + +#[ODM\Document] +class ColumnWithoutType +{ + /** @var string|null */ + #[ODM\Id] + public $id; +} + + +#[ODM\MappedSuperclass] +class AttributeDriverTestSuper +{ + /** @var string|null */ + #[ODM\Id] + public $id; + + /** @var string|null */ + #[ODM\Field(type: 'string')] + protected $protected; + + /** @var string|null */ + #[ODM\Field(type: 'string')] + private $private; +} + + +#[ODM\Document] +class AttributeDriverTestParent extends AttributeDriverTestSuper +{ + /** @var string|null */ + #[ODM\Field(type: 'string')] + public $foo; +} + + +#[ODM\Document] +class AttributeDriverTestChild extends AttributeDriverTestParent +{ + /** @var string|null */ + #[ODM\Field(type: 'string')] + public $bar; +} + +#[ODM\EmbeddedDocument] +#[ODM\ShardKey(keys: ['foo' => 'asc'])] +class AttributeDriverEmbeddedWithShardKey +{ + /** @var string|null */ + #[ODM\Field(type: 'string')] + public $foo; +} + + +#[ODM\Document(writeConcern: 'majority')] +class AttributeDriverTestWriteConcernMajority +{ + /** @var string|null */ + #[ODM\Id] + public $id; +} + + +#[ODM\Document(writeConcern: 0)] +class AttributeDriverTestWriteConcernUnacknowledged +{ + /** @var string|null */ + #[ODM\Id] + public $id; +} + + +#[ODM\Validation(validator: 'wrong')] +class WrongValueForValidationValidator +{ + /** @var string|null */ + #[ODM\Id] + public $id; } diff --git a/tests/Tests/Mapping/Documents/GlobalNamespaceDocument.php b/tests/Tests/Mapping/Documents/GlobalNamespaceDocument.php index ef5a740d26..2ee6c40f98 100644 --- a/tests/Tests/Mapping/Documents/GlobalNamespaceDocument.php +++ b/tests/Tests/Mapping/Documents/GlobalNamespaceDocument.php @@ -5,76 +5,43 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -/** @ODM\Document */ #[ODM\Document] class DoctrineGlobal_Article { - /** - * @ODM\Id - * - * @var string|null - */ + /** @var string|null */ #[ODM\Id] protected $id; - /** - * @ODM\Field(type="string") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string')] protected $headline; - /** - * @ODM\Field(type="string") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string')] protected $text; - /** - * @ODM\ReferenceMany(targetDocument=DoctrineGlobal_User::class) - * - * @var DoctrineGlobal_User|null - */ + /** @var DoctrineGlobal_User|null */ #[ODM\ReferenceMany(targetDocument: DoctrineGlobal_User::class)] protected $author; - /** - * @ODM\ReferenceMany(targetDocument=DoctrineGlobal_User::class) - * - * @var Collection - */ + /** @var Collection */ #[ODM\ReferenceMany(targetDocument: DoctrineGlobal_User::class)] protected $editor; } -/** @ODM\Document */ + #[ODM\Document] class DoctrineGlobal_User { - /** - * @ODM\Id - * - * @var string|null - */ + /** @var string|null */ #[ODM\Id] private $id; - /** - * @ODM\Field(type="string") - * - * @var string - */ + /** @var string */ #[ODM\Field(type: 'string')] private $username; - /** - * @ODM\Field(type="string") - * - * @var string - */ + /** @var string */ #[ODM\Field(type: 'string')] private $email; } diff --git a/tests/Tests/Tools/Console/Command/Schema/UpdateCommandTest.php b/tests/Tests/Tools/Console/Command/Schema/UpdateCommandTest.php index 27a328d793..3da10044b1 100644 --- a/tests/Tests/Tools/Console/Command/Schema/UpdateCommandTest.php +++ b/tests/Tests/Tools/Console/Command/Schema/UpdateCommandTest.php @@ -72,8 +72,8 @@ public function testDisabledValidatorProcessing(): void public function testProcessValidators(): void { // Only load a subset of documents with legit annotations - $annotationDriver = $this->createDriver(); - $this->dm->getConfiguration()->setMetadataDriverImpl($annotationDriver); + $attributeDriver = $this->createDriver(); + $this->dm->getConfiguration()->setMetadataDriverImpl($attributeDriver); $this->commandTester->execute([]); $output = $this->commandTester->getDisplay(); self::assertStringContainsString('Updated validation for all classes', $output); @@ -82,8 +82,8 @@ public function testProcessValidators(): void public function testDisabledValidatorsProcessing(): void { // Only load a subset of documents with legit annotations - $annotationDriver = $this->createDriver(); - $this->dm->getConfiguration()->setMetadataDriverImpl($annotationDriver); + $attributeDriver = $this->createDriver(); + $this->dm->getConfiguration()->setMetadataDriverImpl($attributeDriver); $this->commandTester->execute(['--disable-validators' => true]); $output = $this->commandTester->getDisplay(); self::assertStringNotContainsString('Updated validation for all classes', $output); diff --git a/tests/Tests/Tools/GH1299/BaseUser.php b/tests/Tests/Tools/GH1299/BaseUser.php index 277c84c176..a16a1d51ab 100644 --- a/tests/Tests/Tools/GH1299/BaseUser.php +++ b/tests/Tests/Tools/GH1299/BaseUser.php @@ -6,23 +6,14 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -/** @ODM\Document */ #[ODM\Document] class BaseUser { - /** - * @ODM\Id - * - * @var string|null - */ + /** @var string|null */ #[ODM\Id] protected $id; - /** - * @ODM\Field(type="string") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string')] protected $name; diff --git a/tests/Tests/Tools/GH1299/GH1299User.php b/tests/Tests/Tools/GH1299/GH1299User.php index 64ed574e58..4d7ea90f30 100644 --- a/tests/Tests/Tools/GH1299/GH1299User.php +++ b/tests/Tests/Tools/GH1299/GH1299User.php @@ -6,15 +6,10 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -/** @ODM\Document */ #[ODM\Document] class GH1299User extends BaseUser { - /** - * @ODM\Field(type="string") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string')] protected $lastname; } diff --git a/tests/Tests/Tools/GH297/Address.php b/tests/Tests/Tools/GH297/Address.php index 5a0c11f266..f157369855 100644 --- a/tests/Tests/Tools/GH297/Address.php +++ b/tests/Tests/Tools/GH297/Address.php @@ -6,15 +6,10 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -/** @ODM\EmbeddedDocument */ #[ODM\EmbeddedDocument] class Address { - /** - * @ODM\Field(type="string") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string')] private $street; diff --git a/tests/Tests/Tools/GH297/AddressTrait.php b/tests/Tests/Tools/GH297/AddressTrait.php index eea24926f8..64a4b24cff 100644 --- a/tests/Tests/Tools/GH297/AddressTrait.php +++ b/tests/Tests/Tools/GH297/AddressTrait.php @@ -8,11 +8,7 @@ trait AddressTrait { - /** - * @ODM\EmbedOne - * - * @var Address|null - */ + /** @var Address|null */ #[ODM\EmbedOne] private $address; diff --git a/tests/Tests/Tools/GH297/Admin.php b/tests/Tests/Tools/GH297/Admin.php index 70011f5fa3..ca983b08f6 100644 --- a/tests/Tests/Tools/GH297/Admin.php +++ b/tests/Tests/Tools/GH297/Admin.php @@ -6,7 +6,6 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -/** @ODM\Document */ #[ODM\Document] class Admin extends User { diff --git a/tests/Tests/Tools/GH297/User.php b/tests/Tests/Tools/GH297/User.php index 9fd9bca8bf..9319a43caf 100644 --- a/tests/Tests/Tools/GH297/User.php +++ b/tests/Tests/Tools/GH297/User.php @@ -6,25 +6,16 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -/** @ODM\Document */ #[ODM\Document] class User { use AddressTrait; - /** - * @ODM\Id - * - * @var string|null - */ + /** @var string|null */ #[ODM\Id] private $id; - /** - * @ODM\Field(type="string") - * - * @var string|null - */ + /** @var string|null */ #[ODM\Field(type: 'string')] private $name;