From b34164df337f8d4ed90a1d718b44b71d77baa092 Mon Sep 17 00:00:00 2001 From: kbond Date: Mon, 1 Jan 2024 01:05:52 +0000 Subject: [PATCH 01/11] bot: fix cs [skip ci] --- src/Bundle/Resources/skeleton/Factory.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/Resources/skeleton/Factory.tpl.php b/src/Bundle/Resources/skeleton/Factory.tpl.php index 1728406b2..e4dd60f98 100644 --- a/src/Bundle/Resources/skeleton/Factory.tpl.php +++ b/src/Bundle/Resources/skeleton/Factory.tpl.php @@ -1,4 +1,4 @@ - + namespace ; From 8fcf918b323ddff7dd4640ec822dae9eb9aa8f0c Mon Sep 17 00:00:00 2001 From: kbond Date: Tue, 16 Jan 2024 01:01:08 +0000 Subject: [PATCH 02/11] bot: sync with template [skip ci] --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 92bfdebb7..e40649d38 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Kevin Bond +Copyright (c) 2024 Kevin Bond Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 49341f390dcb13c08b9f1ae253e65ddec789c6bf Mon Sep 17 00:00:00 2001 From: kbond Date: Tue, 16 Jan 2024 01:01:35 +0000 Subject: [PATCH 03/11] bot: fix cs [skip ci] --- src/Bundle/Command/StubCommand.php | 2 +- .../ZenstruckFoundryExtension.php | 2 +- .../Maker/Factory/AbstractDefaultPropertyGuesser.php | 2 +- src/Bundle/Maker/Factory/FactoryClassMap.php | 4 ++-- src/Bundle/Maker/Factory/FactoryGenerator.php | 12 ++++++------ src/Bundle/Maker/Factory/MakeFactoryData.php | 4 ++-- src/Bundle/Maker/Factory/MakeFactoryQuery.php | 2 +- src/Bundle/Maker/Factory/NamespaceGuesser.php | 2 +- .../Factory/NoPersistenceObjectsAutoCompleter.php | 8 ++++---- src/Bundle/Maker/MakeFactory.php | 4 ++-- src/Bundle/Maker/MakeStory.php | 4 ++-- src/ChainManagerRegistry.php | 2 +- src/Configuration.php | 2 +- src/Exception/FoundryBootException.php | 4 ++-- src/Factory.php | 2 +- src/FactoryCollection.php | 4 ++-- src/Proxy.php | 6 +++--- src/RepositoryProxy.php | 4 ++-- src/Test/AbstractSchemaResetter.php | 2 +- src/Test/DatabaseResetter.php | 6 +++--- src/Test/Factories.php | 4 ++-- src/Test/GlobalStateRegistry.php | 4 ++-- src/Test/ODMSchemaResetter.php | 4 ++-- src/Test/ORMDatabaseResetter.php | 6 +++--- src/Test/TestState.php | 2 +- tests/Fixtures/Entity/Address.php | 2 +- tests/Fixtures/Factories/CategoryFactory.php | 2 +- tests/Fixtures/Factories/PostFactory.php | 2 +- tests/Fixtures/Kernel.php | 8 ++++---- tests/Functional/Bundle/Maker/MakeFactoryTest.php | 8 ++++---- tests/Functional/Bundle/Maker/MakeStoryTest.php | 8 ++++---- tests/Functional/Bundle/Maker/MakerTestCase.php | 2 +- tests/Functional/FactoryTest.php | 6 +++--- tests/Functional/ORMModelFactoryTest.php | 12 ++++++------ tests/Functional/ORMRepositoryProxyTest.php | 2 +- tests/Functional/RepositoryProxyTest.php | 6 +++--- tests/Functional/WithMigrationTest.php | 2 +- .../ChainManagerRegistryPassTest.php | 4 ++-- tests/Unit/ChainManagerRegistryTest.php | 10 +++++----- 39 files changed, 86 insertions(+), 86 deletions(-) diff --git a/src/Bundle/Command/StubCommand.php b/src/Bundle/Command/StubCommand.php index 72a453125..e647f00d8 100644 --- a/src/Bundle/Command/StubCommand.php +++ b/src/Bundle/Command/StubCommand.php @@ -22,7 +22,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int { (new SymfonyStyle($input, $output)) ->error( - \sprintf("To run \"%s\" you need the \"MakerBundle\" which is currently not installed.\n\nTry running \"composer require symfony/maker-bundle --dev\".", static::getDefaultName()) + \sprintf("To run \"%s\" you need the \"MakerBundle\" which is currently not installed.\n\nTry running \"composer require symfony/maker-bundle --dev\".", static::getDefaultName()), ) ; diff --git a/src/Bundle/DependencyInjection/ZenstruckFoundryExtension.php b/src/Bundle/DependencyInjection/ZenstruckFoundryExtension.php index 39fa64dbf..993c90828 100644 --- a/src/Bundle/DependencyInjection/ZenstruckFoundryExtension.php +++ b/src/Bundle/DependencyInjection/ZenstruckFoundryExtension.php @@ -139,7 +139,7 @@ private static function isBundleLoaded(ContainerBuilder $container, string $bund return \in_array( $bundleName, \is_array($bundles = $container->getParameter('kernel.bundles')) ? $bundles : [], - true + true, ); } } diff --git a/src/Bundle/Maker/Factory/AbstractDefaultPropertyGuesser.php b/src/Bundle/Maker/Factory/AbstractDefaultPropertyGuesser.php index d9fd18bc3..83f73fb91 100644 --- a/src/Bundle/Maker/Factory/AbstractDefaultPropertyGuesser.php +++ b/src/Bundle/Maker/Factory/AbstractDefaultPropertyGuesser.php @@ -28,7 +28,7 @@ protected function addDefaultValueUsingFactory(SymfonyStyle $io, MakeFactoryData { if (!$factoryClass = $this->factoryClassMap->getFactoryForClass($fieldClass)) { if ($makeFactoryQuery->generateAllFactories() || $io->confirm( - "A factory for class \"{$fieldClass}\" is missing for field {$makeFactoryData->getObjectShortName()}::\${$fieldName}. Do you want to create it?" + "A factory for class \"{$fieldClass}\" is missing for field {$makeFactoryData->getObjectShortName()}::\${$fieldName}. Do you want to create it?", )) { $factoryClass = $this->factoryGenerator->generateFactory($io, $makeFactoryQuery->withClass($fieldClass)); } else { diff --git a/src/Bundle/Maker/Factory/FactoryClassMap.php b/src/Bundle/Maker/Factory/FactoryClassMap.php index 1aabebafd..d8b91dfbc 100644 --- a/src/Bundle/Maker/Factory/FactoryClassMap.php +++ b/src/Bundle/Maker/Factory/FactoryClassMap.php @@ -35,8 +35,8 @@ static function(array $carry, ModelFactory $factory): array { return $carry; }, - [] - ) + [], + ), ); } diff --git a/src/Bundle/Maker/Factory/FactoryGenerator.php b/src/Bundle/Maker/Factory/FactoryGenerator.php index c7c5f89f9..c75b7bbd8 100644 --- a/src/Bundle/Maker/Factory/FactoryGenerator.php +++ b/src/Bundle/Maker/Factory/FactoryGenerator.php @@ -69,8 +69,8 @@ public function generateFactory(SymfonyStyle $io, MakeFactoryQuery $makeFactoryQ \sprintf( 'Class "%s" already exists. Chose another one please (it will be generated in namespace "%s")', Str::getShortClassName($factoryClass), - Str::getNamespace($factoryClass) - ) + Str::getNamespace($factoryClass), + ), ); $question->setValidator( @@ -81,7 +81,7 @@ function(string $newClassName) use ($factoryClass) { } return $newFactoryClass; - } + }, ); $factoryClass = $io->askQuestion($question); @@ -100,7 +100,7 @@ function(string $newClassName) use ($factoryClass) { __DIR__.'/../../Resources/skeleton/Factory.tpl.php', [ 'makeFactoryData' => $makeFactoryData, - ] + ], ); return $factoryClass; @@ -114,7 +114,7 @@ private function createMakeFactoryData(Generator $generator, string $class, Make $factory = $generator->createClassNameDetails( $object->getShortName(), ($this->namespaceGuesser)($generator, $class, $makeFactoryQuery->getNamespace(), $makeFactoryQuery->isTest()), - 'Factory' + 'Factory', ); if ($persisted = $makeFactoryQuery->isPersisted()) { @@ -137,7 +137,7 @@ private function createMakeFactoryData(Generator $generator, string $class, Make $factory, $repository ?? null, $this->staticAnalysisTool(), - $persisted + $persisted, ); } diff --git a/src/Bundle/Maker/Factory/MakeFactoryData.php b/src/Bundle/Maker/Factory/MakeFactoryData.php index 68c218649..f48303986 100644 --- a/src/Bundle/Maker/Factory/MakeFactoryData.php +++ b/src/Bundle/Maker/Factory/MakeFactoryData.php @@ -130,7 +130,7 @@ public function getMethodsPHPDoc(): array $methodsInPHPDoc = $this->methodsInPHPDoc; \usort( $methodsInPHPDoc, - static fn(MakeFactoryPHPDocMethod $m1, MakeFactoryPHPDocMethod $m2) => $m1->sortValue() <=> $m2->sortValue() + static fn(MakeFactoryPHPDocMethod $m1, MakeFactoryPHPDocMethod $m2) => $m1->sortValue() <=> $m2->sortValue(), ); return $methodsInPHPDoc; @@ -151,7 +151,7 @@ public function addEnumDefaultProperty(string $propertyName, string $enumClass): $enumShortClassName = Str::getShortClassName($enumClass); $this->addDefaultProperty( $propertyName, - "self::faker()->randomElement({$enumShortClassName}::cases())," + "self::faker()->randomElement({$enumShortClassName}::cases()),", ); } } diff --git a/src/Bundle/Maker/Factory/MakeFactoryQuery.php b/src/Bundle/Maker/Factory/MakeFactoryQuery.php index fa45d7475..706249d05 100644 --- a/src/Bundle/Maker/Factory/MakeFactoryQuery.php +++ b/src/Bundle/Maker/Factory/MakeFactoryQuery.php @@ -32,7 +32,7 @@ public static function fromInput(InputInterface $input, string $class, bool $gen allFields: (bool) $input->getOption('all-fields'), class: $class, generateAllFactories: $generateAllFactories, - generator: $generator + generator: $generator, ); } diff --git a/src/Bundle/Maker/Factory/NamespaceGuesser.php b/src/Bundle/Maker/Factory/NamespaceGuesser.php index f3b8646aa..634efca04 100644 --- a/src/Bundle/Maker/Factory/NamespaceGuesser.php +++ b/src/Bundle/Maker/Factory/NamespaceGuesser.php @@ -36,7 +36,7 @@ public function __construct(ManagerRegistry $managerRegistry) $doctrineNamespaces[] = match (true) { \is_a($manager, EntityManager::class) => \array_values($manager->getConfiguration()->getEntityNamespaces()), \is_a($manager, DocumentManager::class) => \array_values($manager->getConfiguration()->getDocumentNamespaces()), - default => [] + default => [], }; } diff --git a/src/Bundle/Maker/Factory/NoPersistenceObjectsAutoCompleter.php b/src/Bundle/Maker/Factory/NoPersistenceObjectsAutoCompleter.php index c7ea9c8d5..5f4c4ab27 100644 --- a/src/Bundle/Maker/Factory/NoPersistenceObjectsAutoCompleter.php +++ b/src/Bundle/Maker/Factory/NoPersistenceObjectsAutoCompleter.php @@ -74,12 +74,12 @@ private function getDefinedNamespaces(): array return \array_combine( \array_map( static fn(string $namespacePrefix): string => \trim($namespacePrefix, '\\'), - \array_keys($definedNamespaces) + \array_keys($definedNamespaces), ), \array_map( static fn(string $rootFragment): string => \trim($rootFragment, '/'), - \array_values($definedNamespaces) - ) + \array_values($definedNamespaces), + ), ); } @@ -89,7 +89,7 @@ private function excludedFiles(): array return \array_map( fn(string $file): string => "{$this->kernelRootDir}/{$file}", - $composerConfig['autoload']['files'] ?? [] + $composerConfig['autoload']['files'] ?? [], ); } diff --git a/src/Bundle/Maker/MakeFactory.php b/src/Bundle/Maker/MakeFactory.php index ffa644e0a..9be7b3aaa 100644 --- a/src/Bundle/Maker/MakeFactory.php +++ b/src/Bundle/Maker/MakeFactory.php @@ -40,7 +40,7 @@ public function __construct( private FactoryGenerator $factoryGenerator, private NoPersistenceObjectsAutoCompleter $noPersistenceObjectsAutoCompleter, private FactoryCandidatesClassesExtractor $factoryCandidatesClassesExtractor, - private string $defaultNamespace + private string $defaultNamespace, ) { } @@ -105,7 +105,7 @@ static function(string $class) { } return $class; - } + }, ); $question->setAutocompleterValues($this->noPersistenceObjectsAutoCompleter->getAutocompleteValues()); $class = $io->askQuestion($question); diff --git a/src/Bundle/Maker/MakeStory.php b/src/Bundle/Maker/MakeStory.php index 9e1949dd7..403b31621 100644 --- a/src/Bundle/Maker/MakeStory.php +++ b/src/Bundle/Maker/MakeStory.php @@ -68,13 +68,13 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen $storyClassNameDetails = $generator->createClassNameDetails( $input->getArgument('name'), $input->getOption('test') ? 'Tests\\Story' : 'Story', - 'Story' + 'Story', ); $generator->generateClass( $storyClassNameDetails->getFullName(), __DIR__.'/../Resources/skeleton/Story.tpl.php', - [] + [], ); $generator->writeChanges(); diff --git a/src/ChainManagerRegistry.php b/src/ChainManagerRegistry.php index 250ec93a0..10107d59f 100644 --- a/src/ChainManagerRegistry.php +++ b/src/ChainManagerRegistry.php @@ -59,7 +59,7 @@ public function getManagers(): array return \array_reduce( $this->managerRegistries, static fn(array $carry, ManagerRegistry $managerRegistry): array => \array_merge($carry, \array_values($managerRegistry->getManagers())), - [] + [], ); } diff --git a/src/Configuration.php b/src/Configuration.php index 317ed7df7..d890e7a35 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -30,7 +30,7 @@ final class Configuration private ModelFactoryManager $factories; - private \Faker\Generator $faker; + private Faker\Generator $faker; /** @var callable */ private $instantiator; diff --git a/src/Exception/FoundryBootException.php b/src/Exception/FoundryBootException.php index 437a540c4..8817b1b57 100644 --- a/src/Exception/FoundryBootException.php +++ b/src/Exception/FoundryBootException.php @@ -26,14 +26,14 @@ private function __construct(string $message) public static function notBootedYet(): self { return new self( - 'Foundry is not yet booted. Using in a test: is your Test case using the Factories trait? Using in a fixture: is ZenstruckFoundryBundle enabled for this environment?' + 'Foundry is not yet booted. Using in a test: is your Test case using the Factories trait? Using in a fixture: is ZenstruckFoundryBundle enabled for this environment?', ); } public static function notBootedWithDoctrine(): self { return new self( - 'Foundry was booted without doctrine. Ensure your TestCase extends '.KernelTestCase::class + 'Foundry was booted without doctrine. Ensure your TestCase extends '.KernelTestCase::class, ); } } diff --git a/src/Factory.php b/src/Factory.php index ed31d971d..905fba462 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -379,7 +379,7 @@ private function normalizeAttribute(mixed $value, string $name): mixed if (\is_array($value)) { return \array_map( fn($value) => $this->normalizeAttribute($value, $name), - $value + $value, ); } diff --git a/src/FactoryCollection.php b/src/FactoryCollection.php index d4e020acc..6eea33942 100644 --- a/src/FactoryCollection.php +++ b/src/FactoryCollection.php @@ -74,7 +74,7 @@ public function create(array|callable $attributes = []): array $objects = []; foreach ($this->all() as $i => $factory) { $objects[] = $factory->create( - \is_callable($attributes) ? $attributes($i + 1) : $attributes + \is_callable($attributes) ? $attributes($i + 1) : $attributes, ); } @@ -91,7 +91,7 @@ public function all(): array if (!$this->sequence) { return \array_map( fn(): Factory => clone $this->factory, - \array_fill(0, \random_int($this->min, $this->max), null) + \array_fill(0, \random_int($this->min, $this->max), null), ); } diff --git a/src/Proxy.php b/src/Proxy.php index 150efacb5..1b8e2c413 100644 --- a/src/Proxy.php +++ b/src/Proxy.php @@ -42,7 +42,7 @@ final class Proxy implements \Stringable */ public function __construct( /** @param TProxiedObject $object */ - private object $object + private object $object, ) { $this->class = $object::class; $this->autoRefresh = Factory::configuration()->defaultProxyAutoRefresh(); @@ -277,9 +277,9 @@ public function executeCallback(callable $callback, mixed ...$arguments): void Parameter::union( Parameter::untyped($this), Parameter::typed(self::class, $this), - Parameter::typed($this->class, Parameter::factory(fn(): object => $this->object())) + Parameter::typed($this->class, Parameter::factory(fn(): object => $this->object())), )->optional(), - ...$arguments + ...$arguments, ); } diff --git a/src/RepositoryProxy.php b/src/RepositoryProxy.php index a714f6aa2..d4a027045 100644 --- a/src/RepositoryProxy.php +++ b/src/RepositoryProxy.php @@ -342,7 +342,7 @@ public function find($criteria) $isEmbedded = match ($metadataForAttribute::class) { ORMClassMetadata::class => $metadataForAttribute->isEmbeddedClass, ODMClassMetadata::class => $metadataForAttribute->isEmbeddedDocument, - default => throw new \LogicException(\sprintf('Metadata class %s is not supported.', $metadataForAttribute::class)) + default => throw new \LogicException(\sprintf('Metadata class %s is not supported.', $metadataForAttribute::class)), }; // it's a regular entity @@ -444,7 +444,7 @@ private static function normalizeCriteria(array $criteria): array { return \array_map( static fn($value) => $value instanceof Proxy ? $value->object() : $value, - $criteria + $criteria, ); } diff --git a/src/Test/AbstractSchemaResetter.php b/src/Test/AbstractSchemaResetter.php index 28266f808..8d84f1f7f 100644 --- a/src/Test/AbstractSchemaResetter.php +++ b/src/Test/AbstractSchemaResetter.php @@ -26,7 +26,7 @@ protected function runCommand(Application $application, string $command, array $ { $exit = $application->run( new ArrayInput(\array_merge(['command' => $command], $parameters)), - $output = new BufferedOutput() + $output = new BufferedOutput(), ); if (0 !== $exit && !$canFail) { diff --git a/src/Test/DatabaseResetter.php b/src/Test/DatabaseResetter.php index e07e8f7b0..c266070ba 100644 --- a/src/Test/DatabaseResetter.php +++ b/src/Test/DatabaseResetter.php @@ -92,7 +92,7 @@ private static function bootFoundry(KernelInterface $kernel, bool $flushGlobalSt if ($flushGlobalState) { TestState::flushGlobalState( - $container->has('.zenstruck_foundry.global_state_registry') ? $container->get('.zenstruck_foundry.global_state_registry') : null + $container->has('.zenstruck_foundry.global_state_registry') ? $container->get('.zenstruck_foundry.global_state_registry') : null, ); } } @@ -115,7 +115,7 @@ private static function createORMDatabaseResetter(Application $application, Kern $container->get('doctrine'), $configuration ? $configuration->getOrmConnectionsToReset() : [], $configuration ? $configuration->getOrmObjectManagersToReset() : [], - $configuration ? $configuration->getOrmResetMode() : ORMDatabaseResetter::RESET_MODE_SCHEMA + $configuration ? $configuration->getOrmResetMode() : ORMDatabaseResetter::RESET_MODE_SCHEMA, ); } @@ -127,7 +127,7 @@ private static function createODMSchemaResetter(Application $application, Kernel return new ODMSchemaResetter( $application, $container->get('doctrine_mongodb'), - $configuration ? $configuration->getOdmObjectManagersToReset() : [] + $configuration ? $configuration->getOdmObjectManagersToReset() : [], ); } diff --git a/src/Test/Factories.php b/src/Test/Factories.php index c4b640b35..ca14b3dde 100644 --- a/src/Test/Factories.php +++ b/src/Test/Factories.php @@ -46,8 +46,8 @@ public static function _setUpFactories(): void } return TestState::initializeChainManagerRegistry(static::$kernel->getContainer()); - } - ) + }, + ), ); $kernel->shutdown(); diff --git a/src/Test/GlobalStateRegistry.php b/src/Test/GlobalStateRegistry.php index d74900ab0..c07699b34 100644 --- a/src/Test/GlobalStateRegistry.php +++ b/src/Test/GlobalStateRegistry.php @@ -57,14 +57,14 @@ public function getGlobalStates(): array // let's use ::load() in order to register the service in StoryManager $story::class::load(); }, - $this->storiesAsService + $this->storiesAsService, ), ...$this->invokableServices, ...\array_map( static fn(string $storyClassName): \Closure => static function() use ($storyClassName): void { $storyClassName::load(); }, - $this->standaloneStories + $this->standaloneStories, ), ]; } diff --git a/src/Test/ODMSchemaResetter.php b/src/Test/ODMSchemaResetter.php index b19135836..58ec700f7 100644 --- a/src/Test/ODMSchemaResetter.php +++ b/src/Test/ODMSchemaResetter.php @@ -40,7 +40,7 @@ public function resetSchema(): void 'doctrine:mongodb:schema:drop', [ '--dm' => $manager, - ] + ], ); } catch (\Exception) { } @@ -50,7 +50,7 @@ public function resetSchema(): void 'doctrine:mongodb:schema:create', [ '--dm' => $manager, - ] + ], ); } } diff --git a/src/Test/ORMDatabaseResetter.php b/src/Test/ORMDatabaseResetter.php index 143983c0b..7a553eb47 100644 --- a/src/Test/ORMDatabaseResetter.php +++ b/src/Test/ORMDatabaseResetter.php @@ -75,7 +75,7 @@ private function createSchema(): void 'doctrine:schema:create', [ '--em' => $manager, - ] + ], ); } } @@ -95,7 +95,7 @@ private function dropSchema(): void [ '--em' => $manager, '--force' => true, - ] + ], ); } } @@ -132,7 +132,7 @@ private function dropAndResetDatabase(): void 'doctrine:database:create', [ '--connection' => $connection, - ] + ], ); } } diff --git a/src/Test/TestState.php b/src/Test/TestState.php index f68582fee..e16de84b3 100644 --- a/src/Test/TestState.php +++ b/src/Test/TestState.php @@ -29,7 +29,7 @@ final class TestState /** @var callable|null */ private static $instantiator; - private static ?\Faker\Generator $faker = null; + private static ?Faker\Generator $faker = null; private static ?bool $defaultProxyAutoRefresh = null; diff --git a/tests/Fixtures/Entity/Address.php b/tests/Fixtures/Entity/Address.php index e498a1d39..a0ad10324 100644 --- a/tests/Fixtures/Entity/Address.php +++ b/tests/Fixtures/Entity/Address.php @@ -18,7 +18,7 @@ final class Address { public function __construct( #[ORM\Column(type: 'string', nullable: true)] - private string $value + private string $value, ) { } diff --git a/tests/Fixtures/Factories/CategoryFactory.php b/tests/Fixtures/Factories/CategoryFactory.php index 6edd0f1aa..f74a2352a 100644 --- a/tests/Fixtures/Factories/CategoryFactory.php +++ b/tests/Fixtures/Factories/CategoryFactory.php @@ -34,7 +34,7 @@ protected function initialize() { return $this ->instantiateWith( - (new Instantiator())->allowExtraAttributes(['extraPostsBeforeInstantiate', 'extraPostsAfterInstantiate']) + (new Instantiator())->allowExtraAttributes(['extraPostsBeforeInstantiate', 'extraPostsAfterInstantiate']), ) ->beforeInstantiate(function(array $attributes): array { if (isset($attributes['extraPostsBeforeInstantiate'])) { diff --git a/tests/Fixtures/Factories/PostFactory.php b/tests/Fixtures/Factories/PostFactory.php index 415f2a475..039632810 100644 --- a/tests/Fixtures/Factories/PostFactory.php +++ b/tests/Fixtures/Factories/PostFactory.php @@ -42,7 +42,7 @@ protected function initialize() { return $this ->instantiateWith( - (new Instantiator())->allowExtraAttributes(['extraCategoryBeforeInstantiate', 'extraCategoryAfterInstantiate']) + (new Instantiator())->allowExtraAttributes(['extraCategoryBeforeInstantiate', 'extraCategoryAfterInstantiate']), ) ->beforeInstantiate(function(array $attributes): array { if (isset($attributes['extraCategoryBeforeInstantiate'])) { diff --git a/tests/Fixtures/Kernel.php b/tests/Fixtures/Kernel.php index 96f05acdb..9991e5aa6 100644 --- a/tests/Fixtures/Kernel.php +++ b/tests/Fixtures/Kernel.php @@ -99,9 +99,9 @@ public function getCacheDir(): string $this->defaultMakeFactoryNamespace, $this->withMigrations(), ], - \JSON_THROW_ON_ERROR - ) - ) + \JSON_THROW_ON_ERROR, + ), + ), ); } @@ -160,7 +160,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load 'auto_mapping' => true, 'mappings' => $mappings, ], - ] + ], ); } diff --git a/tests/Functional/Bundle/Maker/MakeFactoryTest.php b/tests/Functional/Bundle/Maker/MakeFactoryTest.php index c50a2d423..c892d3369 100644 --- a/tests/Functional/Bundle/Maker/MakeFactoryTest.php +++ b/tests/Functional/Bundle/Maker/MakeFactoryTest.php @@ -110,7 +110,7 @@ public function can_create_factory_interactively(): void $output = $tester->getDisplay(); $this->assertStringContainsString( 'A factory for class "Zenstruck\Foundry\Tests\Fixtures\Entity\User" is missing for field Comment::$user. Do you want to create it?', - $output + $output, ); $this->assertFileDoesNotExist(self::tempFile('src/Factory/UserFactory.php')); @@ -570,7 +570,7 @@ protected static function createKernel(array $options = []): KernelInterface return Kernel::create( enableDoctrine: $options['enableDoctrine'] ?? true, factoriesRegistered: $options['factoriesRegistered'] ?? [], - defaultMakeFactoryNamespace: $options['defaultMakeFactoryNamespace'] ?? null + defaultMakeFactoryNamespace: $options['defaultMakeFactoryNamespace'] ?? null, ); } @@ -584,8 +584,8 @@ private function makeFactoryCommandTester(array $factoriesRegistered = []): Comm { return new CommandTester( (new Application( - self::bootKernel($factoriesRegistered) - ))->find('make:factory') + self::bootKernel($factoriesRegistered), + ))->find('make:factory'), ); } } diff --git a/tests/Functional/Bundle/Maker/MakeStoryTest.php b/tests/Functional/Bundle/Maker/MakeStoryTest.php index 05411b988..4368043ab 100644 --- a/tests/Functional/Bundle/Maker/MakeStoryTest.php +++ b/tests/Functional/Bundle/Maker/MakeStoryTest.php @@ -57,7 +57,7 @@ public function build(): void } EOF - , \file_get_contents(self::tempFile('src/Story/FooBarStory.php')) + , \file_get_contents(self::tempFile('src/Story/FooBarStory.php')), ); } @@ -103,7 +103,7 @@ public function build(): void } EOF - , \file_get_contents(self::tempFile('src/Story/FooBarStory.php')) + , \file_get_contents(self::tempFile('src/Story/FooBarStory.php')), ); } @@ -145,7 +145,7 @@ public function build(): void } EOF - , \file_get_contents(self::tempFile('tests/Story/FooBarStory.php')) + , \file_get_contents(self::tempFile('tests/Story/FooBarStory.php')), ); } @@ -191,7 +191,7 @@ public function build(): void } EOF - , \file_get_contents(self::tempFile('tests/Story/FooBarStory.php')) + , \file_get_contents(self::tempFile('tests/Story/FooBarStory.php')), ); } diff --git a/tests/Functional/Bundle/Maker/MakerTestCase.php b/tests/Functional/Bundle/Maker/MakerTestCase.php index 15cf0a68e..314f2a4d2 100644 --- a/tests/Functional/Bundle/Maker/MakerTestCase.php +++ b/tests/Functional/Bundle/Maker/MakerTestCase.php @@ -57,7 +57,7 @@ protected function expectedFile(): string $path = \sprintf( '%s/../../../Fixtures/Maker/expected/%s.php', __DIR__, - (new AsciiSlugger())->slug($this->getName(), '_') + (new AsciiSlugger())->slug($this->getName(), '_'), ); $this->assertFileExists($path); diff --git a/tests/Functional/FactoryTest.php b/tests/Functional/FactoryTest.php index da374eee4..940168a91 100644 --- a/tests/Functional/FactoryTest.php +++ b/tests/Functional/FactoryTest.php @@ -71,7 +71,7 @@ public function one_to_many_relationship(): void $posts = \array_map( static fn($post) => $post->getTitle(), - $category->getPosts()->toArray() + $category->getPosts()->toArray(), ); $this->assertCount(2, $posts); @@ -95,7 +95,7 @@ public function many_to_many_relationship(): void $tags = \array_map( static fn($tag) => $tag->getName(), - $post->getTags()->toArray() + $post->getTags()->toArray(), ); $this->assertCount(2, $tags); @@ -118,7 +118,7 @@ public function many_to_many_reverse_relationship(): void $posts = \array_map( static fn($post) => $post->getTitle(), - $tag->getPosts()->toArray() + $tag->getPosts()->toArray(), ); $this->assertCount(2, $posts); diff --git a/tests/Functional/ORMModelFactoryTest.php b/tests/Functional/ORMModelFactoryTest.php index 84a7328a8..d7b144f87 100644 --- a/tests/Functional/ORMModelFactoryTest.php +++ b/tests/Functional/ORMModelFactoryTest.php @@ -302,7 +302,7 @@ public function many_to_many_with_nested_collection_relationship(): void TagFactory::assert()->count( \getenv('USE_FOUNDRY_BUNDLE') ? 5 // 3 created by this test and 2 in global state - : 3 + : 3, ); PostFactory::assert()->count(1); } @@ -322,7 +322,7 @@ public function many_to_many_with_two_relationships_same_entity(): void TagFactory::assert()->count( \getenv('USE_FOUNDRY_BUNDLE') ? 8 // 6 created by this test and 2 in global state - : 6 + : 6, ); PostFactory::assert()->count(1); } @@ -368,7 +368,7 @@ public function inverse_many_to_many_with_nested_collection_relationship(): void TagFactory::assert()->count( \getenv('USE_FOUNDRY_BUNDLE') ? 3 // 1 created by this test and 2 in global state - : 1 + : 1, ); PostFactory::assert()->count(3); } @@ -388,7 +388,7 @@ public function inverse_many_to_many_with_two_relationships_same_entity(): void TagFactory::assert()->count( \getenv('USE_FOUNDRY_BUNDLE') ? 3 // 1 created by this test and 2 in global state - : 1 + : 1, ); PostFactory::assert()->count(6); } @@ -435,7 +435,7 @@ public function create_multiple_many_to_many_with_nested_collection_relationship TagFactory::assert()->count( \getenv('USE_FOUNDRY_BUNDLE') ? 8 // 6 created by this test and 2 in global state - : 6 + : 6, ); PostFactory::assert()->count(2); } @@ -468,7 +468,7 @@ public function unpersisted_many_to_many_with_nested_collection_relationship(): TagFactory::assert()->count( \getenv('USE_FOUNDRY_BUNDLE') ? 2 // 2 created in global state - : 0 + : 0, ); PostFactory::assert()->empty(); } diff --git a/tests/Functional/ORMRepositoryProxyTest.php b/tests/Functional/ORMRepositoryProxyTest.php index 2a6339fd0..dac3cf85b 100644 --- a/tests/Functional/ORMRepositoryProxyTest.php +++ b/tests/Functional/ORMRepositoryProxyTest.php @@ -81,7 +81,7 @@ public function proxy_repository_can_return_scalars(): void { self::assertSame( [['id' => 1]], - PostFactory::repository()->returnNestedArray() + PostFactory::repository()->returnNestedArray(), ); } diff --git a/tests/Functional/RepositoryProxyTest.php b/tests/Functional/RepositoryProxyTest.php index 37b90c93d..e184f0b64 100644 --- a/tests/Functional/RepositoryProxyTest.php +++ b/tests/Functional/RepositoryProxyTest.php @@ -194,9 +194,9 @@ public function can_find_random_set_of_objects(): void \array_unique( \array_map( static fn($category) => $category->getId(), - $objects - ) - ) + $objects, + ), + ), ); } diff --git a/tests/Functional/WithMigrationTest.php b/tests/Functional/WithMigrationTest.php index fd4eec376..7e555e6e2 100644 --- a/tests/Functional/WithMigrationTest.php +++ b/tests/Functional/WithMigrationTest.php @@ -38,7 +38,7 @@ public function it_can_use_schema_reset_with_migration(): void $validator = new SchemaValidator($kernel->getContainer()->get('doctrine')->getManager()); self::assertEmpty( $validator->validateMapping(), - \implode("\n", \array_map(static fn($s): string => \implode("\n", $s), $validator->validateMapping())) + \implode("\n", \array_map(static fn($s): string => \implode("\n", $s), $validator->validateMapping())), ); self::assertTrue($validator->schemaInSyncWithMetadata()); diff --git a/tests/Unit/Bundle/DependencyInjection/ChainManagerRegistryPassTest.php b/tests/Unit/Bundle/DependencyInjection/ChainManagerRegistryPassTest.php index 59e60f73e..d4dbc2f2f 100644 --- a/tests/Unit/Bundle/DependencyInjection/ChainManagerRegistryPassTest.php +++ b/tests/Unit/Bundle/DependencyInjection/ChainManagerRegistryPassTest.php @@ -34,7 +34,7 @@ public function add_both_odm_and_orm_if_present(): void $this->assertContainerBuilderHasServiceDefinitionWithArgument( '.zenstruck_foundry.chain_manager_registry', '$managerRegistries', - [new Reference('doctrine'), new Reference('doctrine_mongodb')] + [new Reference('doctrine'), new Reference('doctrine_mongodb')], ); } @@ -52,7 +52,7 @@ public function only_add_orm(): void $this->assertContainerBuilderHasServiceDefinitionWithArgument( '.zenstruck_foundry.chain_manager_registry', '$managerRegistries', - [new Reference('doctrine')] + [new Reference('doctrine')], ); } diff --git a/tests/Unit/ChainManagerRegistryTest.php b/tests/Unit/ChainManagerRegistryTest.php index 0317bd4ee..f1c2b20af 100644 --- a/tests/Unit/ChainManagerRegistryTest.php +++ b/tests/Unit/ChainManagerRegistryTest.php @@ -32,7 +32,7 @@ public function can_get_repository(): void $managerRegistry2 = $this->createMock(ManagerRegistry::class); $managerRegistry2->expects($this->once())->method('getRepository')->willReturn( - $repository = $this->createMock(ObjectRepository::class) + $repository = $this->createMock(ObjectRepository::class), ); $chainManagerRegistry = new ChainManagerRegistry([$managerRegistry1, $managerRegistry2]); @@ -69,7 +69,7 @@ public function can_get_manager_from_class(): void $managerRegistry2 = $this->createMock(ManagerRegistry::class); $managerRegistry2->expects($this->once())->method('getManagerForClass')->willReturn( - $objectManager = $this->createMock(ObjectManager::class) + $objectManager = $this->createMock(ObjectManager::class), ); $chainManagerRegistry = new ChainManagerRegistry([$managerRegistry1, $managerRegistry2]); @@ -99,21 +99,21 @@ public function can_get_managers(): void $managerRegistry2 = $this->createMock(ManagerRegistry::class); $managerRegistry1->expects($this->once())->method('getManagers')->willReturn( - [$objectManager1 = $this->createMock(ObjectManager::class)] + [$objectManager1 = $this->createMock(ObjectManager::class)], ); $managerRegistry2->expects($this->once())->method('getManagers')->willReturn( [ $objectManager2 = $this->createMock(ObjectManager::class), $objectManager3 = $this->createMock(ObjectManager::class), - ] + ], ); $chainManagerRegistry = new ChainManagerRegistry([$managerRegistry1, $managerRegistry2]); $this->assertSame( [$objectManager1, $objectManager2, $objectManager3], - $chainManagerRegistry->getManagers() + $chainManagerRegistry->getManagers(), ); } } From cf87b9730977ddf8d9f1ccb88415eab7424d6910 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Mon, 5 Feb 2024 12:26:32 -0500 Subject: [PATCH 04/11] minor: add sqlite to CI (#557) --- .github/workflows/ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9d80ff747..3a45b21ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,8 +46,13 @@ jobs: symfony: '*' database: pgsql use-dama: 0 + - php: 8.2 + deps: highest + symfony: '*' + database: sqlite + use-dama: 0 env: - DATABASE_URL: ${{ contains(matrix.database, 'mysql') && 'mysql://root:root@localhost:3306/foundry?serverVersion=5.7.42' || contains(matrix.database, 'pgsql') && 'postgresql://root:root@localhost:5432/foundry?serverVersion=15' || '' }} + DATABASE_URL: ${{ contains(matrix.database, 'mysql') && 'mysql://root:root@localhost:3306/foundry?serverVersion=5.7.42' || contains(matrix.database, 'pgsql') && 'postgresql://root:root@localhost:5432/foundry?serverVersion=15' || contains(matrix.database, 'sqlite') && 'sqlite:///%kernel.project_dir%/var/data.db' || '' }} MONGO_URL: ${{ contains(matrix.database, 'mongo') && 'mongodb://127.0.0.1:27017/dbName?compressors=disabled&gssapiServiceName=mongodb' || '' }} USE_DAMA_DOCTRINE_TEST_BUNDLE: ${{ matrix.use-dama == 1 && contains(matrix.database, 'sql') && 1 || 0 }} services: From 669bc2ddd6b0f1eb9c094f2ecb2c6cfe29043dca Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Wed, 7 Feb 2024 18:41:16 -0500 Subject: [PATCH 05/11] chore: drop SF 6.3 from matrix (#558) --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a45b21ad..8be704278 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: matrix: php: [ 8.1, 8.2 ] deps: [ highest ] - symfony: [ 6.3.*, 6.4.*, 7.0.* ] + symfony: [ 6.4.*, 7.0.* ] database: [ mysql, mongo ] use-dama: [ 1 ] exclude: @@ -215,7 +215,7 @@ jobs: if: (github.event_name == 'push' || github.event_name == 'schedule') && !startsWith(github.ref, 'refs/tags') && github.repository_owner == 'zenstruck' runs-on: ubuntu-latest steps: - - uses: zenstruck/.github@php-cs-fixer + - uses: zenstruck/.github/actions/php-cs-fixer@main with: php: 8 key: ${{ secrets.GPG_PRIVATE_KEY }} @@ -226,7 +226,7 @@ jobs: if: (github.event_name == 'push' || github.event_name == 'schedule') && !startsWith(github.ref, 'refs/tags') && github.repository_owner == 'zenstruck' runs-on: ubuntu-latest steps: - - uses: zenstruck/.github@sync-with-template + - uses: zenstruck/.github/actions/sync-with-template@main with: key: ${{ secrets.GPG_PRIVATE_KEY }} token: ${{ secrets.COMPOSER_TOKEN }} From 38e24bfaec4aa3990f25da9d2f67e78955915eff Mon Sep 17 00:00:00 2001 From: kbond Date: Fri, 1 Mar 2024 01:02:27 +0000 Subject: [PATCH 06/11] bot: fix cs [skip ci] --- src/Bundle/Maker/Factory/MakeFactoryPHPDocMethod.php | 4 ++-- src/Bundle/Maker/Factory/NamespaceGuesser.php | 2 +- src/Bundle/Maker/Factory/ObjectDefaultPropertiesGuesser.php | 4 ++-- src/Factory.php | 2 +- tests/Fixtures/Kernel.php | 4 ++-- tests/Fixtures/Object/SomeObject.php | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Bundle/Maker/Factory/MakeFactoryPHPDocMethod.php b/src/Bundle/Maker/Factory/MakeFactoryPHPDocMethod.php index 335796cb9..e57e64544 100644 --- a/src/Bundle/Maker/Factory/MakeFactoryPHPDocMethod.php +++ b/src/Bundle/Maker/Factory/MakeFactoryPHPDocMethod.php @@ -16,7 +16,7 @@ */ final class MakeFactoryPHPDocMethod { - public function __construct(private string $objectName, private string $prototype, private bool $returnsCollection, private bool $isStatic = true, private string|null $repository = null) + public function __construct(private string $objectName, private string $prototype, private bool $returnsCollection, private bool $isStatic = true, private ?string $repository = null) { } @@ -52,7 +52,7 @@ public static function createAll(MakeFactoryData $makeFactoryData): array return $methods; } - public function toString(string|null $staticAnalysisTool = null): string + public function toString(?string $staticAnalysisTool = null): string { $annotation = $staticAnalysisTool ? "{$staticAnalysisTool}-method" : 'method'; $static = $this->isStatic ? 'static' : ' '; diff --git a/src/Bundle/Maker/Factory/NamespaceGuesser.php b/src/Bundle/Maker/Factory/NamespaceGuesser.php index 634efca04..f72355383 100644 --- a/src/Bundle/Maker/Factory/NamespaceGuesser.php +++ b/src/Bundle/Maker/Factory/NamespaceGuesser.php @@ -62,7 +62,7 @@ public function __invoke(Generator $generator, string $originalClass, string $ba return $baseNamespace; } - private function namespaceSuffixFromDoctrineMapping(string $originalClass): string|null + private function namespaceSuffixFromDoctrineMapping(string $originalClass): ?string { $originalClassNamespace = Str::getNamespace($originalClass); diff --git a/src/Bundle/Maker/Factory/ObjectDefaultPropertiesGuesser.php b/src/Bundle/Maker/Factory/ObjectDefaultPropertiesGuesser.php index a1ff34f95..f90cf9e07 100644 --- a/src/Bundle/Maker/Factory/ObjectDefaultPropertiesGuesser.php +++ b/src/Bundle/Maker/Factory/ObjectDefaultPropertiesGuesser.php @@ -85,7 +85,7 @@ private function shouldAddPropertyToFactory(MakeFactoryQuery $makeFactoryQuery, return $property->hasType(); } - private function getPropertyType(\ReflectionProperty $property): string|null + private function getPropertyType(\ReflectionProperty $property): ?string { if (!$property->hasType()) { $type = $this->getConstructorParameterForProperty($property)?->getType(); @@ -100,7 +100,7 @@ private function getPropertyType(\ReflectionProperty $property): string|null return $type->getName(); } - private function getConstructorParameterForProperty(\ReflectionProperty $property): \ReflectionParameter|null + private function getConstructorParameterForProperty(\ReflectionProperty $property): ?\ReflectionParameter { if ($constructor = $property->getDeclaringClass()->getConstructor()) { foreach ($constructor->getParameters() as $parameter) { diff --git a/src/Factory.php b/src/Factory.php index 905fba462..ffdb21241 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -447,7 +447,7 @@ private static function normalizeObject(object $object): object * * @return array{cascade: bool, inversedField: ?string, inverseIsCollection: bool, isOwningSide: bool}|null */ - private static function getRelationshipMetadata(EntityManagerInterface $entityManager, string $factoryClass, string $relationshipName): array|null + private static function getRelationshipMetadata(EntityManagerInterface $entityManager, string $factoryClass, string $relationshipName): ?array { $metadata = $entityManager->getClassMetadata($factoryClass); diff --git a/tests/Fixtures/Kernel.php b/tests/Fixtures/Kernel.php index 9991e5aa6..094c804bb 100644 --- a/tests/Fixtures/Kernel.php +++ b/tests/Fixtures/Kernel.php @@ -41,13 +41,13 @@ class Kernel extends BaseKernel private string $ormResetMode = ORMDatabaseResetter::RESET_MODE_SCHEMA; private array $factoriesRegistered = []; - private string|null $defaultMakeFactoryNamespace = null; + private ?string $defaultMakeFactoryNamespace = null; public static function create( bool $enableDoctrine = true, string $ormResetMode = ORMDatabaseResetter::RESET_MODE_SCHEMA, array $factoriesRegistered = [], - string|null $defaultMakeFactoryNamespace = null, + ?string $defaultMakeFactoryNamespace = null, ): self { $kernel = new self('test', true); diff --git a/tests/Fixtures/Object/SomeObject.php b/tests/Fixtures/Object/SomeObject.php index f637f75d4..ed735eb73 100644 --- a/tests/Fixtures/Object/SomeObject.php +++ b/tests/Fixtures/Object/SomeObject.php @@ -17,7 +17,7 @@ final class SomeObject { public $propertyWithoutType; public string $stringMandatory; - public string|null $stringNullable; + public ?string $stringNullable; public string $stringWithDefault = ''; public int $intMandatory; public float $floatMandatory; From f80386831572f290f3f0988d42a98b9a647e6d40 Mon Sep 17 00:00:00 2001 From: Nicolas PHILIPPE Date: Wed, 20 Mar 2024 14:25:22 +0100 Subject: [PATCH 07/11] fix: only run maker test on php > 8.0 (#570) --- tests/Functional/Bundle/Maker/MakeFactoryTest.php | 2 ++ tests/Functional/Bundle/Maker/MakeStoryTest.php | 2 ++ tests/Functional/Bundle/Maker/MakerTestCase.php | 2 ++ 3 files changed, 6 insertions(+) diff --git a/tests/Functional/Bundle/Maker/MakeFactoryTest.php b/tests/Functional/Bundle/Maker/MakeFactoryTest.php index c892d3369..9a39c0a6c 100644 --- a/tests/Functional/Bundle/Maker/MakeFactoryTest.php +++ b/tests/Functional/Bundle/Maker/MakeFactoryTest.php @@ -40,6 +40,8 @@ /** * @author Kevin Bond + * @group maker + * @requires PHP 8.1 */ final class MakeFactoryTest extends MakerTestCase { diff --git a/tests/Functional/Bundle/Maker/MakeStoryTest.php b/tests/Functional/Bundle/Maker/MakeStoryTest.php index 4368043ab..300e58f86 100644 --- a/tests/Functional/Bundle/Maker/MakeStoryTest.php +++ b/tests/Functional/Bundle/Maker/MakeStoryTest.php @@ -16,6 +16,8 @@ /** * @author Kevin Bond + * @group maker + * @requires PHP 8.1 */ final class MakeStoryTest extends MakerTestCase { diff --git a/tests/Functional/Bundle/Maker/MakerTestCase.php b/tests/Functional/Bundle/Maker/MakerTestCase.php index 314f2a4d2..1c737cbbc 100644 --- a/tests/Functional/Bundle/Maker/MakerTestCase.php +++ b/tests/Functional/Bundle/Maker/MakerTestCase.php @@ -17,6 +17,8 @@ /** * @author Kevin Bond + * @group maker + * @requires PHP 8.1 */ abstract class MakerTestCase extends KernelTestCase { From 68148e1946fce6fb40c2316a2bcfd012808b156f Mon Sep 17 00:00:00 2001 From: Jesse Rushlow <40327885+jrushlow@users.noreply.github.com> Date: Wed, 20 Mar 2024 09:26:30 -0400 Subject: [PATCH 08/11] use phpunit attributes (#562) --- src/Test/Factories.php | 4 ++++ src/Test/ResetDatabase.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Test/Factories.php b/src/Test/Factories.php index ca14b3dde..b6d86c19b 100644 --- a/src/Test/Factories.php +++ b/src/Test/Factories.php @@ -11,6 +11,8 @@ namespace Zenstruck\Foundry\Test; +use PHPUnit\Framework\Attributes\After; +use PHPUnit\Framework\Attributes\Before; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Zenstruck\Foundry\ChainManagerRegistry; use Zenstruck\Foundry\Exception\FoundryBootException; @@ -27,6 +29,7 @@ trait Factories * @internal * @before */ + #[Before] public static function _setUpFactories(): void { if (!\is_subclass_of(static::class, KernelTestCase::class)) { @@ -57,6 +60,7 @@ public static function _setUpFactories(): void * @internal * @after */ + #[After] public static function _tearDownFactories(): void { try { diff --git a/src/Test/ResetDatabase.php b/src/Test/ResetDatabase.php index 3c9d87a97..4de28b319 100644 --- a/src/Test/ResetDatabase.php +++ b/src/Test/ResetDatabase.php @@ -12,6 +12,8 @@ namespace Zenstruck\Foundry\Test; use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver; +use PHPUnit\Framework\Attributes\Before; +use PHPUnit\Framework\Attributes\BeforeClass; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\KernelInterface; @@ -28,6 +30,7 @@ trait ResetDatabase * @internal * @beforeClass */ + #[BeforeClass] public static function _resetDatabase(): void { if (!\is_subclass_of(static::class, KernelTestCase::class)) { @@ -65,6 +68,7 @@ public static function _resetDatabase(): void * @internal * @before */ + #[Before] public static function _resetSchema(): void { if (!\is_subclass_of(static::class, KernelTestCase::class)) { From 4a9b00e311a175ae85d53a39c230d73ccb2cd937 Mon Sep 17 00:00:00 2001 From: Nicolas PHILIPPE Date: Wed, 20 Mar 2024 16:06:49 +0100 Subject: [PATCH 09/11] feat: support `doctrine/orm` 3 (#569) --- composer.json | 2 +- phpstan.neon | 4 + ...neScalarFieldsDefaultPropertiesGuesser.php | 27 ++++-- .../FactoryCandidatesClassesExtractor.php | 2 +- src/Bundle/Maker/Factory/FactoryGenerator.php | 2 +- .../LegacyORMDefaultPropertiesGuesser.php | 82 +++++++++++++++++++ .../Factory/ODMDefaultPropertiesGuesser.php | 2 + .../Factory/ORMDefaultPropertiesGuesser.php | 21 +++-- src/Bundle/Resources/config/maker.xml | 7 ++ src/Factory.php | 26 +++++- src/Persistence/DoctrineVersionGuesser.php | 15 ++++ src/Test/ORMDatabaseResetter.php | 32 ++------ tests/Fixtures/Kernel.php | 1 + tests/Functional/ORMModelFactoryTest.php | 2 +- tests/Functional/ORMRepositoryProxyTest.php | 10 ++- tests/bootstrap.php | 5 +- 16 files changed, 191 insertions(+), 49 deletions(-) create mode 100644 src/Bundle/Maker/Factory/LegacyORMDefaultPropertiesGuesser.php create mode 100644 src/Persistence/DoctrineVersionGuesser.php diff --git a/composer.json b/composer.json index 342018cce..efc9b4d85 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "doctrine/doctrine-migrations-bundle": "^2.2|^3.0", "doctrine/mongodb-odm": "^2.4", "doctrine/mongodb-odm-bundle": "^4.4.0|^5.0", - "doctrine/orm": "^2.11", + "doctrine/orm": "^2.11|^3.0", "matthiasnoback/symfony-dependency-injection-test": "^4.1|^5.0", "phpunit/phpunit": "^9.5.0", "symfony/dotenv": "^5.4|^6.0|^7.0", diff --git a/phpstan.neon b/phpstan.neon index fd4a7ef47..aa1efd935 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -34,6 +34,10 @@ parameters: excludePaths: - ./src/Bundle/Resources + # phpstan runs with orm 3 - there are too many failures in these files which are compatible with orm 2 + - ./src/Bundle/Maker/Factory/LegacyORMDefaultPropertiesGuesser.php + - ./src/Bundle/Maker/Factory/DoctrineScalarFieldsDefaultPropertiesGuesser.php + ignoreErrors: - message: '#Unsafe usage of new static\(\).*#' diff --git a/src/Bundle/Maker/Factory/DoctrineScalarFieldsDefaultPropertiesGuesser.php b/src/Bundle/Maker/Factory/DoctrineScalarFieldsDefaultPropertiesGuesser.php index d873f32e0..06835e56c 100644 --- a/src/Bundle/Maker/Factory/DoctrineScalarFieldsDefaultPropertiesGuesser.php +++ b/src/Bundle/Maker/Factory/DoctrineScalarFieldsDefaultPropertiesGuesser.php @@ -12,7 +12,8 @@ namespace Zenstruck\Foundry\Bundle\Maker\Factory; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata as ODMClassMetadata; -use Doctrine\ORM\Mapping\ClassMetadataInfo as ORMClassMetadata; +use Doctrine\ORM\Mapping\ClassMetadata as ORMClassMetadata; +use Doctrine\ORM\Mapping\FieldMapping; use Symfony\Component\Console\Style\SymfonyStyle; /** @@ -56,12 +57,12 @@ public function __invoke(SymfonyStyle $io, MakeFactoryData $makeFactoryData, Mak $ids = $metadata->getIdentifierFieldNames(); foreach ($metadata->fieldMappings as $property) { - if ($property['embedded'] ?? false) { + if (is_array($property) && ($property['embedded'] ?? false)) { // skip ODM embedded continue; } - $fieldName = $property['fieldName']; + $fieldName = $this->extractFieldMappingData($property, 'fieldName'); if (\str_contains($fieldName, '.')) { // this is a "subfield" of an ORM embeddable field. @@ -69,19 +70,19 @@ public function __invoke(SymfonyStyle $io, MakeFactoryData $makeFactoryData, Mak } // ignore identifiers and nullable fields - if ((!$makeFactoryQuery->isAllFields() && ($property['nullable'] ?? false)) || \in_array($fieldName, $ids, true)) { + if ((!$makeFactoryQuery->isAllFields() && $this->extractFieldMappingData($property, 'nullable', false)) || \in_array($fieldName, $ids, true)) { continue; } - $type = \mb_strtoupper($property['type']); - if (isset($property['enumType'])) { - $makeFactoryData->addEnumDefaultProperty($fieldName, $property['enumType']); + $type = \mb_strtoupper($this->extractFieldMappingData($property, 'type')); + if ($this->extractFieldMappingData($property, 'enumType')) { + $makeFactoryData->addEnumDefaultProperty($fieldName, $this->extractFieldMappingData($property, 'enumType')); continue; } $value = "null, // TODO add {$type} type manually"; - $length = $property['length'] ?? ''; + $length = $this->extractFieldMappingData($property, 'length', ''); if (\array_key_exists($type, self::DEFAULTS)) { $value = self::DEFAULTS[$type]; @@ -95,4 +96,14 @@ public function supports(MakeFactoryData $makeFactoryData): bool { return $makeFactoryData->isPersisted(); } + + // handles both ORM 3 & 4 + private function extractFieldMappingData(FieldMapping|array $fieldMapping, string $field, mixed $default = null): mixed + { + if ($fieldMapping instanceof FieldMapping) { + return $fieldMapping->{$field}; + } else { + return $fieldMapping[$field] ?? $default; + } + } } diff --git a/src/Bundle/Maker/Factory/FactoryCandidatesClassesExtractor.php b/src/Bundle/Maker/Factory/FactoryCandidatesClassesExtractor.php index 9ae570c52..6f0ba1893 100644 --- a/src/Bundle/Maker/Factory/FactoryCandidatesClassesExtractor.php +++ b/src/Bundle/Maker/Factory/FactoryCandidatesClassesExtractor.php @@ -11,7 +11,7 @@ namespace Zenstruck\Foundry\Bundle\Maker\Factory; -use Doctrine\ORM\Mapping\ClassMetadataInfo as ORMClassMetadata; +use Doctrine\ORM\Mapping\ClassMetadata as ORMClassMetadata; use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\Mapping\ClassMetadata; use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException; diff --git a/src/Bundle/Maker/Factory/FactoryGenerator.php b/src/Bundle/Maker/Factory/FactoryGenerator.php index c75b7bbd8..f4ed573c1 100644 --- a/src/Bundle/Maker/Factory/FactoryGenerator.php +++ b/src/Bundle/Maker/Factory/FactoryGenerator.php @@ -12,7 +12,7 @@ namespace Zenstruck\Foundry\Bundle\Maker\Factory; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata as ODMClassMetadata; -use Doctrine\ORM\Mapping\ClassMetadataInfo as ORMClassMetadata; +use Doctrine\ORM\Mapping\ClassMetadata as ORMClassMetadata; use Doctrine\Persistence\ManagerRegistry; use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException; use Symfony\Bundle\MakerBundle\Generator; diff --git a/src/Bundle/Maker/Factory/LegacyORMDefaultPropertiesGuesser.php b/src/Bundle/Maker/Factory/LegacyORMDefaultPropertiesGuesser.php new file mode 100644 index 000000000..71f831a74 --- /dev/null +++ b/src/Bundle/Maker/Factory/LegacyORMDefaultPropertiesGuesser.php @@ -0,0 +1,82 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zenstruck\Foundry\Bundle\Maker\Factory; + +use Doctrine\ORM\Mapping\ClassMetadataInfo as ORMClassMetadata; +use Symfony\Component\Console\Style\SymfonyStyle; +use Zenstruck\Foundry\Persistence\DoctrineVersionGuesser; + +/** + * @internal + * @see \Zenstruck\Foundry\Bundle\Maker\Factory\ORMDefaultPropertiesGuesser + * + * This file is basically a copy/paste of ORMDefaultPropertiesGuesser, but offers doctrine/orm 2 compatibility + */ +final class LegacyORMDefaultPropertiesGuesser extends AbstractDoctrineDefaultPropertiesGuesser +{ + public function __invoke(SymfonyStyle $io, MakeFactoryData $makeFactoryData, MakeFactoryQuery $makeFactoryQuery): void + { + if (DoctrineVersionGuesser::isOrmV4()) { + return; + } + + $metadata = $this->getClassMetadata($makeFactoryData); + + if (!$metadata instanceof ORMClassMetadata) { + throw new \InvalidArgumentException("\"{$makeFactoryData->getObjectFullyQualifiedClassName()}\" is not a valid ORM class."); + } + + $this->guessDefaultValueForORMAssociativeFields($io, $makeFactoryData, $makeFactoryQuery, $metadata); + $this->guessDefaultValueForEmbedded($io, $makeFactoryData, $makeFactoryQuery, $metadata); + } + + public function supports(MakeFactoryData $makeFactoryData): bool + { + try { + $metadata = $this->getClassMetadata($makeFactoryData); + + return $metadata instanceof ORMClassMetadata; + } catch (\InvalidArgumentException) { + return false; + } + } + + private function guessDefaultValueForORMAssociativeFields(SymfonyStyle $io, MakeFactoryData $makeFactoryData, MakeFactoryQuery $makeFactoryQuery, ORMClassMetadata $metadata): void + { + foreach ($metadata->associationMappings as $item) { + // if joinColumns is not written entity is default nullable ($nullable = true;) + if (true === ($item['joinColumns'][0]['nullable'] ?? true)) { + continue; + } + + if (isset($item['mappedBy']) || isset($item['joinTable'])) { + // we don't want to add defaults for X-To-Many relationships + continue; + } + + $this->addDefaultValueUsingFactory($io, $makeFactoryData, $makeFactoryQuery, $item['fieldName'], $item['targetEntity']); + } + } + + private function guessDefaultValueForEmbedded(SymfonyStyle $io, MakeFactoryData $makeFactoryData, MakeFactoryQuery $makeFactoryQuery, ORMClassMetadata $metadata): void + { + foreach ($metadata->embeddedClasses as $fieldName => $item) { + $isNullable = $makeFactoryData->getObject()->getProperty($fieldName)->getType()?->allowsNull() ?? true; + + if (!$makeFactoryQuery->isAllFields() && $isNullable) { + continue; + } + + $this->addDefaultValueUsingFactory($io, $makeFactoryData, $makeFactoryQuery, $fieldName, $item['class']); + } + } +} diff --git a/src/Bundle/Maker/Factory/ODMDefaultPropertiesGuesser.php b/src/Bundle/Maker/Factory/ODMDefaultPropertiesGuesser.php index 28d08a18b..aaae1768c 100644 --- a/src/Bundle/Maker/Factory/ODMDefaultPropertiesGuesser.php +++ b/src/Bundle/Maker/Factory/ODMDefaultPropertiesGuesser.php @@ -16,6 +16,8 @@ /** * @internal + * + * @phpstan-import-type AssociationFieldMapping from ODMClassMetadata */ class ODMDefaultPropertiesGuesser extends AbstractDoctrineDefaultPropertiesGuesser { diff --git a/src/Bundle/Maker/Factory/ORMDefaultPropertiesGuesser.php b/src/Bundle/Maker/Factory/ORMDefaultPropertiesGuesser.php index 9b810c259..39fc07db4 100644 --- a/src/Bundle/Maker/Factory/ORMDefaultPropertiesGuesser.php +++ b/src/Bundle/Maker/Factory/ORMDefaultPropertiesGuesser.php @@ -11,16 +11,22 @@ namespace Zenstruck\Foundry\Bundle\Maker\Factory; -use Doctrine\ORM\Mapping\ClassMetadataInfo as ORMClassMetadata; +use Doctrine\ORM\Mapping\ClassMetadata as ORMClassMetadata; +use Doctrine\ORM\Mapping\ToOneAssociationMapping; use Symfony\Component\Console\Style\SymfonyStyle; +use Zenstruck\Foundry\Persistence\DoctrineVersionGuesser; /** * @internal */ -class ORMDefaultPropertiesGuesser extends AbstractDoctrineDefaultPropertiesGuesser +final class ORMDefaultPropertiesGuesser extends AbstractDoctrineDefaultPropertiesGuesser { public function __invoke(SymfonyStyle $io, MakeFactoryData $makeFactoryData, MakeFactoryQuery $makeFactoryQuery): void { + if (!DoctrineVersionGuesser::isOrmV4()) { + return; + } + $metadata = $this->getClassMetadata($makeFactoryData); if (!$metadata instanceof ORMClassMetadata) { @@ -45,17 +51,16 @@ public function supports(MakeFactoryData $makeFactoryData): bool private function guessDefaultValueForORMAssociativeFields(SymfonyStyle $io, MakeFactoryData $makeFactoryData, MakeFactoryQuery $makeFactoryQuery, ORMClassMetadata $metadata): void { foreach ($metadata->associationMappings as $item) { - // if joinColumns is not written entity is default nullable ($nullable = true;) - if (true === ($item['joinColumns'][0]['nullable'] ?? true)) { + if (!$item instanceof ToOneAssociationMapping) { + // we don't want to add defaults for X-To-Many relationships continue; } - if (isset($item['mappedBy']) || isset($item['joinTable'])) { - // we don't want to add defaults for X-To-Many relationships + if ($item->joinColumns[0]->nullable ?? true) { continue; } - $this->addDefaultValueUsingFactory($io, $makeFactoryData, $makeFactoryQuery, $item['fieldName'], $item['targetEntity']); + $this->addDefaultValueUsingFactory($io, $makeFactoryData, $makeFactoryQuery, $item->fieldName, $item->targetEntity); } } @@ -68,7 +73,7 @@ private function guessDefaultValueForEmbedded(SymfonyStyle $io, MakeFactoryData continue; } - $this->addDefaultValueUsingFactory($io, $makeFactoryData, $makeFactoryQuery, $fieldName, $item['class']); + $this->addDefaultValueUsingFactory($io, $makeFactoryData, $makeFactoryQuery, $fieldName, $item->class); } } } diff --git a/src/Bundle/Resources/config/maker.xml b/src/Bundle/Resources/config/maker.xml index 6e2bd98c5..916b91b3b 100644 --- a/src/Bundle/Resources/config/maker.xml +++ b/src/Bundle/Resources/config/maker.xml @@ -20,6 +20,13 @@ + + + + + + + diff --git a/src/Factory.php b/src/Factory.php index ffdb21241..2763a42bb 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -13,7 +13,9 @@ use Doctrine\ODM\MongoDB\Mapping\ClassMetadata as ODMClassMetadata; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Mapping\AssociationMapping; use Doctrine\ORM\Mapping\ClassMetadata as ORMClassMetadata; +use Doctrine\ORM\Mapping\OwningSideMapping; use Faker; use Zenstruck\Foundry\Exception\FoundryBootException; use Zenstruck\Foundry\Persistence\InversedRelationshipPostPersistCallback; @@ -457,10 +459,30 @@ private static function getRelationshipMetadata(EntityManagerInterface $entityMa return null; } + if ($relationshipMetadata instanceof AssociationMapping) { + $inversedField = $relationshipMetadata instanceof OwningSideMapping ? $relationshipMetadata->inversedBy : $relationshipMetadata->mappedBy; + + return [ + 'cascade' => $relationshipMetadata->isCascadePersist(), + 'inversedField' => $inversedField, + 'inverseIsCollection' => $inversedField && $entityManager + ->getClassMetadata($relationshipMetadata->targetEntity) + ->isCollectionValuedAssociation($inversedField), + 'isOwningSide' => $relationshipMetadata->isOwningSide(), + ]; + } + + // doctrine/orm 2 compatibility follows... + + // @phpstan-ignore-next-line + $inversedField = $relationshipMetadata['inversedBy'] ?? $relationshipMetadata['mappedBy'] ?? null; + return [ 'cascade' => $relationshipMetadata['isCascadePersist'], - 'inversedField' => $relationshipMetadata['inversedBy'] ?? $relationshipMetadata['mappedBy'] ?? null, - 'inverseIsCollection' => $entityManager->getClassMetadata($relationshipMetadata['targetEntity'])->isCollectionValuedAssociation($relationshipMetadata['inversedBy'] ?? $relationshipMetadata['mappedBy']), + 'inversedField' => $inversedField, + 'inverseIsCollection' => $inversedField && $entityManager + ->getClassMetadata($relationshipMetadata['targetEntity']) + ->isCollectionValuedAssociation($inversedField), 'isOwningSide' => $relationshipMetadata['isOwningSide'], ]; } diff --git a/src/Persistence/DoctrineVersionGuesser.php b/src/Persistence/DoctrineVersionGuesser.php new file mode 100644 index 000000000..f776dd9b5 --- /dev/null +++ b/src/Persistence/DoctrineVersionGuesser.php @@ -0,0 +1,15 @@ +objectManagersToReset() as $manager) { - $this->runCommand( - $this->application, - 'doctrine:schema:create', - [ - '--em' => $manager, - ], - ); + $this->runCommand($this->application, 'doctrine:schema:create', ['--em' => $manager,]); } } @@ -89,14 +83,7 @@ private function dropSchema(): void } foreach ($this->objectManagersToReset() as $manager) { - $this->runCommand( - $this->application, - 'doctrine:schema:drop', - [ - '--em' => $manager, - '--force' => true, - ], - ); + $this->runCommand($this->application, 'doctrine:schema:drop', ['--em' => $manager, '--force' => true,]); } } @@ -120,20 +107,17 @@ private function dropAndResetDatabase(): void $dropParams = ['--connection' => $connection, '--force' => true]; - if (!$databasePlatform instanceof SqlitePlatform) { + if (!$databasePlatform instanceof SQLitePlatform) { // sqlite does not support "--if-exists" (ref: https://github.com/doctrine/dbal/pull/2402) $dropParams['--if-exists'] = true; } $this->runCommand($this->application, 'doctrine:database:drop', $dropParams); - $this->runCommand( - $this->application, - 'doctrine:database:create', - [ - '--connection' => $connection, - ], - ); + if (!$databasePlatform instanceof SQLitePlatform) { + // d:d:create not supported on SQLite + $this->runCommand($this->application, 'doctrine:database:create', ['--connection' => $connection,]); + } } } diff --git a/tests/Fixtures/Kernel.php b/tests/Fixtures/Kernel.php index 094c804bb..441e97caa 100644 --- a/tests/Fixtures/Kernel.php +++ b/tests/Fixtures/Kernel.php @@ -154,6 +154,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load 'dbal' => [ 'url' => '%env(resolve:DATABASE_URL)%', 'use_savepoints' => true, + 'schema_filter' => '~^(?!(doctrine_migration_versions)$)~' ], 'orm' => [ 'auto_generate_proxy_classes' => true, diff --git a/tests/Functional/ORMModelFactoryTest.php b/tests/Functional/ORMModelFactoryTest.php index d7b144f87..62fa652f4 100644 --- a/tests/Functional/ORMModelFactoryTest.php +++ b/tests/Functional/ORMModelFactoryTest.php @@ -597,7 +597,7 @@ public function can_find_or_create_from_factory_of_embedded_object(): void public function can_find_or_create_from_object(): void { $user = UserFactory::createOne(); - $comment = CommentFactory::findOrCreate($attributes = ['user' => $user->object(), 'createdAt' => new \DateTimeImmutable('2023-01-01')]); + $comment = CommentFactory::findOrCreate($attributes = ['user' => $user->object(), 'createdAt' => new \DateTime('2023-01-01')]); self::assertSame($user->object(), $comment->getUser()); CommentFactory::assert()->count(1); diff --git a/tests/Functional/ORMRepositoryProxyTest.php b/tests/Functional/ORMRepositoryProxyTest.php index dac3cf85b..d1bdd1ecd 100644 --- a/tests/Functional/ORMRepositoryProxyTest.php +++ b/tests/Functional/ORMRepositoryProxyTest.php @@ -11,7 +11,8 @@ namespace Zenstruck\Foundry\Tests\Functional; -use Doctrine\Common\Proxy\Proxy as DoctrineProxy; +use Doctrine\Common\Proxy\Proxy as LegacyDoctrineProxy; +use Doctrine\Persistence\Proxy as DoctrineProxy; use Zenstruck\Foundry\Tests\Fixtures\Entity\Category; use Zenstruck\Foundry\Tests\Fixtures\Entity\Post; use Zenstruck\Foundry\Tests\Fixtures\Factories\CategoryFactory; @@ -58,7 +59,12 @@ public function doctrine_proxies_are_converted_to_foundry_proxies(): void $category = CategoryFactory::random()->object(); // ensure the category is a "doctrine proxy" and a Category - $this->assertInstanceOf(DoctrineProxy::class, $category); + if (interface_exists(DoctrineProxy::class)) { + $this->assertInstanceOf(DoctrineProxy::class, $category); + } else { + $this->assertInstanceOf(LegacyDoctrineProxy::class, $category); + } + $this->assertInstanceOf(Category::class, $category); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 5ef599e38..24acdc59f 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -34,7 +34,10 @@ $application = new Application($kernel); $application->setAutoExit(false); - $application->run(new StringInput('doctrine:database:create --if-not-exists --no-interaction'), new NullOutput()); + if (!str_starts_with(\getenv('DATABASE_URL'), 'sqlite')) { + $application->run(new StringInput('doctrine:database:create --if-not-exists --no-interaction'), new NullOutput()); + } + $application->run(new StringInput('doctrine:schema:drop --force --no-interaction'), new NullOutput()); $application->run(new StringInput('doctrine:migrations:diff --no-interaction'), new NullOutput()); From 5e81f4ed55aee874114c5ccc0e0a76e8c4901564 Mon Sep 17 00:00:00 2001 From: kbond Date: Wed, 20 Mar 2024 15:07:53 +0000 Subject: [PATCH 10/11] bot: fix cs [skip ci] --- .../DoctrineScalarFieldsDefaultPropertiesGuesser.php | 2 +- .../Factory/LegacyORMDefaultPropertiesGuesser.php | 2 +- src/Persistence/DoctrineVersionGuesser.php | 11 ++++++++++- src/Test/ORMDatabaseResetter.php | 6 +++--- tests/Fixtures/Kernel.php | 2 +- tests/Functional/ORMRepositoryProxyTest.php | 2 +- tests/bootstrap.php | 2 +- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/Bundle/Maker/Factory/DoctrineScalarFieldsDefaultPropertiesGuesser.php b/src/Bundle/Maker/Factory/DoctrineScalarFieldsDefaultPropertiesGuesser.php index 06835e56c..fcf70cf5f 100644 --- a/src/Bundle/Maker/Factory/DoctrineScalarFieldsDefaultPropertiesGuesser.php +++ b/src/Bundle/Maker/Factory/DoctrineScalarFieldsDefaultPropertiesGuesser.php @@ -57,7 +57,7 @@ public function __invoke(SymfonyStyle $io, MakeFactoryData $makeFactoryData, Mak $ids = $metadata->getIdentifierFieldNames(); foreach ($metadata->fieldMappings as $property) { - if (is_array($property) && ($property['embedded'] ?? false)) { + if (\is_array($property) && ($property['embedded'] ?? false)) { // skip ODM embedded continue; } diff --git a/src/Bundle/Maker/Factory/LegacyORMDefaultPropertiesGuesser.php b/src/Bundle/Maker/Factory/LegacyORMDefaultPropertiesGuesser.php index 71f831a74..5a055dfa8 100644 --- a/src/Bundle/Maker/Factory/LegacyORMDefaultPropertiesGuesser.php +++ b/src/Bundle/Maker/Factory/LegacyORMDefaultPropertiesGuesser.php @@ -17,7 +17,7 @@ /** * @internal - * @see \Zenstruck\Foundry\Bundle\Maker\Factory\ORMDefaultPropertiesGuesser + * @see ORMDefaultPropertiesGuesser * * This file is basically a copy/paste of ORMDefaultPropertiesGuesser, but offers doctrine/orm 2 compatibility */ diff --git a/src/Persistence/DoctrineVersionGuesser.php b/src/Persistence/DoctrineVersionGuesser.php index f776dd9b5..7606c9b6a 100644 --- a/src/Persistence/DoctrineVersionGuesser.php +++ b/src/Persistence/DoctrineVersionGuesser.php @@ -2,6 +2,15 @@ declare(strict_types=1); +/* + * This file is part of the zenstruck/foundry package. + * + * (c) Kevin Bond + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zenstruck\Foundry\Persistence; use Doctrine\ORM\Mapping\FieldMapping; @@ -10,6 +19,6 @@ final class DoctrineVersionGuesser { public static function isOrmV4(): bool { - return class_exists(FieldMapping::class); + return \class_exists(FieldMapping::class); } } diff --git a/src/Test/ORMDatabaseResetter.php b/src/Test/ORMDatabaseResetter.php index 487dda32e..88bc06b78 100644 --- a/src/Test/ORMDatabaseResetter.php +++ b/src/Test/ORMDatabaseResetter.php @@ -70,7 +70,7 @@ private function createSchema(): void } foreach ($this->objectManagersToReset() as $manager) { - $this->runCommand($this->application, 'doctrine:schema:create', ['--em' => $manager,]); + $this->runCommand($this->application, 'doctrine:schema:create', ['--em' => $manager]); } } @@ -83,7 +83,7 @@ private function dropSchema(): void } foreach ($this->objectManagersToReset() as $manager) { - $this->runCommand($this->application, 'doctrine:schema:drop', ['--em' => $manager, '--force' => true,]); + $this->runCommand($this->application, 'doctrine:schema:drop', ['--em' => $manager, '--force' => true]); } } @@ -116,7 +116,7 @@ private function dropAndResetDatabase(): void if (!$databasePlatform instanceof SQLitePlatform) { // d:d:create not supported on SQLite - $this->runCommand($this->application, 'doctrine:database:create', ['--connection' => $connection,]); + $this->runCommand($this->application, 'doctrine:database:create', ['--connection' => $connection]); } } } diff --git a/tests/Fixtures/Kernel.php b/tests/Fixtures/Kernel.php index 441e97caa..8766e2902 100644 --- a/tests/Fixtures/Kernel.php +++ b/tests/Fixtures/Kernel.php @@ -154,7 +154,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load 'dbal' => [ 'url' => '%env(resolve:DATABASE_URL)%', 'use_savepoints' => true, - 'schema_filter' => '~^(?!(doctrine_migration_versions)$)~' + 'schema_filter' => '~^(?!(doctrine_migration_versions)$)~', ], 'orm' => [ 'auto_generate_proxy_classes' => true, diff --git a/tests/Functional/ORMRepositoryProxyTest.php b/tests/Functional/ORMRepositoryProxyTest.php index d1bdd1ecd..0bbd446f1 100644 --- a/tests/Functional/ORMRepositoryProxyTest.php +++ b/tests/Functional/ORMRepositoryProxyTest.php @@ -59,7 +59,7 @@ public function doctrine_proxies_are_converted_to_foundry_proxies(): void $category = CategoryFactory::random()->object(); // ensure the category is a "doctrine proxy" and a Category - if (interface_exists(DoctrineProxy::class)) { + if (\interface_exists(DoctrineProxy::class)) { $this->assertInstanceOf(DoctrineProxy::class, $category); } else { $this->assertInstanceOf(LegacyDoctrineProxy::class, $category); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 24acdc59f..452a58ef7 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -34,7 +34,7 @@ $application = new Application($kernel); $application->setAutoExit(false); - if (!str_starts_with(\getenv('DATABASE_URL'), 'sqlite')) { + if (!\str_starts_with(\getenv('DATABASE_URL'), 'sqlite')) { $application->run(new StringInput('doctrine:database:create --if-not-exists --no-interaction'), new NullOutput()); } From e01d77f01d2837e568ed92d226e6e778c37319a4 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Wed, 20 Mar 2024 11:09:26 -0400 Subject: [PATCH 11/11] changelog: update [skip ci] --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32587cf6a..b9ef81709 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # CHANGELOG +## [v1.37.0](https://github.com/zenstruck/foundry/releases/tag/v1.37.0) + +March 20th, 2024 - [v1.36.1...v1.37.0](https://github.com/zenstruck/foundry/compare/v1.36.1...v1.37.0) + +* 4a9b00e feat: support `doctrine/orm` 3 (#569) by @nikophil +* 68148e1 use phpunit attributes (#562) by @jrushlow +* f803868 fix: only run maker test on php > 8.0 (#570) by @nikophil +* 669bc2d chore: drop SF 6.3 from matrix (#558) by @kbond +* cf87b97 minor: add sqlite to CI (#557) by @kbond + ## [v1.36.1](https://github.com/zenstruck/foundry/releases/tag/v1.36.1) December 14th, 2023 - [v1.36.0...v1.36.1](https://github.com/zenstruck/foundry/compare/v1.36.0...v1.36.1)