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() ;