From 6df9ebfc41dcc5e3099b46480f88257f5bac1142 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 24 Jan 2023 15:02:24 +0100 Subject: [PATCH 1/9] Update license years (last time) --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 00837045..0138f8f0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2023 Fabien Potencier +Copyright (c) 2004-present Fabien Potencier 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 0f26987317331abe11b6323b8a8bc91960600d34 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 4 Feb 2023 11:23:10 +0100 Subject: [PATCH 2/9] stop using assertObjectHasAttribute()/assertObjectHasNotAttribute() --- Tests/ManagerRegistryTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tests/ManagerRegistryTest.php b/Tests/ManagerRegistryTest.php index dd7dabcc..e524ebce 100644 --- a/Tests/ManagerRegistryTest.php +++ b/Tests/ManagerRegistryTest.php @@ -44,7 +44,8 @@ public function testResetService() $registry->resetManager(); $this->assertSame($foo, $container->get('foo')); - $this->assertObjectNotHasAttribute('bar', $foo); + $this->assertInstanceOf(\stdClass::class, $foo); + $this->assertFalse(property_exists($foo, 'bar')); } /** From 05ef8c257dc77881654b59445b30b2559c1e66c7 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Sun, 5 Feb 2023 10:12:16 +0100 Subject: [PATCH 3/9] [Tests] Migrate data providers to static ones --- Tests/Form/DoctrineOrmTypeGuesserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Form/DoctrineOrmTypeGuesserTest.php b/Tests/Form/DoctrineOrmTypeGuesserTest.php index 652f9d67..b4ffee55 100644 --- a/Tests/Form/DoctrineOrmTypeGuesserTest.php +++ b/Tests/Form/DoctrineOrmTypeGuesserTest.php @@ -35,7 +35,7 @@ public function testTypeGuesser(string $type, $expected) $this->assertEquals($expected, $this->getGuesser($classMetadata)->guessType('TestEntity', 'field')); } - public function requiredType() + public static function requiredType() { yield [Types::DATE_IMMUTABLE, new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateType', ['input' => 'datetime_immutable'], Guess::HIGH_CONFIDENCE)]; yield [Types::DATE_MUTABLE, new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateType', [], Guess::HIGH_CONFIDENCE)]; From f7e8ed0c1e74617516e6d53854db7e28e1026a66 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 7 Feb 2023 10:31:13 +0100 Subject: [PATCH 4/9] minor #49253 [PHPUnit 10] Use `TestCase` suffix for abstract tests in `/Tests/` (OskarStark) This PR was merged into the 6.3 branch. Discussion ---------- [PHPUnit 10] Use `TestCase` suffix for abstract tests in `/Tests/` | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Refs https://github.com/symfony/symfony/pull/49233 | License | MIT | Doc PR | n/a Replaces #49234 Using `Test` suffix is deprecated since PHPUnit 10 Spotted in * https://github.com/symfony/symfony/pull/49233 Commits ------- cb3db968e4 [PHPUnit 10] Use `TestCase` suffix for abstract tests in `/Tests/` --- Tests/Form/Type/EntityTypeTest.php | 4 ++-- composer.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/Form/Type/EntityTypeTest.php b/Tests/Form/Type/EntityTypeTest.php index 66eccf10..1e71bf68 100644 --- a/Tests/Form/Type/EntityTypeTest.php +++ b/Tests/Form/Type/EntityTypeTest.php @@ -35,12 +35,12 @@ use Symfony\Component\Form\Exception\RuntimeException; use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\Form\Forms; -use Symfony\Component\Form\Tests\Extension\Core\Type\BaseTypeTest; +use Symfony\Component\Form\Tests\Extension\Core\Type\BaseTypeTestCase; use Symfony\Component\Form\Tests\Extension\Core\Type\FormTypeTest; use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; use Symfony\Component\OptionsResolver\Exception\MissingOptionsException; -class EntityTypeTest extends BaseTypeTest +class EntityTypeTest extends BaseTypeTestCase { public const TESTED_TYPE = 'Symfony\Bridge\Doctrine\Form\Type\EntityType'; diff --git a/composer.json b/composer.json index 923ee2da..a0dbbe96 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "symfony/cache": "^5.4|^6.0", "symfony/config": "^4.4|^5.0|^6.0", "symfony/dependency-injection": "^4.4|^5.0|^6.0", - "symfony/form": "^5.4.9|^6.0.9", + "symfony/form": "^5.4.21|^6.2.7", "symfony/http-kernel": "^5.0|^6.0", "symfony/messenger": "^4.4|^5.0|^6.0", "symfony/doctrine-messenger": "^5.1|^6.0", @@ -57,7 +57,7 @@ "phpunit/phpunit": "<5.4.3", "symfony/cache": "<5.4", "symfony/dependency-injection": "<4.4", - "symfony/form": "<5.1", + "symfony/form": "<5.4.21|>=6,<6.2.7", "symfony/http-kernel": "<5", "symfony/messenger": "<4.4", "symfony/property-info": "<5", From f3ad7f8ba997c332a5846ef6007ab9cef63a0fcc Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Tue, 7 Feb 2023 21:09:05 +0100 Subject: [PATCH 5/9] [Tests] Migrate tests to static data providers --- Tests/Form/DoctrineOrmTypeGuesserTest.php | 47 +++++++++++------------ 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/Tests/Form/DoctrineOrmTypeGuesserTest.php b/Tests/Form/DoctrineOrmTypeGuesserTest.php index b4ffee55..f211f291 100644 --- a/Tests/Form/DoctrineOrmTypeGuesserTest.php +++ b/Tests/Form/DoctrineOrmTypeGuesserTest.php @@ -49,66 +49,63 @@ public static function requiredType() yield [Types::DATETIMETZ_MUTABLE, new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateTimeType', [], Guess::HIGH_CONFIDENCE)]; } - /** - * @dataProvider requiredProvider - */ - public function testRequiredGuesser($classMetadata, $expected) - { - $this->assertEquals($expected, $this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field')); - } - - public function requiredProvider() + public function testRequiredGuesserSimpleFieldNotNullable() { - $return = []; - - // Simple field, not nullable $classMetadata = $this->createMock(ClassMetadata::class); $classMetadata->fieldMappings['field'] = true; $classMetadata->expects($this->once())->method('isNullable')->with('field')->willReturn(false); - $return[] = [$classMetadata, new ValueGuess(true, Guess::HIGH_CONFIDENCE)]; + $this->assertEquals(new ValueGuess(true, Guess::HIGH_CONFIDENCE), $this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field')); + } - // Simple field, nullable + public function testRequiredGuesserSimpleFieldNullable() + { $classMetadata = $this->createMock(ClassMetadata::class); $classMetadata->fieldMappings['field'] = true; $classMetadata->expects($this->once())->method('isNullable')->with('field')->willReturn(true); - $return[] = [$classMetadata, new ValueGuess(false, Guess::MEDIUM_CONFIDENCE)]; + $this->assertEquals(new ValueGuess(false, Guess::MEDIUM_CONFIDENCE), $this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field')); + } - // One-to-one, nullable (by default) + public function testRequiredGuesserOneToOneNullable() + { $classMetadata = $this->createMock(ClassMetadata::class); $classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(true); $mapping = ['joinColumns' => [[]]]; $classMetadata->expects($this->once())->method('getAssociationMapping')->with('field')->willReturn($mapping); - $return[] = [$classMetadata, new ValueGuess(false, Guess::HIGH_CONFIDENCE)]; + $this->assertEquals(new ValueGuess(false, Guess::HIGH_CONFIDENCE), $this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field')); + } - // One-to-one, nullable (explicit) + public function testRequiredGuesserOneToOneExplicitNullable() + { $classMetadata = $this->createMock(ClassMetadata::class); $classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(true); $mapping = ['joinColumns' => [['nullable' => true]]]; $classMetadata->expects($this->once())->method('getAssociationMapping')->with('field')->willReturn($mapping); - $return[] = [$classMetadata, new ValueGuess(false, Guess::HIGH_CONFIDENCE)]; + $this->assertEquals(new ValueGuess(false, Guess::HIGH_CONFIDENCE), $this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field')); + } - // One-to-one, not nullable + public function testRequiredGuesserOneToOneNotNullable() + { $classMetadata = $this->createMock(ClassMetadata::class); $classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(true); $mapping = ['joinColumns' => [['nullable' => false]]]; $classMetadata->expects($this->once())->method('getAssociationMapping')->with('field')->willReturn($mapping); - $return[] = [$classMetadata, new ValueGuess(true, Guess::HIGH_CONFIDENCE)]; + $this->assertEquals(new ValueGuess(true, Guess::HIGH_CONFIDENCE), $this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field')); + } - // One-to-many, no clue + public function testRequiredGuesserOneToMany() + { $classMetadata = $this->createMock(ClassMetadata::class); $classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(false); - $return[] = [$classMetadata, null]; - - return $return; + $this->assertNull($this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field')); } private function getGuesser(ClassMetadata $classMetadata) From d0ec59b38d87bcaa4dab5717be98433fa3db58dc Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Wed, 14 Dec 2022 15:42:16 +0100 Subject: [PATCH 6/9] Migrate to `static` data providers using `rector/rector` --- Tests/DataCollector/DoctrineDataCollectorTest.php | 2 +- .../DoctrineDataCollectorWithDebugStackTest.php | 2 +- .../DependencyInjection/DoctrineExtensionTest.php | 6 +++--- .../Form/ChoiceList/ORMQueryBuilderLoaderTest.php | 4 ++-- Tests/Form/Type/EntityTypeTest.php | 2 +- Tests/Logger/DbalLoggerTest.php | 2 +- Tests/Middleware/Debug/MiddlewareTest.php | 6 +++--- Tests/PropertyInfo/DoctrineExtractorTest.php | 2 +- Tests/Types/UlidTypeTest.php | 2 +- Tests/Types/UuidTypeTest.php | 2 +- .../Constraints/UniqueEntityValidatorTest.php | 14 +++++++------- Tests/Validator/DoctrineLoaderTest.php | 2 +- 12 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Tests/DataCollector/DoctrineDataCollectorTest.php b/Tests/DataCollector/DoctrineDataCollectorTest.php index 25cc33fb..8146adb9 100644 --- a/Tests/DataCollector/DoctrineDataCollectorTest.php +++ b/Tests/DataCollector/DoctrineDataCollectorTest.php @@ -134,7 +134,7 @@ public function testSerialization($param, array $types, $expected) $this->assertTrue($collectedQueries['default'][0]['runnable']); } - public function paramProvider(): array + public static function paramProvider(): array { return [ ['some value', [], 'some value'], diff --git a/Tests/DataCollector/DoctrineDataCollectorWithDebugStackTest.php b/Tests/DataCollector/DoctrineDataCollectorWithDebugStackTest.php index f0962eff..64bee120 100644 --- a/Tests/DataCollector/DoctrineDataCollectorWithDebugStackTest.php +++ b/Tests/DataCollector/DoctrineDataCollectorWithDebugStackTest.php @@ -107,7 +107,7 @@ public function testSerialization($param, array $types, $expected, $explainable, $this->assertSame($runnable, $collectedQueries['default'][0]['runnable']); } - public function paramProvider(): array + public static function paramProvider(): array { return [ ['some value', [], 'some value', true], diff --git a/Tests/DependencyInjection/DoctrineExtensionTest.php b/Tests/DependencyInjection/DoctrineExtensionTest.php index b6f415e2..97cec26c 100644 --- a/Tests/DependencyInjection/DoctrineExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineExtensionTest.php @@ -84,7 +84,7 @@ public function testFixManagersAutoMappingsWithTwoAutomappings() $method->invoke($this->extension, $emConfigs, $bundles); } - public function getAutomappingData() + public static function getAutomappingData() { return [ [ @@ -197,7 +197,7 @@ public function testMappingTypeDetection() $this->assertSame($mappingType, \PHP_VERSION_ID < 80000 ? 'annotation' : 'attribute'); } - public function providerBasicDrivers() + public static function providerBasicDrivers() { return [ ['doctrine.orm.cache.apc.class', ['type' => 'apc']], @@ -276,7 +276,7 @@ public function testUnrecognizedCacheDriverException() $this->invokeLoadCacheDriver($objectManager, $container, $cacheName); } - public function providerBundles() + public static function providerBundles() { yield ['AnnotationsBundle', 'annotation', '/Entity']; yield ['AnnotationsOneLineBundle', 'annotation', '/Entity']; diff --git a/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php b/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php index 7d253dc5..50e08323 100644 --- a/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php +++ b/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php @@ -262,7 +262,7 @@ public function testEmbeddedIdentifierName() $loader->getEntitiesByIds('id.value', [1, '', 2, 3, 'foo']); } - public function provideGuidEntityClasses() + public static function provideGuidEntityClasses() { return [ ['Symfony\Bridge\Doctrine\Tests\Fixtures\GuidIdEntity'], @@ -270,7 +270,7 @@ public function provideGuidEntityClasses() ]; } - public function provideUidEntityClasses() + public static function provideUidEntityClasses() { return [ ['Symfony\Bridge\Doctrine\Tests\Fixtures\UuidIdEntity'], diff --git a/Tests/Form/Type/EntityTypeTest.php b/Tests/Form/Type/EntityTypeTest.php index 1e71bf68..d8491588 100644 --- a/Tests/Form/Type/EntityTypeTest.php +++ b/Tests/Form/Type/EntityTypeTest.php @@ -158,7 +158,7 @@ public function testChoiceTranslationDomainIsDisabledByDefault($expanded) } } - public function choiceTranslationDomainProvider() + public static function choiceTranslationDomainProvider() { return [ [false], diff --git a/Tests/Logger/DbalLoggerTest.php b/Tests/Logger/DbalLoggerTest.php index 710e87a1..91061632 100644 --- a/Tests/Logger/DbalLoggerTest.php +++ b/Tests/Logger/DbalLoggerTest.php @@ -43,7 +43,7 @@ public function testLog($sql, $params, $logParams) $dbalLogger->startQuery($sql, $params); } - public function getLogFixtures() + public static function getLogFixtures() { return [ ['SQL', null, []], diff --git a/Tests/Middleware/Debug/MiddlewareTest.php b/Tests/Middleware/Debug/MiddlewareTest.php index 2b8a25b4..3e24f83f 100644 --- a/Tests/Middleware/Debug/MiddlewareTest.php +++ b/Tests/Middleware/Debug/MiddlewareTest.php @@ -79,7 +79,7 @@ private function getResourceFromString(string $str) return $res; } - public function provideExecuteMethod(): array + public static function provideExecuteMethod(): array { return [ 'executeStatement' => [ @@ -173,7 +173,7 @@ public function testWithParamBound(callable $executeMethod) $this->assertGreaterThan(0, $debug[1]['executionMS']); } - public function provideEndTransactionMethod(): array + public static function provideEndTransactionMethod(): array { return [ 'commit' => [ @@ -223,7 +223,7 @@ public function testTransaction(callable $endTransactionMethod, string $expected $this->assertGreaterThan(0, $debug[6]['executionMS']); } - public function provideExecuteAndEndTransactionMethods(): array + public static function provideExecuteAndEndTransactionMethods(): array { return [ 'commit and exec' => [ diff --git a/Tests/PropertyInfo/DoctrineExtractorTest.php b/Tests/PropertyInfo/DoctrineExtractorTest.php index 42a8d656..bbe4b6ab 100644 --- a/Tests/PropertyInfo/DoctrineExtractorTest.php +++ b/Tests/PropertyInfo/DoctrineExtractorTest.php @@ -146,7 +146,7 @@ public function testExtractEnum() $this->assertNull($this->createExtractor()->getTypes(DoctrineEnum::class, 'enumCustom', [])); } - public function typesProvider() + public static function typesProvider() { $provider = [ ['id', [new Type(Type::BUILTIN_TYPE_INT)]], diff --git a/Tests/Types/UlidTypeTest.php b/Tests/Types/UlidTypeTest.php index 8fd4b8b0..06114aee 100644 --- a/Tests/Types/UlidTypeTest.php +++ b/Tests/Types/UlidTypeTest.php @@ -140,7 +140,7 @@ public function testGetGuidTypeDeclarationSQL(AbstractPlatform $platform, string $this->assertEquals($expectedDeclaration, $this->type->getSqlDeclaration(['length' => 36], $platform)); } - public function provideSqlDeclarations(): array + public static function provideSqlDeclarations(): array { return [ [new PostgreSQLPlatform(), 'UUID'], diff --git a/Tests/Types/UuidTypeTest.php b/Tests/Types/UuidTypeTest.php index 9b904b89..d49afc5f 100644 --- a/Tests/Types/UuidTypeTest.php +++ b/Tests/Types/UuidTypeTest.php @@ -152,7 +152,7 @@ public function testGetGuidTypeDeclarationSQL(AbstractPlatform $platform, string $this->assertEquals($expectedDeclaration, $this->type->getSqlDeclaration(['length' => 36], $platform)); } - public function provideSqlDeclarations(): array + public static function provideSqlDeclarations(): array { return [ [new PostgreSQLPlatform(), 'UUID'], diff --git a/Tests/Validator/Constraints/UniqueEntityValidatorTest.php b/Tests/Validator/Constraints/UniqueEntityValidatorTest.php index 78d8ae01..a4e92843 100644 --- a/Tests/Validator/Constraints/UniqueEntityValidatorTest.php +++ b/Tests/Validator/Constraints/UniqueEntityValidatorTest.php @@ -186,7 +186,7 @@ public function testValidateUniqueness(UniqueEntity $constraint) ->assertRaised(); } - public function provideUniquenessConstraints(): iterable + public static function provideUniquenessConstraints(): iterable { yield 'Doctrine style' => [new UniqueEntity([ 'message' => 'myMessage', @@ -221,7 +221,7 @@ public function testValidateCustomErrorPath(UniqueEntity $constraint) ->assertRaised(); } - public function provideConstraintsWithCustomErrorPath(): iterable + public static function provideConstraintsWithCustomErrorPath(): iterable { yield 'Doctrine style' => [new UniqueEntity([ 'message' => 'myMessage', @@ -282,7 +282,7 @@ public function testValidateUniquenessWithIgnoreNullDisabled(UniqueEntity $const ->assertRaised(); } - public function provideConstraintsWithIgnoreNullDisabled(): iterable + public static function provideConstraintsWithIgnoreNullDisabled(): iterable { yield 'Doctrine style' => [new UniqueEntity([ 'message' => 'myMessage', @@ -331,7 +331,7 @@ public function testNoValidationIfFirstFieldIsNullAndNullValuesAreIgnored(Unique $this->assertNoViolation(); } - public function provideConstraintsWithIgnoreNullEnabled(): iterable + public static function provideConstraintsWithIgnoreNullEnabled(): iterable { yield 'Doctrine style' => [new UniqueEntity([ 'message' => 'myMessage', @@ -432,7 +432,7 @@ function () use ($entity) { $this->assertNoViolation(); } - public function provideConstraintsWithCustomRepositoryMethod(): iterable + public static function provideConstraintsWithCustomRepositoryMethod(): iterable { yield 'Doctrine style' => [new UniqueEntity([ 'message' => 'myMessage', @@ -473,7 +473,7 @@ public function testValidateResultTypes($entity1, $result) $this->assertNoViolation(); } - public function resultTypesProvider() + public static function resultTypesProvider() { $entity = new SingleIntIdEntity(1, 'foo'); @@ -886,7 +886,7 @@ public function testValueCanBeNull() $this->assertNoViolation(); } - public function resultWithEmptyIterator(): array + public static function resultWithEmptyIterator(): array { $entity = new SingleIntIdEntity(1, 'foo'); diff --git a/Tests/Validator/DoctrineLoaderTest.php b/Tests/Validator/DoctrineLoaderTest.php index 034cd001..a72e78f6 100644 --- a/Tests/Validator/DoctrineLoaderTest.php +++ b/Tests/Validator/DoctrineLoaderTest.php @@ -209,7 +209,7 @@ public function testClassValidator(bool $expected, string $classValidatorRegexp $this->assertSame($expected, $doctrineLoader->loadClassMetadata($classMetadata)); } - public function regexpProvider() + public static function regexpProvider() { return [ [false, null], From decc4801e2ecc4b72334ef472ed82e4d640492ec Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Mon, 6 Mar 2023 21:48:01 +0100 Subject: [PATCH 7/9] [Tests] Replace `setMethods()` by `onlyMethods()` and `addMethods()` --- .../DoctrineExtensionTest.php | 2 +- .../ChoiceList/ORMQueryBuilderLoaderTest.php | 55 +++++++++++++------ Tests/Logger/DbalLoggerTest.php | 10 ++-- .../Security/User/EntityUserProviderTest.php | 2 +- .../Constraints/UniqueEntityValidatorTest.php | 3 +- 5 files changed, 48 insertions(+), 24 deletions(-) diff --git a/Tests/DependencyInjection/DoctrineExtensionTest.php b/Tests/DependencyInjection/DoctrineExtensionTest.php index 97cec26c..a8480481 100644 --- a/Tests/DependencyInjection/DoctrineExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineExtensionTest.php @@ -34,7 +34,7 @@ protected function setUp(): void $this->extension = $this ->getMockBuilder(AbstractDoctrineExtension::class) - ->setMethods([ + ->onlyMethods([ 'getMappingResourceConfigDirectory', 'getObjectManagerElementName', 'getMappingObjectDefaultName', diff --git a/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php b/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php index 50e08323..10c73ca3 100644 --- a/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php +++ b/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php @@ -12,8 +12,10 @@ namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Result; use Doctrine\DBAL\Types\GuidType; use Doctrine\DBAL\Types\Type; +use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\Version; use PHPUnit\Framework\TestCase; use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader; @@ -46,8 +48,8 @@ protected function checkIdentifierType($classname, $expectedType) { $em = DoctrineTestHelper::createTestEntityManager(); - $query = $this->getMockBuilder(\QueryMock::class) - ->setMethods(['setParameter', 'getResult', 'getSql', '_doExecute']) + $query = $this->getMockBuilder(QueryMock::class) + ->onlyMethods(['setParameter', 'getResult', 'getSql', '_doExecute']) ->getMock(); $query @@ -61,7 +63,7 @@ protected function checkIdentifierType($classname, $expectedType) $qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class) ->setConstructorArgs([$em]) - ->setMethods(['getQuery']) + ->onlyMethods(['getQuery']) ->getMock(); $qb->expects($this->once()) @@ -79,8 +81,8 @@ public function testFilterNonIntegerValues() { $em = DoctrineTestHelper::createTestEntityManager(); - $query = $this->getMockBuilder(\QueryMock::class) - ->setMethods(['setParameter', 'getResult', 'getSql', '_doExecute']) + $query = $this->getMockBuilder(QueryMock::class) + ->onlyMethods(['setParameter', 'getResult', 'getSql', '_doExecute']) ->getMock(); $query @@ -94,7 +96,7 @@ public function testFilterNonIntegerValues() $qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class) ->setConstructorArgs([$em]) - ->setMethods(['getQuery']) + ->onlyMethods(['getQuery']) ->getMock(); $qb->expects($this->once()) @@ -115,8 +117,8 @@ public function testFilterEmptyUuids($entityClass) { $em = DoctrineTestHelper::createTestEntityManager(); - $query = $this->getMockBuilder(\QueryMock::class) - ->setMethods(['setParameter', 'getResult', 'getSql', '_doExecute']) + $query = $this->getMockBuilder(QueryMock::class) + ->onlyMethods(['setParameter', 'getResult', 'getSql', '_doExecute']) ->getMock(); $query @@ -130,7 +132,7 @@ public function testFilterEmptyUuids($entityClass) $qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class) ->setConstructorArgs([$em]) - ->setMethods(['getQuery']) + ->onlyMethods(['getQuery']) ->getMock(); $qb->expects($this->once()) @@ -160,8 +162,8 @@ public function testFilterUid($entityClass) $em = DoctrineTestHelper::createTestEntityManager(); - $query = $this->getMockBuilder(\QueryMock::class) - ->setMethods(['setParameter', 'getResult', 'getSql', '_doExecute']) + $query = $this->getMockBuilder(QueryMock::class) + ->onlyMethods(['setParameter', 'getResult', 'getSql', '_doExecute']) ->getMock(); $query @@ -175,7 +177,7 @@ public function testFilterUid($entityClass) $qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class) ->setConstructorArgs([$em]) - ->setMethods(['getQuery']) + ->onlyMethods(['getQuery']) ->getMock(); $qb->expects($this->once()) @@ -207,7 +209,7 @@ public function testUidThrowProperException($entityClass) $qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class) ->setConstructorArgs([$em]) - ->setMethods(['getQuery']) + ->onlyMethods(['getQuery']) ->getMock(); $qb->expects($this->never()) @@ -234,8 +236,8 @@ public function testEmbeddedIdentifierName() $em = DoctrineTestHelper::createTestEntityManager(); - $query = $this->getMockBuilder(\QueryMock::class) - ->setMethods(['setParameter', 'getResult', 'getSql', '_doExecute']) + $query = $this->getMockBuilder(QueryMock::class) + ->onlyMethods(['setParameter', 'getResult', 'getSql', '_doExecute']) ->getMock(); $query @@ -249,7 +251,7 @@ public function testEmbeddedIdentifierName() $qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class) ->setConstructorArgs([$em]) - ->setMethods(['getQuery']) + ->onlyMethods(['getQuery']) ->getMock(); $qb->expects($this->once()) ->method('getQuery') @@ -278,3 +280,24 @@ public static function provideUidEntityClasses() ]; } } + +class QueryMock extends AbstractQuery +{ + public function __construct() + { + } + + /** + * @return array|string + */ + public function getSQL() + { + } + + /** + * @return Result|int + */ + protected function _doExecute() + { + } +} diff --git a/Tests/Logger/DbalLoggerTest.php b/Tests/Logger/DbalLoggerTest.php index 91061632..2e9ed80e 100644 --- a/Tests/Logger/DbalLoggerTest.php +++ b/Tests/Logger/DbalLoggerTest.php @@ -30,7 +30,7 @@ public function testLog($sql, $params, $logParams) $dbalLogger = $this ->getMockBuilder(DbalLogger::class) ->setConstructorArgs([$logger, null]) - ->setMethods(['log']) + ->onlyMethods(['log']) ->getMock() ; @@ -62,7 +62,7 @@ public function testLogNonUtf8() $dbalLogger = $this ->getMockBuilder(DbalLogger::class) ->setConstructorArgs([$logger, null]) - ->setMethods(['log']) + ->onlyMethods(['log']) ->getMock() ; @@ -85,7 +85,7 @@ public function testLogNonUtf8Array() $dbalLogger = $this ->getMockBuilder(DbalLogger::class) ->setConstructorArgs([$logger, null]) - ->setMethods(['log']) + ->onlyMethods(['log']) ->getMock() ; @@ -116,7 +116,7 @@ public function testLogLongString() $dbalLogger = $this ->getMockBuilder(DbalLogger::class) ->setConstructorArgs([$logger, null]) - ->setMethods(['log']) + ->onlyMethods(['log']) ->getMock() ; @@ -144,7 +144,7 @@ public function testLogUTF8LongString() $dbalLogger = $this ->getMockBuilder(DbalLogger::class) ->setConstructorArgs([$logger, null]) - ->setMethods(['log']) + ->onlyMethods(['log']) ->getMock() ; diff --git a/Tests/Security/User/EntityUserProviderTest.php b/Tests/Security/User/EntityUserProviderTest.php index 20d1e487..7a09cb88 100644 --- a/Tests/Security/User/EntityUserProviderTest.php +++ b/Tests/Security/User/EntityUserProviderTest.php @@ -211,7 +211,7 @@ private function getManager($em, $name = null) private function getObjectManager($repository) { $em = $this->getMockBuilder(ObjectManager::class) - ->setMethods(['getClassMetadata', 'getRepository']) + ->onlyMethods(['getClassMetadata', 'getRepository']) ->getMockForAbstractClass(); $em->expects($this->any()) ->method('getRepository') diff --git a/Tests/Validator/Constraints/UniqueEntityValidatorTest.php b/Tests/Validator/Constraints/UniqueEntityValidatorTest.php index a4e92843..14f60165 100644 --- a/Tests/Validator/Constraints/UniqueEntityValidatorTest.php +++ b/Tests/Validator/Constraints/UniqueEntityValidatorTest.php @@ -96,7 +96,8 @@ protected function createRegistryMock($em = null) protected function createRepositoryMock() { $repository = $this->getMockBuilder(ObjectRepository::class) - ->setMethods(['findByCustom', 'find', 'findAll', 'findOneBy', 'findBy', 'getClassName']) + ->onlyMethods(['find', 'findAll', 'findOneBy', 'findBy', 'getClassName']) + ->addMethods(['findByCustom']) ->getMock() ; From 32cddf41cf6abfc4c3db68568c785e48eebf3d71 Mon Sep 17 00:00:00 2001 From: David Maicher Date: Mon, 23 Jan 2023 17:35:46 +0100 Subject: [PATCH 8/9] [DoctrineBridge] fix issue with missing stopwatch events --- Middleware/Debug/Connection.php | 3 ++- Middleware/Debug/Statement.php | 13 ++++++++++++- Tests/Middleware/Debug/MiddlewareTest.php | 12 ++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Middleware/Debug/Connection.php b/Middleware/Debug/Connection.php index d085b0af..e768407b 100644 --- a/Middleware/Debug/Connection.php +++ b/Middleware/Debug/Connection.php @@ -44,7 +44,8 @@ public function prepare(string $sql): DriverStatement parent::prepare($sql), $this->debugDataHolder, $this->connectionName, - $sql + $sql, + $this->stopwatch, ); } diff --git a/Middleware/Debug/Statement.php b/Middleware/Debug/Statement.php index e52530e9..a40cdaa9 100644 --- a/Middleware/Debug/Statement.php +++ b/Middleware/Debug/Statement.php @@ -15,6 +15,7 @@ use Doctrine\DBAL\Driver\Result as ResultInterface; use Doctrine\DBAL\Driver\Statement as StatementInterface; use Doctrine\DBAL\ParameterType; +use Symfony\Component\Stopwatch\Stopwatch; /** * @author Laurent VOULLEMIER @@ -26,14 +27,16 @@ final class Statement extends AbstractStatementMiddleware private $debugDataHolder; private $connectionName; private $query; + private $stopwatch; - public function __construct(StatementInterface $statement, DebugDataHolder $debugDataHolder, string $connectionName, string $sql) + public function __construct(StatementInterface $statement, DebugDataHolder $debugDataHolder, string $connectionName, string $sql, Stopwatch $stopwatch = null) { parent::__construct($statement); $this->debugDataHolder = $debugDataHolder; $this->connectionName = $connectionName; $this->query = new Query($sql); + $this->stopwatch = $stopwatch; } public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null): bool @@ -59,12 +62,20 @@ public function execute($params = null): ResultInterface // clone to prevent variables by reference to change $this->debugDataHolder->addQuery($this->connectionName, $query = clone $this->query); + if ($this->stopwatch) { + $this->stopwatch->start('doctrine', 'doctrine'); + } + $query->start(); try { $result = parent::execute($params); } finally { $query->stop(); + + if ($this->stopwatch) { + $this->stopwatch->stop('doctrine'); + } } return $result; diff --git a/Tests/Middleware/Debug/MiddlewareTest.php b/Tests/Middleware/Debug/MiddlewareTest.php index 3e24f83f..9b71bb8a 100644 --- a/Tests/Middleware/Debug/MiddlewareTest.php +++ b/Tests/Middleware/Debug/MiddlewareTest.php @@ -161,10 +161,6 @@ public function testWithParamBound(callable $executeMethod) $executeMethod($stmt); // Debug data should not be affected by these changes - $product = 'product2'; - $price = 13.5; - $stock = 4; - $debug = $this->debugDataHolder->getData()['default'] ?? []; $this->assertCount(2, $debug); $this->assertSame('INSERT INTO products(name, price, stock) VALUES (?, ?, ?)', $debug[1]['sql']); @@ -242,6 +238,14 @@ static function (Connection $conn): bool { return $conn->rollBack(); }, ], + 'prepared statement' => [ + static function (Connection $conn, string $sql): Result { + return $conn->prepare($sql)->executeQuery(); + }, + static function (Connection $conn): bool { + return $conn->commit(); + }, + ], ]; } From 4b3aeaa90d41c5527d7ba211d12102cedf06936e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 11 Apr 2023 18:08:35 +0200 Subject: [PATCH 9/9] fix merge --- Tests/Middleware/Debug/MiddlewareTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/Middleware/Debug/MiddlewareTest.php b/Tests/Middleware/Debug/MiddlewareTest.php index 833d389b..e605afec 100644 --- a/Tests/Middleware/Debug/MiddlewareTest.php +++ b/Tests/Middleware/Debug/MiddlewareTest.php @@ -16,6 +16,7 @@ use Doctrine\DBAL\Driver\Middleware as MiddlewareInterface; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\ParameterType; +use Doctrine\DBAL\Result; use Doctrine\DBAL\Statement; use Doctrine\DBAL\Types\Types; use PHPUnit\Framework\TestCase;