From 871c2301e311486e564f157eb8bf676751ebb21e Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Sun, 29 Oct 2023 17:30:04 +0100 Subject: [PATCH 1/7] Test with Symfony 6.4 --- .github/workflows/continuous-integration.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 778334bd..130f5274 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -29,8 +29,7 @@ jobs: - "stable" symfony-version: - "5.4.*" - - "6.2.*" - - "6.3.*" + - "6.4.*" driver-version: - "stable" dependencies: From dc54819096a2e57b4d04dca3fd9e275d37024e46 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Sun, 29 Oct 2023 17:48:15 +0100 Subject: [PATCH 2/7] Add $buildDir parameter to warmUp method --- CacheWarmer/HydratorCacheWarmer.php | 2 +- CacheWarmer/PersistentCollectionCacheWarmer.php | 2 +- CacheWarmer/ProxyCacheWarmer.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CacheWarmer/HydratorCacheWarmer.php b/CacheWarmer/HydratorCacheWarmer.php index 7351f308..cd391959 100644 --- a/CacheWarmer/HydratorCacheWarmer.php +++ b/CacheWarmer/HydratorCacheWarmer.php @@ -46,7 +46,7 @@ public function isOptional() } /** @return string[] */ - public function warmUp(string $cacheDir) + public function warmUp(string $cacheDir, ?string $buildDir = null) { // we need the directory no matter the hydrator cache generation strategy. $hydratorCacheDir = (string) $this->container->getParameter('doctrine_mongodb.odm.hydrator_dir'); diff --git a/CacheWarmer/PersistentCollectionCacheWarmer.php b/CacheWarmer/PersistentCollectionCacheWarmer.php index 135e9017..fa3f2327 100644 --- a/CacheWarmer/PersistentCollectionCacheWarmer.php +++ b/CacheWarmer/PersistentCollectionCacheWarmer.php @@ -47,7 +47,7 @@ public function isOptional() } /** @return string[] */ - public function warmUp(string $cacheDir) + public function warmUp(string $cacheDir, ?string $buildDir = null) { // we need the directory no matter the hydrator cache generation strategy. $collCacheDir = (string) $this->container->getParameter('doctrine_mongodb.odm.persistent_collection_dir'); diff --git a/CacheWarmer/ProxyCacheWarmer.php b/CacheWarmer/ProxyCacheWarmer.php index 1380e8eb..3ca8f574 100644 --- a/CacheWarmer/ProxyCacheWarmer.php +++ b/CacheWarmer/ProxyCacheWarmer.php @@ -48,7 +48,7 @@ public function isOptional() } /** @return string[] */ - public function warmUp(string $cacheDir) + public function warmUp(string $cacheDir, ?string $buildDir = null) { // we need the directory no matter the proxy cache generation strategy. $proxyCacheDir = (string) $this->container->getParameter('doctrine_mongodb.odm.proxy_dir'); From 38be25184ac19d0cbdf1e9dcff7da530217d5e9a Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Thu, 2 Nov 2023 19:39:59 +0100 Subject: [PATCH 3/7] Remove the use of ContainerAwareTrait --- Command/TailCursorDoctrineODMCommand.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Command/TailCursorDoctrineODMCommand.php b/Command/TailCursorDoctrineODMCommand.php index 4e37cdc5..e43fbe20 100644 --- a/Command/TailCursorDoctrineODMCommand.php +++ b/Command/TailCursorDoctrineODMCommand.php @@ -14,7 +14,6 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerAwareTrait; use Throwable; use function sleep; @@ -28,7 +27,8 @@ */ class TailCursorDoctrineODMCommand extends Command implements ContainerAwareInterface { - use ContainerAwareTrait; + /** @var ContainerInterface|null */ + protected $container; /** @return void */ protected function configure() @@ -108,6 +108,12 @@ protected function execute(InputInterface $input, OutputInterface $output) return 0; } + /** @return void */ + public function setContainer(?ContainerInterface $container = null) + { + $this->container = $container; + } + /** @return ContainerInterface|null */ protected function getContainer() { From a1fd3ae4073b7fbe1447179aa19664b88dec0ea3 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Tue, 5 Dec 2023 09:26:38 +0100 Subject: [PATCH 4/7] Do not extend deprecated ContainerAwareLoader --- Loader/SymfonyFixturesLoader.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Loader/SymfonyFixturesLoader.php b/Loader/SymfonyFixturesLoader.php index 4a137886..9c5e802e 100644 --- a/Loader/SymfonyFixturesLoader.php +++ b/Loader/SymfonyFixturesLoader.php @@ -8,17 +8,19 @@ use Doctrine\Bundle\MongoDBBundle\Fixture\FixtureGroupInterface; use Doctrine\Common\DataFixtures\DependentFixtureInterface; use Doctrine\Common\DataFixtures\FixtureInterface; +use Doctrine\Common\DataFixtures\Loader; use LogicException; use ReflectionClass; use RuntimeException; -use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader; +use Symfony\Component\DependencyInjection\ContainerAwareInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; use function array_key_exists; use function array_values; use function get_class; use function sprintf; -final class SymfonyFixturesLoader extends ContainerAwareLoader implements SymfonyFixturesLoaderInterface +final class SymfonyFixturesLoader extends Loader implements SymfonyFixturesLoaderInterface { /** @var FixtureInterface[] */ private array $loadedFixtures = []; @@ -26,6 +28,11 @@ final class SymfonyFixturesLoader extends ContainerAwareLoader implements Symfon /** @var array> */ private array $groupsFixtureMapping = []; + public function __construct( + private ContainerInterface $container, + ) { + } + /** * @internal * @@ -60,6 +67,10 @@ public function addFixture(FixtureInterface $fixture): void $this->addGroupsFixtureMapping($class, $fixture::getGroups()); } + if ($fixture instanceof ContainerAwareInterface) { + $fixture->setContainer($this->container); + } + parent::addFixture($fixture); } From a33467761fb467d377483040f078f7bf66084f09 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Tue, 5 Dec 2023 08:50:19 +0100 Subject: [PATCH 5/7] Use attributes in tests --- .../Document/TestCustomClassRepoDocument.php | 2 ++ .../Document/TestCustomServiceRepoDocument.php | 2 ++ .../Document/TestCustomServiceRepoFile.php | 2 ++ .../Document/TestDefaultRepoDocument.php | 2 ++ .../Document/TestDefaultRepoFile.php | 2 ++ .../DependencyInjection/Fixtures/TestKernel.php | 2 +- Tests/Fixtures/Cache/Collections.php | 5 +++++ Tests/Fixtures/CommandBundle/Document/User.php | 2 ++ Tests/Fixtures/DataCollector/Category.php | 4 ++++ Tests/Fixtures/Form/Category.php | 8 ++++++++ Tests/Fixtures/Form/Document.php | 10 ++++++++++ Tests/Fixtures/Form/Guesser.php | 16 ++++++++++++++++ Tests/Fixtures/Security/User.php | 4 ++++ Tests/Fixtures/Validator/Document.php | 11 +++++++++++ Tests/ServiceRepositoryTest.php | 2 +- Tests/TestCase.php | 5 ++--- 16 files changed, 74 insertions(+), 5 deletions(-) diff --git a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomClassRepoDocument.php b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomClassRepoDocument.php index 5b3b2a49..702da4a9 100644 --- a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomClassRepoDocument.php +++ b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomClassRepoDocument.php @@ -8,8 +8,10 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; /** @ODM\Document(repositoryClass=TestCustomClassRepoRepository::class) */ +#[ODM\Document(repositoryClass: TestCustomClassRepoRepository::class)] class TestCustomClassRepoDocument { /** @ODM\Id */ + #[ODM\Id] private string $id; } diff --git a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomServiceRepoDocument.php b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomServiceRepoDocument.php index 90ce91ab..943ee6ad 100644 --- a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomServiceRepoDocument.php +++ b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomServiceRepoDocument.php @@ -8,8 +8,10 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; /** @ODM\Document(repositoryClass=TestCustomServiceRepoDocumentRepository::class) */ +#[ODM\Document(repositoryClass: TestCustomServiceRepoDocumentRepository::class)] class TestCustomServiceRepoDocument { /** @ODM\Id */ + #[ODM\Id] private string $id; } diff --git a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomServiceRepoFile.php b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomServiceRepoFile.php index db3eb52a..8fac4490 100644 --- a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomServiceRepoFile.php +++ b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomServiceRepoFile.php @@ -8,8 +8,10 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; /** @ODM\File(repositoryClass=TestCustomServiceRepoGridFSRepository::class) */ +#[ODM\File(repositoryClass: TestCustomServiceRepoGridFSRepository::class)] class TestCustomServiceRepoFile { /** @ODM\Id */ + #[ODM\Id] private string $id; } diff --git a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestDefaultRepoDocument.php b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestDefaultRepoDocument.php index 6fa6faef..5d83b26a 100644 --- a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestDefaultRepoDocument.php +++ b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestDefaultRepoDocument.php @@ -7,8 +7,10 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; /** @ODM\Document */ +#[ODM\Document] class TestDefaultRepoDocument { /** @ODM\Id */ + #[ODM\Id] private string $id; } diff --git a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestDefaultRepoFile.php b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestDefaultRepoFile.php index 31c15906..cacde3f5 100644 --- a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestDefaultRepoFile.php +++ b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestDefaultRepoFile.php @@ -7,8 +7,10 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; /** @ODM\File */ +#[ODM\File] class TestDefaultRepoFile { /** @ODM\Id */ + #[ODM\Id] private string $id; } diff --git a/Tests/DependencyInjection/Fixtures/TestKernel.php b/Tests/DependencyInjection/Fixtures/TestKernel.php index 84eb2a6d..ca5c195d 100644 --- a/Tests/DependencyInjection/Fixtures/TestKernel.php +++ b/Tests/DependencyInjection/Fixtures/TestKernel.php @@ -45,7 +45,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void 'default' => [ 'mappings' => [ 'RepositoryServiceBundle' => [ - 'type' => 'annotation', + 'type' => 'attribute', 'dir' => __DIR__ . '/Bundles/RepositoryServiceBundle/Document', 'prefix' => 'Fixtures\Bundles\RepositoryServiceBundle\Document', ], diff --git a/Tests/Fixtures/Cache/Collections.php b/Tests/Fixtures/Cache/Collections.php index 652e3712..c25fc3be 100644 --- a/Tests/Fixtures/Cache/Collections.php +++ b/Tests/Fixtures/Cache/Collections.php @@ -9,18 +9,23 @@ use MongoDB\BSON\ObjectId; /** @ODM\Document */ +#[ODM\Document] class Collections { /** @ODM\Id */ + #[ODM\Id] public ?ObjectId $id = null; /** @ODM\EmbedMany(collectionClass=SomeCollection::class) */ + #[ODM\EmbedMany(collectionClass: SomeCollection::class)] public SomeCollection $coll; /** @ODM\ReferenceMany(collectionClass=SomeCollection::class) */ + #[ODM\ReferenceMany(collectionClass: SomeCollection::class)] public SomeCollection $refs; /** @ODM\EmbedMany(collectionClass=AnotherCollection::class) */ + #[ODM\EmbedMany(collectionClass: AnotherCollection::class)] public AnotherCollection $another; } diff --git a/Tests/Fixtures/CommandBundle/Document/User.php b/Tests/Fixtures/CommandBundle/Document/User.php index 31fec3a0..06863dbf 100644 --- a/Tests/Fixtures/CommandBundle/Document/User.php +++ b/Tests/Fixtures/CommandBundle/Document/User.php @@ -7,8 +7,10 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; /** @ODM\Document */ +#[ODM\Document] class User { /** @ODM\Id */ + #[ODM\Id] private ?string $id = null; } diff --git a/Tests/Fixtures/DataCollector/Category.php b/Tests/Fixtures/DataCollector/Category.php index 95e34fd4..489dd3f8 100644 --- a/Tests/Fixtures/DataCollector/Category.php +++ b/Tests/Fixtures/DataCollector/Category.php @@ -5,15 +5,19 @@ namespace Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\DataCollector; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Doctrine\ODM\MongoDB\Types\Type; use MongoDB\BSON\ObjectId; /** @ODM\Document */ +#[ODM\Document] class Category { /** @ODM\Id */ + #[ODM\Id] protected ?ObjectId $id = null; /** @ODM\Field(type="string") */ + #[ODM\Field(type: Type::STRING)] public string $name; public function __construct(string $name) diff --git a/Tests/Fixtures/Form/Category.php b/Tests/Fixtures/Form/Category.php index 4d8d9971..51ed8447 100644 --- a/Tests/Fixtures/Form/Category.php +++ b/Tests/Fixtures/Form/Category.php @@ -7,15 +7,19 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Doctrine\ODM\MongoDB\Types\Type; use MongoDB\BSON\ObjectId; /** @ODM\Document */ +#[ODM\Document] class Category { /** @ODM\Id */ + #[ODM\Id] protected ObjectId|string|null $id; /** @ODM\Field(type="string") */ + #[ODM\Field(type: Type::STRING)] public string $name; /** @@ -26,6 +30,10 @@ class Category * * @var Collection */ + #[ODM\ReferenceMany( + targetDocument: Document::class, + mappedBy: 'categories', + )] public Collection $documents; public function __construct(string $name) diff --git a/Tests/Fixtures/Form/Document.php b/Tests/Fixtures/Form/Document.php index 7c404613..f51e412f 100644 --- a/Tests/Fixtures/Form/Document.php +++ b/Tests/Fixtures/Form/Document.php @@ -7,15 +7,20 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; +use Doctrine\ODM\MongoDB\Types\Type; use MongoDB\BSON\ObjectId; /** @ODM\Document */ +#[ODM\Document] class Document { /** @ODM\Id(strategy="none") */ + #[ODM\Id(strategy: 'none')] protected ObjectId $id; /** @ODM\Field(type="string") */ + #[ODM\Field(type: Type::STRING)] public string $name; /** @@ -27,6 +32,11 @@ class Document * * @var Collection */ + #[ODM\ReferenceMany( + targetDocument: Category::class, + inversedBy: 'documents', + strategy: ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET_ARRAY, + )] public Collection $categories; public function __construct(ObjectId $id, string $name) diff --git a/Tests/Fixtures/Form/Guesser.php b/Tests/Fixtures/Form/Guesser.php index 2c9def07..8d61d0c2 100644 --- a/Tests/Fixtures/Form/Guesser.php +++ b/Tests/Fixtures/Form/Guesser.php @@ -7,21 +7,28 @@ use DateTime; use Doctrine\Common\Collections\Collection; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; +use Doctrine\ODM\MongoDB\Types\Type; use MongoDB\BSON\ObjectId; /** @ODM\Document */ +#[ODM\Document] class Guesser { /** @ODM\Id(strategy="none") */ + #[ODM\Id(strategy: 'none')] protected ?ObjectId $id = null; /** @ODM\Field() */ + #[ODM\Field] public ?string $name = null; /** @ODM\Field(type="date") */ + #[ODM\Field(type: Type::DATE)] public ?DateTime $date = null; /** @ODM\Field(type="timestamp") */ + #[ODM\Field(type: Type::TIMESTAMP)] public DateTime $ts; /** @@ -33,15 +40,23 @@ class Guesser * * @var Collection */ + #[ODM\ReferenceMany( + targetDocument: Category::class, + inversedBy: 'documents', + strategy: ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET_ARRAY, + )] public Collection $categories; /** @ODM\Field(type="bool") */ + #[ODM\Field(type: Type::BOOL)] public ?bool $boolField = null; /** @ODM\Field(type="float") */ + #[ODM\Field(type: Type::FLOAT)] public ?float $floatField = null; /** @ODM\Field(type="int") */ + #[ODM\Field(type: Type::INT)] public ?int $intField = null; /** @@ -49,6 +64,7 @@ class Guesser * * @var array */ + #[ODM\Field(type: Type::COLLECTION)] public array $collectionField; public mixed $nonMappedField; diff --git a/Tests/Fixtures/Security/User.php b/Tests/Fixtures/Security/User.php index d5696918..cf89c48a 100644 --- a/Tests/Fixtures/Security/User.php +++ b/Tests/Fixtures/Security/User.php @@ -5,16 +5,20 @@ namespace Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Security; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Doctrine\ODM\MongoDB\Types\Type; use MongoDB\BSON\ObjectId; use Symfony\Component\Security\Core\User\UserInterface; /** @ODM\Document */ +#[ODM\Document] class User implements UserInterface { /** @ODM\Id(strategy="none") */ + #[ODM\Id(strategy: 'none')] protected ObjectId $id; /** @ODM\Field(type="string") */ + #[ODM\Field(type: Type::STRING)] public string $name; public function __construct(ObjectId $id, string $name) diff --git a/Tests/Fixtures/Validator/Document.php b/Tests/Fixtures/Validator/Document.php index ae78ff3a..02b459b9 100644 --- a/Tests/Fixtures/Validator/Document.php +++ b/Tests/Fixtures/Validator/Document.php @@ -5,15 +5,19 @@ namespace Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Validator; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Doctrine\ODM\MongoDB\Types\Type; use MongoDB\BSON\ObjectId; /** @ODM\Document(collection="DoctrineMongoDBBundle_Tests_Validator_Document") */ +#[ODM\Document(collection: 'DoctrineMongoDBBundle_Tests_Validator_Document')] class Document { /** @ODM\Id(strategy="none") */ + #[ODM\Id(strategy: 'none')] protected ObjectId $id; /** @ODM\Field(type="string") */ + #[ODM\Field(type: Type::STRING)] public string $name; /** @@ -21,6 +25,7 @@ class Document * * @var array */ + #[ODM\Field(type: Type::HASH)] public array $hash; /** @@ -28,12 +33,15 @@ class Document * * @var array */ + #[ODM\Field(type: Type::COLLECTION)] public array $collection; /** @ODM\ReferenceOne(targetDocument="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Validator\Document") */ + #[ODM\ReferenceOne(targetDocument: self::class)] public ?Document $referenceOne = null; /** @ODM\EmbedOne(targetDocument="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Validator\EmbeddedDocument") */ + #[ODM\EmbedOne(targetDocument: EmbeddedDocument::class)] public ?EmbeddedDocument $embedOne = null; /** @@ -41,6 +49,7 @@ class Document * * @var EmbeddedDocument[] */ + #[ODM\EmbedMany(targetDocument: EmbeddedDocument::class)] public array $embedMany = []; public function __construct(ObjectId $id) @@ -50,8 +59,10 @@ public function __construct(ObjectId $id) } /** @ODM\EmbeddedDocument */ +#[ODM\EmbeddedDocument] class EmbeddedDocument { /** @ODM\Field(type="string") */ + #[ODM\Field(type: Type::STRING)] public string $name; } diff --git a/Tests/ServiceRepositoryTest.php b/Tests/ServiceRepositoryTest.php index 8ee30188..ecbdb5a9 100644 --- a/Tests/ServiceRepositoryTest.php +++ b/Tests/ServiceRepositoryTest.php @@ -60,7 +60,7 @@ protected function setUp(): void 'default' => [ 'mappings' => [ 'RepositoryServiceBundle' => [ - 'type' => 'annotation', + 'type' => 'attribute', 'dir' => __DIR__ . '/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document', 'prefix' => 'Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\RepositoryServiceBundle\Document', ], diff --git a/Tests/TestCase.php b/Tests/TestCase.php index 41d5f93d..b24e0e14 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -4,10 +4,9 @@ namespace Doctrine\Bundle\MongoDBBundle\Tests; -use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\ODM\MongoDB\Configuration; use Doctrine\ODM\MongoDB\DocumentManager; -use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver; +use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver; use PHPUnit\Framework\TestCase as BaseTestCase; use Symfony\Component\Cache\Adapter\ArrayAdapter; @@ -24,7 +23,7 @@ public static function createTestDocumentManager(array $paths = []): DocumentMan $config->setHydratorDir(sys_get_temp_dir()); $config->setProxyNamespace('SymfonyTests\Doctrine'); $config->setHydratorNamespace('SymfonyTests\Doctrine'); - $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader(), $paths)); + $config->setMetadataDriverImpl(new AttributeDriver($paths)); $config->setMetadataCache(new ArrayAdapter()); return DocumentManager::create(null, $config); From b09c0e522101c8c5270eb2ae46b003c83f65d75b Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Tue, 5 Dec 2023 09:36:29 +0100 Subject: [PATCH 6/7] update psalm baseline --- psalm-baseline.xml | 50 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 07ad85e6..3378976c 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,15 +1,55 @@ - + + + + protected function execute(InputInterface $input, OutputInterface $output) + + + + + protected function execute(InputInterface $input, OutputInterface $output) + + + + + protected function execute(InputInterface $input, OutputInterface $output) + + + + + protected function execute(InputInterface $input, OutputInterface $output) + + + + + protected function execute(InputInterface $input, OutputInterface $output) + + ask + + + protected function execute(InputInterface $input, OutputInterface $output) + + + + + protected function execute(InputInterface $input, OutputInterface $output) + + int + + + protected function execute(InputInterface $input, OutputInterface $output) + + arrayNode @@ -21,10 +61,10 @@ children - - - configureOptions - + + + private ContainerInterface $container + From 39c53060733f4b9ef14ae25692450686967ba25a Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Tue, 5 Dec 2023 14:49:29 +0100 Subject: [PATCH 7/7] Remove mapping annotations --- .../Document/TestCustomClassRepoDocument.php | 2 -- .../TestCustomServiceRepoDocument.php | 2 -- .../Document/TestCustomServiceRepoFile.php | 2 -- .../Document/TestDefaultRepoDocument.php | 2 -- .../Document/TestDefaultRepoFile.php | 2 -- Tests/Fixtures/Cache/Collections.php | 5 ---- .../Fixtures/CommandBundle/Document/User.php | 2 -- Tests/Fixtures/DataCollector/Category.php | 3 --- Tests/Fixtures/Form/Category.php | 12 +-------- Tests/Fixtures/Form/Document.php | 13 +--------- Tests/Fixtures/Form/Guesser.php | 24 ++---------------- Tests/Fixtures/Security/User.php | 3 --- Tests/Fixtures/Validator/Document.php | 25 +++---------------- 13 files changed, 7 insertions(+), 90 deletions(-) diff --git a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomClassRepoDocument.php b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomClassRepoDocument.php index 702da4a9..1e0fe733 100644 --- a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomClassRepoDocument.php +++ b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomClassRepoDocument.php @@ -7,11 +7,9 @@ use Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\RepositoryServiceBundle\Repository\TestCustomClassRepoRepository; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -/** @ODM\Document(repositoryClass=TestCustomClassRepoRepository::class) */ #[ODM\Document(repositoryClass: TestCustomClassRepoRepository::class)] class TestCustomClassRepoDocument { - /** @ODM\Id */ #[ODM\Id] private string $id; } diff --git a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomServiceRepoDocument.php b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomServiceRepoDocument.php index 943ee6ad..4b3db764 100644 --- a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomServiceRepoDocument.php +++ b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomServiceRepoDocument.php @@ -7,11 +7,9 @@ use Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\RepositoryServiceBundle\Repository\TestCustomServiceRepoDocumentRepository; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -/** @ODM\Document(repositoryClass=TestCustomServiceRepoDocumentRepository::class) */ #[ODM\Document(repositoryClass: TestCustomServiceRepoDocumentRepository::class)] class TestCustomServiceRepoDocument { - /** @ODM\Id */ #[ODM\Id] private string $id; } diff --git a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomServiceRepoFile.php b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomServiceRepoFile.php index 8fac4490..86ac3fbc 100644 --- a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomServiceRepoFile.php +++ b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestCustomServiceRepoFile.php @@ -7,11 +7,9 @@ use Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\RepositoryServiceBundle\Repository\TestCustomServiceRepoGridFSRepository; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -/** @ODM\File(repositoryClass=TestCustomServiceRepoGridFSRepository::class) */ #[ODM\File(repositoryClass: TestCustomServiceRepoGridFSRepository::class)] class TestCustomServiceRepoFile { - /** @ODM\Id */ #[ODM\Id] private string $id; } diff --git a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestDefaultRepoDocument.php b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestDefaultRepoDocument.php index 5d83b26a..4874cdcf 100644 --- a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestDefaultRepoDocument.php +++ b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestDefaultRepoDocument.php @@ -6,11 +6,9 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -/** @ODM\Document */ #[ODM\Document] class TestDefaultRepoDocument { - /** @ODM\Id */ #[ODM\Id] private string $id; } diff --git a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestDefaultRepoFile.php b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestDefaultRepoFile.php index cacde3f5..3aa05c5d 100644 --- a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestDefaultRepoFile.php +++ b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Document/TestDefaultRepoFile.php @@ -6,11 +6,9 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -/** @ODM\File */ #[ODM\File] class TestDefaultRepoFile { - /** @ODM\Id */ #[ODM\Id] private string $id; } diff --git a/Tests/Fixtures/Cache/Collections.php b/Tests/Fixtures/Cache/Collections.php index c25fc3be..2b361c4d 100644 --- a/Tests/Fixtures/Cache/Collections.php +++ b/Tests/Fixtures/Cache/Collections.php @@ -8,23 +8,18 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use MongoDB\BSON\ObjectId; -/** @ODM\Document */ #[ODM\Document] class Collections { - /** @ODM\Id */ #[ODM\Id] public ?ObjectId $id = null; - /** @ODM\EmbedMany(collectionClass=SomeCollection::class) */ #[ODM\EmbedMany(collectionClass: SomeCollection::class)] public SomeCollection $coll; - /** @ODM\ReferenceMany(collectionClass=SomeCollection::class) */ #[ODM\ReferenceMany(collectionClass: SomeCollection::class)] public SomeCollection $refs; - /** @ODM\EmbedMany(collectionClass=AnotherCollection::class) */ #[ODM\EmbedMany(collectionClass: AnotherCollection::class)] public AnotherCollection $another; } diff --git a/Tests/Fixtures/CommandBundle/Document/User.php b/Tests/Fixtures/CommandBundle/Document/User.php index 06863dbf..5edf4fc7 100644 --- a/Tests/Fixtures/CommandBundle/Document/User.php +++ b/Tests/Fixtures/CommandBundle/Document/User.php @@ -6,11 +6,9 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -/** @ODM\Document */ #[ODM\Document] class User { - /** @ODM\Id */ #[ODM\Id] private ?string $id = null; } diff --git a/Tests/Fixtures/DataCollector/Category.php b/Tests/Fixtures/DataCollector/Category.php index 489dd3f8..c8c90d9a 100644 --- a/Tests/Fixtures/DataCollector/Category.php +++ b/Tests/Fixtures/DataCollector/Category.php @@ -8,15 +8,12 @@ use Doctrine\ODM\MongoDB\Types\Type; use MongoDB\BSON\ObjectId; -/** @ODM\Document */ #[ODM\Document] class Category { - /** @ODM\Id */ #[ODM\Id] protected ?ObjectId $id = null; - /** @ODM\Field(type="string") */ #[ODM\Field(type: Type::STRING)] public string $name; diff --git a/Tests/Fixtures/Form/Category.php b/Tests/Fixtures/Form/Category.php index 51ed8447..136d91ef 100644 --- a/Tests/Fixtures/Form/Category.php +++ b/Tests/Fixtures/Form/Category.php @@ -10,26 +10,16 @@ use Doctrine\ODM\MongoDB\Types\Type; use MongoDB\BSON\ObjectId; -/** @ODM\Document */ #[ODM\Document] class Category { - /** @ODM\Id */ #[ODM\Id] protected ObjectId|string|null $id; - /** @ODM\Field(type="string") */ #[ODM\Field(type: Type::STRING)] public string $name; - /** - * @ODM\ReferenceMany( - * targetDocument="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Form\Document", - * mappedBy="categories" - * ) - * - * @var Collection - */ + /** @var Collection */ #[ODM\ReferenceMany( targetDocument: Document::class, mappedBy: 'categories', diff --git a/Tests/Fixtures/Form/Document.php b/Tests/Fixtures/Form/Document.php index f51e412f..3366a1c5 100644 --- a/Tests/Fixtures/Form/Document.php +++ b/Tests/Fixtures/Form/Document.php @@ -11,27 +11,16 @@ use Doctrine\ODM\MongoDB\Types\Type; use MongoDB\BSON\ObjectId; -/** @ODM\Document */ #[ODM\Document] class Document { - /** @ODM\Id(strategy="none") */ #[ODM\Id(strategy: 'none')] protected ObjectId $id; - /** @ODM\Field(type="string") */ #[ODM\Field(type: Type::STRING)] public string $name; - /** - * @ODM\ReferenceMany( - * targetDocument="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Form\Category", - * inversedBy="documents", - * strategy="atomicSetArray" - * ) - * - * @var Collection - */ + /** @var Collection */ #[ODM\ReferenceMany( targetDocument: Category::class, inversedBy: 'documents', diff --git a/Tests/Fixtures/Form/Guesser.php b/Tests/Fixtures/Form/Guesser.php index 8d61d0c2..3afa0f29 100644 --- a/Tests/Fixtures/Form/Guesser.php +++ b/Tests/Fixtures/Form/Guesser.php @@ -11,35 +11,22 @@ use Doctrine\ODM\MongoDB\Types\Type; use MongoDB\BSON\ObjectId; -/** @ODM\Document */ #[ODM\Document] class Guesser { - /** @ODM\Id(strategy="none") */ #[ODM\Id(strategy: 'none')] protected ?ObjectId $id = null; - /** @ODM\Field() */ #[ODM\Field] public ?string $name = null; - /** @ODM\Field(type="date") */ #[ODM\Field(type: Type::DATE)] public ?DateTime $date = null; - /** @ODM\Field(type="timestamp") */ #[ODM\Field(type: Type::TIMESTAMP)] public DateTime $ts; - /** - * @ODM\ReferenceMany( - * targetDocument="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Form\Category", - * inversedBy="documents", - * strategy="atomicSetArray" - * ) - * - * @var Collection - */ + /** @var Collection */ #[ODM\ReferenceMany( targetDocument: Category::class, inversedBy: 'documents', @@ -47,23 +34,16 @@ class Guesser )] public Collection $categories; - /** @ODM\Field(type="bool") */ #[ODM\Field(type: Type::BOOL)] public ?bool $boolField = null; - /** @ODM\Field(type="float") */ #[ODM\Field(type: Type::FLOAT)] public ?float $floatField = null; - /** @ODM\Field(type="int") */ #[ODM\Field(type: Type::INT)] public ?int $intField = null; - /** - * @ODM\Field(type="collection") - * - * @var array - */ + /** @var array */ #[ODM\Field(type: Type::COLLECTION)] public array $collectionField; diff --git a/Tests/Fixtures/Security/User.php b/Tests/Fixtures/Security/User.php index cf89c48a..9d5966dc 100644 --- a/Tests/Fixtures/Security/User.php +++ b/Tests/Fixtures/Security/User.php @@ -9,15 +9,12 @@ use MongoDB\BSON\ObjectId; use Symfony\Component\Security\Core\User\UserInterface; -/** @ODM\Document */ #[ODM\Document] class User implements UserInterface { - /** @ODM\Id(strategy="none") */ #[ODM\Id(strategy: 'none')] protected ObjectId $id; - /** @ODM\Field(type="string") */ #[ODM\Field(type: Type::STRING)] public string $name; diff --git a/Tests/Fixtures/Validator/Document.php b/Tests/Fixtures/Validator/Document.php index 02b459b9..f2cc90c6 100644 --- a/Tests/Fixtures/Validator/Document.php +++ b/Tests/Fixtures/Validator/Document.php @@ -8,47 +8,30 @@ use Doctrine\ODM\MongoDB\Types\Type; use MongoDB\BSON\ObjectId; -/** @ODM\Document(collection="DoctrineMongoDBBundle_Tests_Validator_Document") */ #[ODM\Document(collection: 'DoctrineMongoDBBundle_Tests_Validator_Document')] class Document { - /** @ODM\Id(strategy="none") */ #[ODM\Id(strategy: 'none')] protected ObjectId $id; - /** @ODM\Field(type="string") */ #[ODM\Field(type: Type::STRING)] public string $name; - /** - * @ODM\Field(type="hash") - * - * @var array - */ + /** @var array */ #[ODM\Field(type: Type::HASH)] public array $hash; - /** - * @ODM\Field(type="collection") - * - * @var array - */ + /** @var array */ #[ODM\Field(type: Type::COLLECTION)] public array $collection; - /** @ODM\ReferenceOne(targetDocument="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Validator\Document") */ #[ODM\ReferenceOne(targetDocument: self::class)] public ?Document $referenceOne = null; - /** @ODM\EmbedOne(targetDocument="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Validator\EmbeddedDocument") */ #[ODM\EmbedOne(targetDocument: EmbeddedDocument::class)] public ?EmbeddedDocument $embedOne = null; - /** - * @ODM\EmbedMany(targetDocument="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Validator\EmbeddedDocument") - * - * @var EmbeddedDocument[] - */ + /** @var EmbeddedDocument[] */ #[ODM\EmbedMany(targetDocument: EmbeddedDocument::class)] public array $embedMany = []; @@ -58,11 +41,9 @@ public function __construct(ObjectId $id) } } -/** @ODM\EmbeddedDocument */ #[ODM\EmbeddedDocument] class EmbeddedDocument { - /** @ODM\Field(type="string") */ #[ODM\Field(type: Type::STRING)] public string $name; }