From 09bfcf33c419cc5f4c5fefff80868b7f3a6e8d59 Mon Sep 17 00:00:00 2001 From: Dennis Riehle Date: Sun, 29 Dec 2024 17:15:50 +0100 Subject: [PATCH 1/2] updated docs regarding caching --- docs/en/caching.rst | 104 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 88 insertions(+), 16 deletions(-) diff --git a/docs/en/caching.rst b/docs/en/caching.rst index cded6d45..a6b56095 100644 --- a/docs/en/caching.rst +++ b/docs/en/caching.rst @@ -1,27 +1,99 @@ Caching ======= -DoctrineModule provides bridging between -`Laminas\Cache `__ and -`Doctrine\Common\Cache `__. -This may be useful in case you want to share configured cache instances -across doctrine, symfony and laminas projects. +DoctrineModule provides some pre-configured caches using +`Laminas\Cache `__, which can be utilized +by either Doctrine ORM or Doctrine ODM. -You may use ``Laminas\Cache`` within your doctrine-related projects as -following: +The following caches are available by default: + +In-Memory +~~~~~~~~~ + +Provided by ``laminas/laminas-cache-storage-adapter-memory``, you can pull this cache from +the container under the key ``doctrine.cache.array``. It does not really do any caching and +suits merely as a proof of concept or for cases, where you do not want to have caching. + +Filesystem +~~~~~~~~~~ + +Provided by ``laminas/laminas-cache-storage-adapter-filesystem``, you can pull this cache from +the container under the key ``doctrine.cache.filesystem``. To override the location for the +cache storage folder, use the following configuration: + +.. code:: php + return [ + 'caches' => [ + 'doctrinemodule.cache.filesystem' => [ + 'options' => [ + 'cache_dir' => './data/cache/', + ], + ], + ], + ]; + +APCu +~~~~ + +This cache requires the additional package ``laminas/laminas-cache-storage-adapter-apcu``, which +is not installed by default. + +You can pull the cache from the container using the key ``doctrine.cache.apcu``. To pass additional +arguments for configuration, use the following config: .. code:: php + return [ + 'caches' => [ + 'doctrinemodule.cache.apcu' => [ + 'options' => [ + + ], + ], + ], + ]; - $laminasCache = new \Laminas\Cache\Storage\Adapter\Memory(); // any storage adapter is OK here - $doctrineCache = new \DoctrineModule\Cache\LaminasStorageCache($laminasCache); - // now use $doctrineCache as a normal Doctrine\Common\Cache\Cache instance +Memcached +~~~~~~~~~ -You may use ``Doctrine\Common\Cache`` within your Laminas projects as -following: +This cache requires the additional package ``laminas/laminas-cache-storage-adapter-memcached``, which +is not installed by default. + +You can pull the cache from the container using the key ``doctrine.cache.memcached``. To pass additional +arguments for configuration, use the following config: .. code:: php + return [ + 'caches' => [ + 'doctrinemodule.cache.memcached' => [ + 'options' => [ + 'servers' => [ + + ], + ], + ], + ], + ]; - $doctrineCache = new \Doctrine\Common\Cache\ArrayCache(); // any doctrine cache is OK here - $adapterOptions = new \Laminas\Cache\Storage\Adapter\AdapterOptions(); - $laminasCacheStorage = new \DoctrineModule\Cache\DoctrineCacheStorage($adapterOptions, $doctrineCache); - // now use $laminasCacheStorage as a normal Laminas\Cache\Storage\StorageInterface instance. +Redis +~~~~~~~~~ + +This cache requires the additional package ``laminas/laminas-cache-storage-adapter-redis``, which +is not installed by default. + +You can pull the cache from the container using the key ``doctrine.cache.redis``. The default config +will access a Redis server at localhost, port 6379. To pass additional arguments for configuration, +or to change the default config, use the following config: + +.. code:: php + return [ + 'caches' => [ + 'doctrinemodule.cache.redis' => [ + 'options' => [ + 'server' => [ + 'host' => 'localhost', + 'post' => 6379, + ], + ], + ], + ], + ]; From 4261946a1b095b4310b3a01d8b1cd7fc716b5429 Mon Sep 17 00:00:00 2001 From: Dennis Riehle Date: Sun, 29 Dec 2024 17:16:12 +0100 Subject: [PATCH 2/2] updated deprecated code in unit tests --- .../Adapter/ObjectRepositoryTest.php | 18 ++--- .../Storage/ObjectRepositoryTest.php | 4 +- .../Form/Element/ObjectMultiCheckboxTest.php | 4 +- tests/Form/Element/ObjectRadioTest.php | 4 +- tests/Form/Element/ObjectSelectTest.php | 4 +- .../Element/ProxyAwareElementTestCase.php | 6 +- tests/Form/Element/ProxyTest.php | 60 ++++++++-------- tests/ModuleTest.php | 6 +- .../Adapter/SelectableAdapterTest.php | 10 +-- tests/Validator/NoObjectExistsTest.php | 6 +- tests/Validator/ObjectExistsTest.php | 8 +-- tests/Validator/UniqueObjectTest.php | 68 +++++++++---------- 12 files changed, 99 insertions(+), 99 deletions(-) diff --git a/tests/Authentication/Adapter/ObjectRepositoryTest.php b/tests/Authentication/Adapter/ObjectRepositoryTest.php index 2f7cd622..25502e50 100644 --- a/tests/Authentication/Adapter/ObjectRepositoryTest.php +++ b/tests/Authentication/Adapter/ObjectRepositoryTest.php @@ -110,13 +110,13 @@ public function testAuthentication(): void ->expects($this->exactly(2)) ->method('findOneBy') ->with($this->equalTo(['username' => 'a username'])) - ->will($this->returnValue($entity)); + ->willReturn($entity); $objectManager = $this->createMock(ObjectManager::class); $objectManager->expects($this->exactly(2)) ->method('getRepository') ->with($this->equalTo(IdentityObject::class)) - ->will($this->returnValue($objectRepository)); + ->willReturn($objectRepository); $adapter = new ObjectRepositoryAdapter(); $adapter->setOptions([ @@ -138,7 +138,7 @@ public function testAuthentication(): void $result->getIdentity(), ); - $method->will($this->returnValue(null)); + $method->willReturn(null); $result = $adapter->authenticate(); @@ -156,7 +156,7 @@ public function testAuthenticationWithPublicProperties(): void ->expects($this->exactly(2)) ->method('findOneBy') ->with($this->equalTo(['username' => 'a username'])) - ->will($this->returnValue($entity)); + ->willReturn($entity); $adapter = new ObjectRepositoryAdapter(); $adapter->setOptions([ @@ -173,7 +173,7 @@ public function testAuthenticationWithPublicProperties(): void $this->assertTrue($result->isValid()); - $method->will($this->returnValue(null)); + $method->willReturn(null); $result = $adapter->authenticate(); @@ -189,7 +189,7 @@ public function testWillRefuseToAuthenticateWithoutGettersOrPublicMethods(): voi ->expects($this->once()) ->method('findOneBy') ->with($this->equalTo(['username' => 'a username'])) - ->will($this->returnValue(new stdClass())); + ->willReturn(new stdClass()); $adapter = new ObjectRepositoryAdapter(); $adapter->setOptions([ @@ -216,7 +216,7 @@ public function testCanValidateWithSpecialCrypt(): void ->expects($this->exactly(2)) ->method('findOneBy') ->with($this->equalTo(['username' => 'username'])) - ->will($this->returnValue($entity)); + ->willReturn($entity); $adapter = new ObjectRepositoryAdapter(); $adapter->setOptions([ @@ -249,7 +249,7 @@ public function testWillRefuseToAuthenticateWhenInvalidInstanceIsFound(): void ->expects($this->once()) ->method('findOneBy') ->with($this->equalTo(['username' => 'a username'])) - ->will($this->returnValue(new stdClass())); + ->willReturn(new stdClass()); $adapter = new ObjectRepositoryAdapter(); $adapter->setOptions([ @@ -283,7 +283,7 @@ public function testWillNotCastAuthCredentialValue(): void ->expects($this->once()) ->method('findOneBy') ->with($this->equalTo(['username' => 'a username'])) - ->will($this->returnValue($entity)); + ->willReturn($entity); $this->assertFalse($adapter->authenticate()->isValid()); } diff --git a/tests/Authentication/Storage/ObjectRepositoryTest.php b/tests/Authentication/Storage/ObjectRepositoryTest.php index 6047e47d..94ab7340 100644 --- a/tests/Authentication/Storage/ObjectRepositoryTest.php +++ b/tests/Authentication/Storage/ObjectRepositoryTest.php @@ -27,13 +27,13 @@ public function testCanRetrieveEntityFromObjectRepositoryStorage(): void $objectRepository->expects($this->exactly(1)) ->method('find') ->with($this->equalTo('a username')) - ->will($this->returnValue($entity)); + ->willReturn($entity); $metadata = $this->createMock(ClassMetadata::class); $metadata->expects($this->exactly(1)) ->method('getIdentifierValues') ->with($this->equalTo($entity)) - ->will($this->returnValue($entity->getUsername())); + ->willReturn($entity->getUsername()); $storage = new ObjectRepositoryStorage([ 'objectRepository' => $objectRepository, diff --git a/tests/Form/Element/ObjectMultiCheckboxTest.php b/tests/Form/Element/ObjectMultiCheckboxTest.php index 23f39ae2..21a484f1 100644 --- a/tests/Form/Element/ObjectMultiCheckboxTest.php +++ b/tests/Form/Element/ObjectMultiCheckboxTest.php @@ -63,7 +63,7 @@ public function testGetValueOptionsDoesntCauseInfiniteLoopIfProxyReturnsEmptyArr $proxy = $this->createMock(Proxy::class); $proxy->expects($this->exactly(2)) ->method('getValueOptions') - ->will($this->returnValue($options)); + ->willReturn($options); $element->expects($this->never()) ->method('setValueOptions'); @@ -80,7 +80,7 @@ public function testGetValueOptionsDoesntInvokeProxyIfOptionsNotEmpty(): void $proxy = $this->createMock(Proxy::class); $proxy->expects($this->once()) ->method('getValueOptions') - ->will($this->returnValue($options)); + ->willReturn($options); $this->setProxyViaReflection($proxy); diff --git a/tests/Form/Element/ObjectRadioTest.php b/tests/Form/Element/ObjectRadioTest.php index 6621e124..0f212169 100644 --- a/tests/Form/Element/ObjectRadioTest.php +++ b/tests/Form/Element/ObjectRadioTest.php @@ -37,7 +37,7 @@ public function testGetValueOptionsDoesntCauseInfiniteLoopIfProxyReturnsEmptyArr $proxy = $this->createMock(Proxy::class); $proxy->expects($this->exactly(2)) ->method('getValueOptions') - ->will($this->returnValue($options)); + ->willReturn($options); $element->expects($this->never()) ->method('setValueOptions'); @@ -54,7 +54,7 @@ public function testGetValueOptionsDoesntInvokeProxyIfOptionsNotEmpty(): void $proxy = $this->createMock(Proxy::class); $proxy->expects($this->once()) ->method('getValueOptions') - ->will($this->returnValue($options)); + ->willReturn($options); $this->setProxyViaReflection($proxy); diff --git a/tests/Form/Element/ObjectSelectTest.php b/tests/Form/Element/ObjectSelectTest.php index 2c969010..28be1d3a 100644 --- a/tests/Form/Element/ObjectSelectTest.php +++ b/tests/Form/Element/ObjectSelectTest.php @@ -81,7 +81,7 @@ public function testGetValueOptionsDoesntCauseInfiniteLoopIfProxyReturnsEmptyArr $proxy = $this->createMock(Proxy::class); $proxy->expects($this->exactly(2)) ->method('getValueOptions') - ->will($this->returnValue($options)); + ->willReturn($options); $element->expects($this->never()) ->method('setValueOptions'); @@ -98,7 +98,7 @@ public function testGetValueOptionsDoesntInvokeProxyIfOptionsNotEmpty(): void $proxy = $this->createMock(Proxy::class); $proxy->expects($this->once()) ->method('getValueOptions') - ->will($this->returnValue($options)); + ->willReturn($options); $this->setProxyViaReflection($proxy); diff --git a/tests/Form/Element/ProxyAwareElementTestCase.php b/tests/Form/Element/ProxyAwareElementTestCase.php index bdbed5ae..68a7983f 100644 --- a/tests/Form/Element/ProxyAwareElementTestCase.php +++ b/tests/Form/Element/ProxyAwareElementTestCase.php @@ -76,19 +76,19 @@ static function () use ($objectOne, $objectTwo) { $objectRepository = $this->createMock(ObjectRepository::class); $objectRepository->expects($this->any()) ->method('findAll') - ->will($this->returnValue($result)); + ->willReturn($result); $objectManager = $this->createMock(ObjectManager::class); $objectManager->expects($this->any()) ->method('getClassMetadata') ->with($this->equalTo($objectClass)) - ->will($this->returnValue($metadata)); + ->willReturn($metadata); $objectManager ->expects($this->any()) ->method('getRepository') ->with($this->equalTo($objectClass)) - ->will($this->returnValue($objectRepository)); + ->willReturn($objectRepository); if (! method_exists($this->element, 'getProxy')) { throw new RuntimeException('Element must implement getProxy().'); diff --git a/tests/Form/Element/ProxyTest.php b/tests/Form/Element/ProxyTest.php index d49736f4..9090f967 100644 --- a/tests/Form/Element/ProxyTest.php +++ b/tests/Form/Element/ProxyTest.php @@ -72,7 +72,7 @@ public function testExceptionThrownForMissingFindMethodName(): void $objectManager->expects($this->once()) ->method('getClassMetadata') ->with($this->equalTo($objectClass)) - ->will($this->returnValue($metadata)); + ->willReturn($metadata); $this->proxy->setOptions([ 'object_manager' => $objectManager, @@ -94,12 +94,12 @@ public function testExceptionFindMethodNameNotExistentInRepository(): void $objectManager->expects($this->once()) ->method('getClassMetadata') ->with($this->equalTo($objectClass)) - ->will($this->returnValue($metadata)); + ->willReturn($metadata); $objectManager->expects($this->once()) ->method('getRepository') ->with($this->equalTo($objectClass)) - ->will($this->returnValue($objectRepository)); + ->willReturn($objectRepository); $this->proxy->setOptions([ 'object_manager' => $objectManager, @@ -128,12 +128,12 @@ public function testExceptionThrownForMissingRequiredParameter(): void $objectManager->expects($this->once()) ->method('getClassMetadata') ->with($this->equalTo($objectClass)) - ->will($this->returnValue($metadata)); + ->willReturn($metadata); $objectManager->expects($this->once()) ->method('getRepository') ->with($this->equalTo($objectClass)) - ->will($this->returnValue($objectRepository)); + ->willReturn($objectRepository); $this->proxy->setOptions([ 'object_manager' => $objectManager, @@ -165,7 +165,7 @@ public function testToStringIsUsedForGetValueOptions(): void $this->metadata->expects($this->exactly(2)) ->method('hasField') ->with($this->equalTo('username')) - ->will($this->returnValue(true)); + ->willReturn(true); $result = $this->proxy->getValueOptions(); $this->assertEquals($result[0]['label'], 'object one username'); @@ -183,7 +183,7 @@ public function testPropertyGetterUsedForGetValueOptions(): void $this->metadata->expects($this->exactly(2)) ->method('hasField') ->with($this->equalTo('password')) - ->will($this->returnValue(true)); + ->willReturn(true); $result = $this->proxy->getValueOptions(); $this->assertEquals($result[0]['label'], 'object one password'); @@ -203,7 +203,7 @@ public function testPublicPropertyUsedForGetValueOptions(): void ->expects($this->exactly(2)) ->method('hasField') ->with($this->equalTo('email')) - ->will($this->returnValue(true)); + ->willReturn(true); $result = $this->proxy->getValueOptions(); $this->assertEquals($result[0]['label'], 'object one email'); @@ -244,7 +244,7 @@ public function testDisplayEmptyItemAndEmptyItemLabelOptionsUsedForGetValueOptio $this->metadata->expects($this->exactly(2)) ->method('hasField') ->with($this->equalTo('password')) - ->will($this->returnValue(true)); + ->willReturn(true); $result = $this->proxy->getValueOptions(); $this->assertArrayHasKey('', $result); @@ -298,7 +298,7 @@ public function testUsingOptionAttributesOfTypeString(): void $this->metadata->expects($this->exactly(2)) ->method('hasField') ->with($this->equalTo('password')) - ->will($this->returnValue(true)); + ->willReturn(true); $options = $this->proxy->getValueOptions(); @@ -330,7 +330,7 @@ public function testUsingOptionAttributesOfTypeCallableReturningString(): void $this->metadata->expects($this->exactly(2)) ->method('hasField') ->with($this->equalTo('password')) - ->will($this->returnValue(true)); + ->willReturn(true); $options = $this->proxy->getValueOptions(); @@ -399,7 +399,7 @@ public function testUsingFindMethod(): void $this->metadata->expects($this->exactly(2)) ->method('hasField') ->with($this->equalTo('password')) - ->will($this->returnValue(true)); + ->willReturn(true); $this->proxy->getValueOptions(); } @@ -443,7 +443,7 @@ public function testValueOptionsGeneratedProperlyWithOptgroups(): void $this->metadata->expects($this->exactly(3)) ->method('hasField') ->with($this->equalTo('username')) - ->will($this->returnValue(true)); + ->willReturn(true); $valueOptions = $this->proxy->getValueOptions(); @@ -500,7 +500,7 @@ public function testEmptyOptgroupValueBelongsToOptgroupDefaultIfConfigured(): vo $this->metadata->expects($this->exactly(2)) ->method('hasField') ->with($this->equalTo('username')) - ->will($this->returnValue(true)); + ->willReturn(true); $valueOptions = $this->proxy->getValueOptions(); @@ -547,7 +547,7 @@ public function testEmptyOptgroupValueBelongsToNoOptgroupIfNotConfigured(): void $this->metadata->expects($this->exactly(2)) ->method('hasField') ->with($this->equalTo('username')) - ->will($this->returnValue(true)); + ->willReturn(true); $valueOptions = $this->proxy->getValueOptions(); @@ -620,19 +620,19 @@ static function () use ($objectOne, $objectTwo) { $objectRepository = $this->createMock(ObjectRepository::class); $objectRepository->expects($this->any()) ->method('findAll') - ->will($this->returnValue($result)); + ->willReturn($result); $objectManager = $this->createMock(ObjectManager::class); $objectManager->expects($this->any()) ->method('getClassMetadata') ->with($this->equalTo($objectClass)) - ->will($this->returnValue($metadata)); + ->willReturn($metadata); $objectManager ->expects($this->any()) ->method('getRepository') ->with($this->equalTo($objectClass)) - ->will($this->returnValue($objectRepository)); + ->willReturn($objectRepository); $this->proxy->setOptions([ 'object_manager' => $objectManager, @@ -705,19 +705,19 @@ static function () use ($objectOne, $objectTwo, $objectThree) { $objectRepository = $this->createMock(ObjectRepository::class); $objectRepository->expects($this->any()) ->method('findAll') - ->will($this->returnValue($result)); + ->willReturn($result); $objectManager = $this->createMock(ObjectManager::class); $objectManager->expects($this->any()) ->method('getClassMetadata') ->with($this->equalTo($objectClass)) - ->will($this->returnValue($metadata)); + ->willReturn($metadata); $objectManager ->expects($this->any()) ->method('getRepository') ->with($this->equalTo($objectClass)) - ->will($this->returnValue($objectRepository)); + ->willReturn($objectRepository); $this->proxy->setOptions([ 'object_manager' => $objectManager, @@ -776,19 +776,19 @@ static function () use ($objectOne, $objectTwo) { $objectRepository = $this->createMock(ObjectRepository::class); $objectRepository->expects($this->any()) ->method('findAll') - ->will($this->returnValue($result)); + ->willReturn($result); $objectManager = $this->createMock(ObjectManager::class); $objectManager->expects($this->any()) ->method('getClassMetadata') ->with($this->equalTo($objectClass)) - ->will($this->returnValue($metadata)); + ->willReturn($metadata); $objectManager ->expects($this->any()) ->method('getRepository') ->with($this->equalTo($objectClass)) - ->will($this->returnValue($objectRepository)); + ->willReturn($objectRepository); $this->proxy->setOptions([ 'object_manager' => $objectManager, @@ -846,20 +846,20 @@ static function () use ($objectOne, $objectTwo) { $objectRepository ->expects($this->once()) ->method('findBy') - ->will($this->returnValue($result)); + ->willReturn($result); $objectManager = $this->createMock(ObjectManager::class); $objectManager ->expects($this->once()) ->method('getClassMetadata') ->with($this->equalTo($objectClass)) - ->will($this->returnValue($metadata)); + ->willReturn($metadata); $objectManager ->expects($this->once()) ->method('getRepository') ->with($this->equalTo($objectClass)) - ->will($this->returnValue($objectRepository)); + ->willReturn($objectRepository); $this->proxy->setOptions([ 'object_manager' => $objectManager, @@ -888,20 +888,20 @@ public function prepareEmptyProxy(mixed $result = null): void $objectRepository ->expects($this->once()) ->method('findAll') - ->will($this->returnValue($result)); + ->willReturn($result); $objectManager = $this->createMock(ObjectManager::class); $objectManager ->expects($this->once()) ->method('getClassMetadata') ->with($this->equalTo($objectClass)) - ->will($this->returnValue($metadata)); + ->willReturn($metadata); $objectManager ->expects($this->once()) ->method('getRepository') ->with($this->equalTo($objectClass)) - ->will($this->returnValue($objectRepository)); + ->willReturn($objectRepository); $this->proxy->setOptions([ 'object_manager' => $objectManager, diff --git a/tests/ModuleTest.php b/tests/ModuleTest.php index bd79007e..5d4e3cd6 100644 --- a/tests/ModuleTest.php +++ b/tests/ModuleTest.php @@ -44,19 +44,19 @@ protected function setUp(): void ->expects($this->any()) ->method('get') ->with('doctrine.cli') - ->will($this->returnValue($this->cli)); + ->willReturn($this->cli); $this ->application ->expects($this->any()) ->method('getServiceManager') - ->will($this->returnValue($this->serviceManager)); + ->willReturn($this->serviceManager); $this ->event ->expects($this->any()) ->method('getTarget') - ->will($this->returnValue($this->application)); + ->willReturn($this->application); } /** @covers \DoctrineModule\Module::getConfig */ diff --git a/tests/Paginator/Adapter/SelectableAdapterTest.php b/tests/Paginator/Adapter/SelectableAdapterTest.php index 4a17b0db..ed3836f1 100644 --- a/tests/Paginator/Adapter/SelectableAdapterTest.php +++ b/tests/Paginator/Adapter/SelectableAdapterTest.php @@ -38,7 +38,7 @@ static function (Criteria $criteria) use ($me) { }, ), ) - ->will($this->returnValue(new ArrayCollection(range(1, 10)))); + ->willReturn(new ArrayCollection(range(1, 10))); $expected = range(1, 10); $actual = $adapter->getItems(0, 10); @@ -70,7 +70,7 @@ static function (Criteria $innerCriteria) use ($criteria, $me) { }, ), ) - ->will($this->returnValue(new ArrayCollection(range(1, 10)))); + ->willReturn(new ArrayCollection(range(1, 10))); $expected = range(1, 10); $actual = $adapter->getItems(0, 10); @@ -98,7 +98,7 @@ static function (Criteria $criteria) use ($me) { }, ), ) - ->will($this->returnValue(new ArrayCollection(range(11, 20)))); + ->willReturn(new ArrayCollection(range(11, 20))); $expected = range(11, 20); $actual = $adapter->getItems(10, 10); @@ -130,7 +130,7 @@ static function (Criteria $innerCriteria) use ($criteria, $me) { }, ), ) - ->will($this->returnValue(new ArrayCollection(range(11, 20)))); + ->willReturn(new ArrayCollection(range(11, 20))); $expected = range(11, 20); $actual = $adapter->getItems(10, 10); @@ -156,7 +156,7 @@ public function testReturnsCorrectCount(): void && $criteria->getMaxResults() === null, ), ) - ->will($this->returnValue(new ArrayCollection(range(1, 101)))); + ->willReturn(new ArrayCollection(range(1, 101))); $this->assertEquals(101, $adapter->count()); diff --git a/tests/Validator/NoObjectExistsTest.php b/tests/Validator/NoObjectExistsTest.php index 112533e4..d4f88674 100644 --- a/tests/Validator/NoObjectExistsTest.php +++ b/tests/Validator/NoObjectExistsTest.php @@ -23,7 +23,7 @@ public function testCanValidateWithNoAvailableObjectInRepository(): void $repository ->expects($this->once()) ->method('findOneBy') - ->will($this->returnValue(null)); + ->willReturn(null); $validator = new NoObjectExists(['object_repository' => $repository, 'fields' => 'matchKey']); @@ -37,7 +37,7 @@ public function testCannotValidateWithAvailableObjectInRepository(): void $repository ->expects($this->once()) ->method('findOneBy') - ->will($this->returnValue(new stdClass())); + ->willReturn(new stdClass()); $validator = new NoObjectExists(['object_repository' => $repository, 'fields' => 'matchKey']); @@ -50,7 +50,7 @@ public function testErrorMessageIsStringInsteadArray(): void $repository ->expects($this->once()) ->method('findOneBy') - ->will($this->returnValue(new stdClass())); + ->willReturn(new stdClass()); $validator = new NoObjectExists(['object_repository' => $repository, 'fields' => 'matchKey']); $this->assertFalse($validator->isValid('matchValue')); diff --git a/tests/Validator/ObjectExistsTest.php b/tests/Validator/ObjectExistsTest.php index c19ca9c1..c1dffbd4 100644 --- a/tests/Validator/ObjectExistsTest.php +++ b/tests/Validator/ObjectExistsTest.php @@ -28,7 +28,7 @@ public function testCanValidateWithSingleField(): void ->expects($this->exactly(2)) ->method('findOneBy') ->with(['matchKey' => 'matchValue']) - ->will($this->returnValue(new stdClass())); + ->willReturn(new stdClass()); $validator = new ObjectExists(['object_repository' => $repository, 'fields' => 'matchKey']); @@ -44,7 +44,7 @@ public function testCanValidateWithIntegerId(): void ->expects($this->exactly(2)) ->method('findOneBy') ->with(['matchKey' => 123]) - ->will($this->returnValue(new stdClass())); + ->willReturn(new stdClass()); $validator = new ObjectExists(['object_repository' => $repository, 'fields' => 'matchKey']); @@ -59,7 +59,7 @@ public function testCanValidateWithMultipleFields(): void ->expects($this->exactly(2)) ->method('findOneBy') ->with(['firstMatchKey' => 'firstMatchValue', 'secondMatchKey' => 'secondMatchValue']) - ->will($this->returnValue(new stdClass())); + ->willReturn(new stdClass()); $validator = new ObjectExists([ 'object_repository' => $repository, @@ -83,7 +83,7 @@ public function testCanValidateFalseOnNoResult(): void $repository ->expects($this->once()) ->method('findOneBy') - ->will($this->returnValue(null)); + ->willReturn(null); $validator = new ObjectExists([ 'object_repository' => $repository, diff --git a/tests/Validator/UniqueObjectTest.php b/tests/Validator/UniqueObjectTest.php index 14aa14fc..f272b924 100644 --- a/tests/Validator/UniqueObjectTest.php +++ b/tests/Validator/UniqueObjectTest.php @@ -29,7 +29,7 @@ public function testCanValidateWithNotAvailableObjectInRepository(): void ->expects($this->once()) ->method('findOneBy') ->with(['matchKey' => 'matchValue']) - ->will($this->returnValue(null)); + ->willReturn(null); $objectManager = $this->createMock(ObjectManager::class); @@ -49,29 +49,29 @@ public function testCanValidateIfThereIsTheSameObjectInTheRepository(): void $classMetadata ->expects($this->once()) ->method('getIdentifierFieldNames') - ->will($this->returnValue(['id'])); + ->willReturn(['id']); $classMetadata ->expects($this->once()) ->method('getIdentifierValues') ->with($match) - ->will($this->returnValue(['id' => 'identifier'])); + ->willReturn(['id' => 'identifier']); $objectManager = $this->createMock(ObjectManager::class); $objectManager->expects($this->any()) ->method('getClassMetadata') ->with('stdClass') - ->will($this->returnValue($classMetadata)); + ->willReturn($classMetadata); $repository = $this->createMock(ObjectRepository::class); $repository ->expects($this->any()) ->method('getClassName') - ->will($this->returnValue('stdClass')); + ->willReturn('stdClass'); $repository ->expects($this->once()) ->method('findOneBy') ->with(['matchKey' => 'matchValue']) - ->will($this->returnValue($match)); + ->willReturn($match); $validator = new UniqueObject([ 'object_repository' => $repository, @@ -89,29 +89,29 @@ public function testCannotValidateIfThereIsAnotherObjectWithTheSameValueInTheRep $classMetadata ->expects($this->once()) ->method('getIdentifierFieldNames') - ->will($this->returnValue(['id'])); + ->willReturn(['id']); $classMetadata ->expects($this->once()) ->method('getIdentifierValues') ->with($match) - ->will($this->returnValue(['id' => 'identifier'])); + ->willReturn(['id' => 'identifier']); $objectManager = $this->createMock(ObjectManager::class); $objectManager->expects($this->any()) ->method('getClassMetadata') ->with('stdClass') - ->will($this->returnValue($classMetadata)); + ->willReturn($classMetadata); $repository = $this->createMock(ObjectRepository::class); $repository ->expects($this->any()) ->method('getClassName') - ->will($this->returnValue('stdClass')); + ->willReturn('stdClass'); $repository ->expects($this->once()) ->method('findOneBy') ->with(['matchKey' => 'matchValue']) - ->will($this->returnValue($match)); + ->willReturn($match); $validator = new UniqueObject([ 'object_repository' => $repository, @@ -129,29 +129,29 @@ public function testCanFetchIdentifierFromContext(): void $classMetadata ->expects($this->once()) ->method('getIdentifierFieldNames') - ->will($this->returnValue(['id'])); + ->willReturn(['id']); $classMetadata ->expects($this->once()) ->method('getIdentifierValues') ->with($match) - ->will($this->returnValue(['id' => 'identifier'])); + ->willReturn(['id' => 'identifier']); $objectManager = $this->createMock(ObjectManager::class); $objectManager->expects($this->any()) ->method('getClassMetadata') ->with('stdClass') - ->will($this->returnValue($classMetadata)); + ->willReturn($classMetadata); $repository = $this->createMock(ObjectRepository::class); $repository ->expects($this->any()) ->method('getClassName') - ->will($this->returnValue('stdClass')); + ->willReturn('stdClass'); $repository ->expects($this->once()) ->method('findOneBy') ->with(['matchKey' => 'matchValue']) - ->will($this->returnValue($match)); + ->willReturn($match); $validator = new UniqueObject([ 'object_repository' => $repository, @@ -174,7 +174,7 @@ public function testThrowsAnExceptionOnUsedButMissingContext(): void ->expects($this->once()) ->method('findOneBy') ->with(['matchKey' => 'matchValue']) - ->will($this->returnValue($match)); + ->willReturn($match); $objectManager = $this->createMock(ObjectManager::class); @@ -198,24 +198,24 @@ public function testThrowsAnExceptionOnMissingIdentifier(): void $classMetadata ->expects($this->once()) ->method('getIdentifierFieldNames') - ->will($this->returnValue(['id'])); + ->willReturn(['id']); $objectManager = $this->createMock(ObjectManager::class); $objectManager->expects($this->any()) ->method('getClassMetadata') ->with('stdClass') - ->will($this->returnValue($classMetadata)); + ->willReturn($classMetadata); $repository = $this->createMock(ObjectRepository::class); $repository ->expects($this->any()) ->method('getClassName') - ->will($this->returnValue('stdClass')); + ->willReturn('stdClass'); $repository ->expects($this->once()) ->method('findOneBy') ->with(['matchKey' => 'matchValue']) - ->will($this->returnValue($match)); + ->willReturn($match); $validator = new UniqueObject([ 'object_repository' => $repository, @@ -236,24 +236,24 @@ public function testThrowsAnExceptionOnMissingIdentifierInContext(): void $classMetadata ->expects($this->once()) ->method('getIdentifierFieldNames') - ->will($this->returnValue(['id'])); + ->willReturn(['id']); $objectManager = $this->createMock(ObjectManager::class); $objectManager->expects($this->any()) ->method('getClassMetadata') ->with('stdClass') - ->will($this->returnValue($classMetadata)); + ->willReturn($classMetadata); $repository = $this->createMock(ObjectRepository::class); $repository ->expects($this->any()) ->method('getClassName') - ->will($this->returnValue('stdClass')); + ->willReturn('stdClass'); $repository ->expects($this->once()) ->method('findOneBy') ->with(['matchKey' => 'matchValue']) - ->will($this->returnValue($match)); + ->willReturn($match); $validator = new UniqueObject([ 'object_repository' => $repository, @@ -307,7 +307,7 @@ public function testCanValidateWithNotAvailableObjectInRepositoryByDateTimeObjec ->expects($this->once()) ->method('findOneBy') ->with(['date' => $date]) - ->will($this->returnValue(null)); + ->willReturn(null); $objectManager = $this->createMock(ObjectManager::class); @@ -340,18 +340,18 @@ public function testCanFetchIdentifierFromObjectContext(): void $objectManager->expects($this->any()) ->method('getClassMetadata') ->with('stdClass') - ->will($this->returnValue($classMetadata)); + ->willReturn($classMetadata); $repository = $this->createMock(ObjectRepository::class); $repository ->expects($this->any()) ->method('getClassName') - ->will($this->returnValue('stdClass')); + ->willReturn('stdClass'); $repository ->expects($this->once()) ->method('findOneBy') ->with(['matchKey' => 'matchValue']) - ->will($this->returnValue($match)); + ->willReturn($match); $validator = new UniqueObject([ 'object_repository' => $repository, @@ -371,29 +371,29 @@ public function testErrorMessageIsStringInsteadArray(): void $classMetadata ->expects($this->once()) ->method('getIdentifierFieldNames') - ->will($this->returnValue(['id'])); + ->willReturn(['id']); $classMetadata ->expects($this->once()) ->method('getIdentifierValues') ->with($match) - ->will($this->returnValue(['id' => 'identifier'])); + ->willReturn(['id' => 'identifier']); $objectManager = $this->createMock(ObjectManager::class); $objectManager->expects($this->any()) ->method('getClassMetadata') ->with('stdClass') - ->will($this->returnValue($classMetadata)); + ->willReturn($classMetadata); $repository = $this->createMock(ObjectRepository::class); $repository ->expects($this->any()) ->method('getClassName') - ->will($this->returnValue('stdClass')); + ->willReturn('stdClass'); $repository ->expects($this->once()) ->method('findOneBy') ->with(['matchKey' => 'matchValue']) - ->will($this->returnValue($match)); + ->willReturn($match); $validator = new UniqueObject([ 'object_repository' => $repository,