From 3b7a3648fe6a3bfd93b90607172d8316ea7c8f32 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Mon, 5 Aug 2024 18:21:29 -0600 Subject: [PATCH 1/4] Migrated phpunit configuration --- phpunit.xml.dist | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5835e874..acd71f56 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,17 +1,13 @@ - - - - ./src - - + ./tests + + + ./src + + From 622add2d707cc61f35d071f85ee01c4bb246aec6 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Mon, 5 Aug 2024 18:45:04 -0600 Subject: [PATCH 2/4] Added phpunit attributes to all tests --- .../Adapter/ObjectRepositoryTest.php | 12 ++++ .../Storage/ObjectRepositoryTest.php | 2 + tests/Cache/DoctrineCacheStorageTest.php | 55 +++++++++++++++++++ tests/Cache/LaminasStorageCacheTest.php | 6 ++ tests/ConfigProviderTest.php | 3 + .../Form/Element/ObjectMultiCheckboxTest.php | 6 ++ tests/Form/Element/ObjectRadioTest.php | 4 ++ tests/Form/Element/ObjectSelectTest.php | 7 +++ tests/Form/Element/ProxyTest.php | 24 ++++++++ tests/ModuleTest.php | 2 + .../Adapter/CollectionAdapterTest.php | 5 ++ .../Adapter/SelectableAdapterTest.php | 8 ++- .../Authentication/AdapterFactoryTest.php | 2 + .../AuthenticationServiceFactoryTest.php | 2 + .../Authentication/StorageFactoryTest.php | 3 + tests/Service/CacheFactoryTest.php | 5 ++ tests/Service/DriverFactoryTest.php | 9 ++- tests/Service/EventManagerFactoryTest.php | 5 ++ .../ModuleDefinedServicesTest.php | 20 ++++--- tests/Validator/NoObjectExistsTest.php | 4 ++ tests/Validator/ObjectExistsTest.php | 14 +++++ .../Service/NoObjectExistsFactoryTest.php | 7 +++ .../Service/ObjectExistsFactoryTest.php | 2 + .../Service/UniqueObjectFactoryTest.php | 2 + tests/Validator/UniqueObjectTest.php | 13 +++++ 25 files changed, 210 insertions(+), 12 deletions(-) diff --git a/tests/Authentication/Adapter/ObjectRepositoryTest.php b/tests/Authentication/Adapter/ObjectRepositoryTest.php index 2f7cd622..04c971ce 100644 --- a/tests/Authentication/Adapter/ObjectRepositoryTest.php +++ b/tests/Authentication/Adapter/ObjectRepositoryTest.php @@ -12,6 +12,7 @@ use Laminas\Authentication\Adapter\Exception\InvalidArgumentException; use Laminas\Authentication\Adapter\Exception\RuntimeException; use Laminas\Authentication\Adapter\Exception\UnexpectedValueException; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase as BaseTestCase; use stdClass; @@ -22,6 +23,7 @@ */ class ObjectRepositoryTest extends BaseTestCase { + #[Test] public function testWillRejectInvalidIdentityProperty(): void { $this->expectException( @@ -34,6 +36,7 @@ public function testWillRejectInvalidIdentityProperty(): void new ObjectRepositoryAdapter(['identity_property' => '']); } + #[Test] public function testWillRejectInvalidCredentialProperty(): void { $this->expectException( @@ -45,6 +48,7 @@ public function testWillRejectInvalidCredentialProperty(): void new ObjectRepositoryAdapter(['credential_property' => '']); } + #[Test] public function testWillRequireIdentityValue(): void { $this->expectException( @@ -63,6 +67,7 @@ public function testWillRequireIdentityValue(): void $adapter->authenticate(); } + #[Test] public function testWillRequireCredentialValue(): void { $this->expectException( @@ -81,6 +86,7 @@ public function testWillRequireCredentialValue(): void $adapter->authenticate(); } + #[Test] public function testWillRejectInvalidCredentialCallable(): void { $this->expectException( @@ -99,6 +105,7 @@ public function testWillRejectInvalidCredentialCallable(): void $adapter->authenticate(); } + #[Test] public function testAuthentication(): void { $entity = new IdentityObject(); @@ -145,6 +152,7 @@ public function testAuthentication(): void $this->assertFalse($result->isValid()); } + #[Test] public function testAuthenticationWithPublicProperties(): void { $entity = new PublicPropertiesIdentityObject(); @@ -180,6 +188,7 @@ public function testAuthenticationWithPublicProperties(): void $this->assertFalse($result->isValid()); } + #[Test] public function testWillRefuseToAuthenticateWithoutGettersOrPublicMethods(): void { $this->expectException(UnexpectedValueException::class); @@ -203,6 +212,7 @@ public function testWillRefuseToAuthenticateWithoutGettersOrPublicMethods(): voi $adapter->authenticate(); } + #[Test] public function testCanValidateWithSpecialCrypt(): void { $hash = '$2y$07$usesomesillystringforsalt$'; @@ -240,6 +250,7 @@ public function testCanValidateWithSpecialCrypt(): void $this->assertFalse($result->isValid()); } + #[Test] public function testWillRefuseToAuthenticateWhenInvalidInstanceIsFound(): void { $this->expectException(UnexpectedValueException::class); @@ -264,6 +275,7 @@ public function testWillRefuseToAuthenticateWhenInvalidInstanceIsFound(): void $adapter->authenticate(); } + #[Test] public function testWillNotCastAuthCredentialValue(): void { $objectRepository = $this->createMock(ObjectRepository::class); diff --git a/tests/Authentication/Storage/ObjectRepositoryTest.php b/tests/Authentication/Storage/ObjectRepositoryTest.php index 6047e47d..9007e670 100644 --- a/tests/Authentication/Storage/ObjectRepositoryTest.php +++ b/tests/Authentication/Storage/ObjectRepositoryTest.php @@ -9,6 +9,7 @@ use DoctrineModule\Authentication\Storage\ObjectRepository as ObjectRepositoryStorage; use DoctrineModuleTest\Authentication\Adapter\TestAsset\IdentityObject; use Laminas\Authentication\Storage\NonPersistent as NonPersistentStorage; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase as BaseTestCase; /** @@ -16,6 +17,7 @@ */ class ObjectRepositoryTest extends BaseTestCase { + #[Test] public function testCanRetrieveEntityFromObjectRepositoryStorage(): void { // Identifier is considered to be username here diff --git a/tests/Cache/DoctrineCacheStorageTest.php b/tests/Cache/DoctrineCacheStorageTest.php index 79463fad..d3396f16 100644 --- a/tests/Cache/DoctrineCacheStorageTest.php +++ b/tests/Cache/DoctrineCacheStorageTest.php @@ -12,6 +12,7 @@ use Laminas\Cache\Storage\Capabilities; use Laminas\Cache\Storage\StorageInterface; use Laminas\Stdlib\ErrorHandler; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use stdClass; @@ -82,6 +83,7 @@ protected function tearDown(): void ErrorHandler::clean(); } + #[Test] public function testOptionNamesValid(): void { $options = $this->storage->getOptions()->toArray(); @@ -97,6 +99,7 @@ public function testOptionNamesValid(): void } } + #[Test] public function testGettersAndSettersOfOptionsExists(): void { $options = $this->storage->getOptions(); @@ -127,6 +130,7 @@ public function testGettersAndSettersOfOptionsExists(): void } } + #[Test] public function testOptionsGetAndSetDefault(): void { $options = $this->storage->getOptions(); @@ -134,6 +138,7 @@ public function testOptionsGetAndSetDefault(): void $this->assertSame($options, $this->storage->getOptions()); } + #[Test] public function testOptionsFluentInterface(): void { $options = $this->storage->getOptions(); @@ -157,12 +162,14 @@ public function testOptionsFluentInterface(): void ); } + #[Test] public function testGetCapabilities(): void { $capabilities = $this->storage->getCapabilities(); $this->assertInstanceOf(Capabilities::class, $capabilities); } + #[Test] public function testDatatypesCapability(): void { $capabilities = $this->storage->getCapabilities(); @@ -180,6 +187,7 @@ public function testDatatypesCapability(): void } } + #[Test] public function testSupportedMetadataCapability(): void { $capabilities = $this->storage->getCapabilities(); @@ -191,6 +199,7 @@ public function testSupportedMetadataCapability(): void } } + #[Test] public function testTtlCapabilities(): void { $capabilities = $this->storage->getCapabilities(); @@ -206,6 +215,7 @@ public function testTtlCapabilities(): void $this->assertIsBool($capabilities->getStaticTtl()); } + #[Test] public function testKeyCapabilities(): void { $capabilities = $this->storage->getCapabilities(); @@ -218,17 +228,20 @@ public function testKeyCapabilities(): void $this->assertIsString($capabilities->getNamespaceSeparator()); } + #[Test] public function testHasItemReturnsTrueOnValidItem(): void { $this->assertTrue($this->storage->setItem('key', 'value')); $this->assertTrue($this->storage->hasItem('key')); } + #[Test] public function testHasItemReturnsFalseOnMissingItem(): void { $this->assertFalse($this->storage->hasItem('key')); } + #[Test] public function testHasItemNonReadable(): void { $this->assertTrue($this->storage->setItem('key', 'value')); @@ -237,6 +250,7 @@ public function testHasItemNonReadable(): void $this->assertFalse($this->storage->hasItem('key')); } + #[Test] public function testHasItemsReturnsKeysOfFoundItems(): void { $this->assertTrue($this->storage->setItem('key1', 'value1')); @@ -249,6 +263,7 @@ public function testHasItemsReturnsKeysOfFoundItems(): void $this->assertEquals($expectedResult, $result); } + #[Test] public function testHasItemsReturnsEmptyArrayIfNonReadable(): void { $this->assertTrue($this->storage->setItem('key', 'value')); @@ -257,11 +272,13 @@ public function testHasItemsReturnsEmptyArrayIfNonReadable(): void $this->assertEquals([], $this->storage->hasItems(['key'])); } + #[Test] public function testGetItemReturnsNullOnMissingItem(): void { $this->assertNull($this->storage->getItem('unknown')); } + #[Test] public function testGetItemSetsSuccessFlag(): void { $success = null; @@ -276,6 +293,7 @@ public function testGetItemSetsSuccessFlag(): void $this->assertTrue($success); } + #[Test] public function testGetItemReturnsNullIfNonReadable(): void { $this->options->setReadable(false); @@ -284,6 +302,7 @@ public function testGetItemReturnsNullIfNonReadable(): void $this->assertNull($this->storage->getItem('key')); } + #[Test] public function testGetItemsReturnsKeyValuePairsOfFoundItems(): void { $this->assertTrue($this->storage->setItem('key1', 'value1')); @@ -299,6 +318,7 @@ public function testGetItemsReturnsKeyValuePairsOfFoundItems(): void $this->assertEquals($expectedResult, $result); } + #[Test] public function testGetItemsReturnsEmptyArrayIfNonReadable(): void { $this->options->setReadable(false); @@ -307,6 +327,7 @@ public function testGetItemsReturnsEmptyArrayIfNonReadable(): void $this->assertEquals([], $this->storage->getItems(['key'])); } + #[Test] public function testGetMetadata(): void { $capabilities = $this->storage->getCapabilities(); @@ -321,11 +342,13 @@ public function testGetMetadata(): void } } + #[Test] public function testGetMetadataReturnsFalseOnMissingItem(): void { $this->assertFalse($this->storage->getMetadata('unknown')); } + #[Test] public function testGetMetadataReturnsFalseIfNonReadable(): void { $this->options->setReadable(false); @@ -334,6 +357,7 @@ public function testGetMetadataReturnsFalseIfNonReadable(): void $this->assertFalse($this->storage->getMetadata('key')); } + #[Test] public function testGetMetadatas(): void { $capabilities = $this->storage->getCapabilities(); @@ -357,6 +381,7 @@ public function testGetMetadatas(): void } } + #[Test] public function testGetMetadatasReturnsEmptyArrayIfNonReadable(): void { $this->options->setReadable(false); @@ -365,6 +390,7 @@ public function testGetMetadatasReturnsEmptyArrayIfNonReadable(): void $this->assertEquals([], $this->storage->getMetadatas(['key'])); } + #[Test] public function testSetGetHasAndRemoveItem(): void { $this->assertTrue($this->storage->setItem('key', 'value')); @@ -376,6 +402,7 @@ public function testSetGetHasAndRemoveItem(): void $this->assertNull($this->storage->getItem('key')); } + #[Test] public function testSetGetHasAndRemoveItems(): void { $items = [ @@ -418,6 +445,7 @@ public function testSetGetHasAndRemoveItems(): void } } + #[Test] public function testSetGetHasAndRemoveItemWithNamespace(): void { // write "key" to default namespace @@ -448,6 +476,7 @@ public function testSetGetHasAndRemoveItemWithNamespace(): void $this->assertFalse($this->storage->hasItem('key')); } + #[Test] public function testSetGetHasAndRemoveItemsWithNamespace(): void { $items = [ @@ -496,6 +525,7 @@ public function testSetGetHasAndRemoveItemsWithNamespace(): void } } + #[Test] public function testSetAndGetItemOfDifferentTypes(): void { $capabilities = $this->storage->getCapabilities(); @@ -538,6 +568,7 @@ public function testSetAndGetItemOfDifferentTypes(): void } } + #[Test] public function testSetItemReturnsFalseIfNonWritable(): void { $this->options->setWritable(false); @@ -546,18 +577,21 @@ public function testSetItemReturnsFalseIfNonWritable(): void $this->assertFalse($this->storage->hasItem('key')); } + #[Test] public function testAddNewItem(): void { $this->assertTrue($this->storage->addItem('key', 'value')); $this->assertTrue($this->storage->hasItem('key')); } + #[Test] public function testAddItemReturnsFalseIfItemAlreadyExists(): void { $this->assertTrue($this->storage->setItem('key', 'value')); $this->assertFalse($this->storage->addItem('key', 'newValue')); } + #[Test] public function testAddItemReturnsFalseIfNonWritable(): void { $this->options->setWritable(false); @@ -566,6 +600,7 @@ public function testAddItemReturnsFalseIfNonWritable(): void $this->assertFalse($this->storage->hasItem('key')); } + #[Test] public function testAddItemsReturnsFailedKeys(): void { $this->assertTrue($this->storage->setItem('key1', 'value1')); @@ -580,6 +615,7 @@ public function testAddItemsReturnsFailedKeys(): void $this->assertTrue($this->storage->hasItem('key2')); } + #[Test] public function testReplaceExistingItem(): void { $this->assertTrue($this->storage->setItem('key', 'value')); @@ -587,11 +623,13 @@ public function testReplaceExistingItem(): void $this->assertEquals('anOtherValue', $this->storage->getItem('key')); } + #[Test] public function testReplaceItemReturnsFalseOnMissingItem(): void { $this->assertFalse($this->storage->replaceItem('missingKey', 'value')); } + #[Test] public function testReplaceItemReturnsFalseIfNonWritable(): void { $this->storage->setItem('key', 'value'); @@ -601,6 +639,7 @@ public function testReplaceItemReturnsFalseIfNonWritable(): void $this->assertEquals('value', $this->storage->getItem('key')); } + #[Test] public function testReplaceItemsReturnsFailedKeys(): void { $this->assertTrue($this->storage->setItem('key1', 'value1')); @@ -615,17 +654,20 @@ public function testReplaceItemsReturnsFailedKeys(): void $this->assertFalse($this->storage->hasItem('key2')); } + #[Test] public function testRemoveItemReturnsFalseOnMissingItem(): void { $this->assertFalse($this->storage->removeItem('missing')); } + #[Test] public function testRemoveItemsReturnsMissingKeys(): void { $this->storage->setItem('key', 'value'); $this->assertSame(['missing'], $this->storage->removeItems(['key', 'missing'])); } + #[Test] public function testCheckAndSetItem(): void { $this->assertTrue($this->storage->setItem('key', 'value')); @@ -640,6 +682,7 @@ public function testCheckAndSetItem(): void $this->assertEquals('newValue', $this->storage->getItem('key')); } + #[Test] public function testIncrementItem(): void { $this->assertTrue($this->storage->setItem('counter', 10)); @@ -647,12 +690,14 @@ public function testIncrementItem(): void $this->assertEquals(15, $this->storage->getItem('counter')); } + #[Test] public function testIncrementItemInitialValue(): void { $this->assertEquals(5, $this->storage->incrementItem('counter', 5)); $this->assertEquals(5, $this->storage->getItem('counter')); } + #[Test] public function testIncrementItemReturnsFalseIfNonWritable(): void { $this->storage->setItem('key', 10); @@ -662,6 +707,7 @@ public function testIncrementItemReturnsFalseIfNonWritable(): void $this->assertEquals(10, $this->storage->getItem('key')); } + #[Test] public function testIncrementItemsReturnsKeyValuePairsOfWrittenItems(): void { $this->assertTrue($this->storage->setItem('key1', 10)); @@ -673,6 +719,7 @@ public function testIncrementItemsReturnsKeyValuePairsOfWrittenItems(): void $this->assertSame(['key1' => 20, 'key2' => 10], $result); } + #[Test] public function testIncrementItemsReturnsEmptyArrayIfNonWritable(): void { $this->storage->setItem('key', 10); @@ -682,6 +729,7 @@ public function testIncrementItemsReturnsEmptyArrayIfNonWritable(): void $this->assertEquals(10, $this->storage->getItem('key')); } + #[Test] public function testDecrementItem(): void { $this->assertTrue($this->storage->setItem('counter', 30)); @@ -689,12 +737,14 @@ public function testDecrementItem(): void $this->assertEquals(25, $this->storage->getItem('counter')); } + #[Test] public function testDecrementItemInitialValue(): void { $this->assertEquals(-5, $this->storage->decrementItem('counter', 5)); $this->assertEquals(-5, $this->storage->getItem('counter')); } + #[Test] public function testDecrementItemReturnsFalseIfNonWritable(): void { $this->storage->setItem('key', 10); @@ -704,6 +754,7 @@ public function testDecrementItemReturnsFalseIfNonWritable(): void $this->assertEquals(10, $this->storage->getItem('key')); } + #[Test] public function testDecrementItemsReturnsEmptyArrayIfNonWritable(): void { $this->storage->setItem('key', 10); @@ -713,11 +764,13 @@ public function testDecrementItemsReturnsEmptyArrayIfNonWritable(): void $this->assertEquals(10, $this->storage->getItem('key')); } + #[Test] public function testTouchItemReturnsFalseOnMissingItem(): void { $this->assertFalse($this->storage->touchItem('missing')); } + #[Test] public function testTouchItemReturnsFalseIfNonWritable(): void { $this->options->setWritable(false); @@ -725,12 +778,14 @@ public function testTouchItemReturnsFalseIfNonWritable(): void $this->assertFalse($this->storage->touchItem('key')); } + #[Test] public function testTouchItemsReturnsGivenKeysIfNonWritable(): void { $this->options->setWritable(false); $this->assertSame(['key'], $this->storage->touchItems(['key'])); } + #[Test] public function testSetItemAndSetItemsCallSaveWithTtl(): void { $ttl = random_int(0, mt_getrandmax()); diff --git a/tests/Cache/LaminasStorageCacheTest.php b/tests/Cache/LaminasStorageCacheTest.php index d8a383b3..62a15963 100644 --- a/tests/Cache/LaminasStorageCacheTest.php +++ b/tests/Cache/LaminasStorageCacheTest.php @@ -8,6 +8,7 @@ use Doctrine\Common\Cache\Cache; use DoctrineModule\Cache\LaminasStorageCache; use Laminas\Cache\Storage\Adapter\Memory; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; /** @@ -20,6 +21,7 @@ protected function getCacheDriver(): LaminasStorageCache return new LaminasStorageCache(new Memory()); } + #[Test] public function testBasics(): void { $cache = $this->getCacheDriver(); @@ -43,6 +45,7 @@ public function testBasics(): void $this->assertInstanceOf('ArrayObject', $cache->fetch('test_object_key')); } + #[Test] public function testDeleteAll(): void { $cache = $this->getCacheDriver(); @@ -54,6 +57,7 @@ public function testDeleteAll(): void $this->assertFalse($cache->contains('test_key2')); } + #[Test] public function testFlushAll(): void { $cache = $this->getCacheDriver(); @@ -65,6 +69,7 @@ public function testFlushAll(): void $this->assertFalse($cache->contains('test_key2')); } + #[Test] public function testNamespace(): void { $cache = $this->getCacheDriver(); @@ -78,6 +83,7 @@ public function testNamespace(): void $this->assertFalse($cache->contains('key1')); } + #[Test] public function testGetStats(): void { $cache = $this->getCacheDriver(); diff --git a/tests/ConfigProviderTest.php b/tests/ConfigProviderTest.php index 082226fe..5fda7999 100644 --- a/tests/ConfigProviderTest.php +++ b/tests/ConfigProviderTest.php @@ -6,6 +6,7 @@ use DoctrineModule\ConfigProvider; use Laminas\Cache\Storage\Adapter\Filesystem; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use function serialize; @@ -16,6 +17,7 @@ */ class ConfigProviderTest extends TestCase { + #[Test] public function testInvokeHasCorrectKeys(): void { $config = (new ConfigProvider())->__invoke(); @@ -37,6 +39,7 @@ public function testInvokeHasCorrectKeys(): void self::assertSame($config, unserialize(serialize($config))); } + #[Test] public function testDoctrineCompatibleCacheKeyConfiguration(): void { $config = (new ConfigProvider())->getCachesConfig()['doctrinemodule.cache.filesystem']; diff --git a/tests/Form/Element/ObjectMultiCheckboxTest.php b/tests/Form/Element/ObjectMultiCheckboxTest.php index 23f39ae2..a028c365 100644 --- a/tests/Form/Element/ObjectMultiCheckboxTest.php +++ b/tests/Form/Element/ObjectMultiCheckboxTest.php @@ -7,6 +7,7 @@ use DoctrineModule\Form\Element\ObjectMultiCheckbox; use DoctrineModule\Form\Element\Proxy; use Laminas\Form\Element; +use PHPUnit\Framework\Attributes\Test; /** * Tests for the ObjectMultiCheckbox element @@ -30,6 +31,7 @@ protected function setUp(): void $this->prepareProxy(); } + #[Test] public function testSetValueWithCollection(): void { $this->element->setValue( @@ -42,6 +44,7 @@ public function testSetValueWithCollection(): void ); } + #[Test] public function testSetValueWithArray(): void { $this->element->setValue( @@ -54,6 +57,7 @@ public function testSetValueWithArray(): void ); } + #[Test] public function testGetValueOptionsDoesntCauseInfiniteLoopIfProxyReturnsEmptyArrayAndValidatorIsInitialized(): void { $element = $this->createPartialMock($this->element::class, ['setValueOptions']); @@ -73,6 +77,7 @@ public function testGetValueOptionsDoesntCauseInfiniteLoopIfProxyReturnsEmptyArr $this->assertEquals($options, $element->getValueOptions()); } + #[Test] public function testGetValueOptionsDoesntInvokeProxyIfOptionsNotEmpty(): void { $options = ['foo' => 'bar']; @@ -88,6 +93,7 @@ public function testGetValueOptionsDoesntInvokeProxyIfOptionsNotEmpty(): void $this->assertEquals($options, $this->element->getValueOptions()); } + #[Test] public function testOptionsCanBeSetSingle(): void { $proxy = $this->createMock(Proxy::class); diff --git a/tests/Form/Element/ObjectRadioTest.php b/tests/Form/Element/ObjectRadioTest.php index 6621e124..de158e72 100644 --- a/tests/Form/Element/ObjectRadioTest.php +++ b/tests/Form/Element/ObjectRadioTest.php @@ -7,6 +7,7 @@ use DoctrineModule\Form\Element\ObjectRadio; use DoctrineModule\Form\Element\Proxy; use Laminas\Form\Element; +use PHPUnit\Framework\Attributes\Test; /** * Tests for the ObjectRadio element @@ -28,6 +29,7 @@ protected function setUp(): void $this->element = new ObjectRadio(); } + #[Test] public function testGetValueOptionsDoesntCauseInfiniteLoopIfProxyReturnsEmptyArrayAndValidatorIsInitialized(): void { $element = $this->createPartialMock($this->element::class, ['setValueOptions']); @@ -47,6 +49,7 @@ public function testGetValueOptionsDoesntCauseInfiniteLoopIfProxyReturnsEmptyArr $this->assertEquals($options, $element->getValueOptions()); } + #[Test] public function testGetValueOptionsDoesntInvokeProxyIfOptionsNotEmpty(): void { $options = ['foo' => 'bar']; @@ -62,6 +65,7 @@ public function testGetValueOptionsDoesntInvokeProxyIfOptionsNotEmpty(): void $this->assertEquals($options, $this->element->getValueOptions()); } + #[Test] public function testOptionsCanBeSetSingle(): void { $proxy = $this->createMock(Proxy::class); diff --git a/tests/Form/Element/ObjectSelectTest.php b/tests/Form/Element/ObjectSelectTest.php index 2c969010..91204a9c 100644 --- a/tests/Form/Element/ObjectSelectTest.php +++ b/tests/Form/Element/ObjectSelectTest.php @@ -7,6 +7,7 @@ use DoctrineModule\Form\Element\ObjectSelect; use DoctrineModule\Form\Element\Proxy; use Laminas\Form\Element; +use PHPUnit\Framework\Attributes\Test; /** * Tests for the ObjectSelect element @@ -30,6 +31,7 @@ protected function setUp(): void $this->prepareProxy(); } + #[Test] public function testSetValueWithCollection(): void { $this->element->setAttribute('multiple', true); @@ -44,6 +46,7 @@ public function testSetValueWithCollection(): void ); } + #[Test] public function testSetValueWithArray(): void { $this->element->setAttribute('multiple', true); @@ -58,6 +61,7 @@ public function testSetValueWithArray(): void ); } + #[Test] public function testSetValueSingleValue(): void { $value = $this->values->toArray(); @@ -72,6 +76,7 @@ public function testSetValueSingleValue(): void ); } + #[Test] public function testGetValueOptionsDoesntCauseInfiniteLoopIfProxyReturnsEmptyArrayAndValidatorIsInitialized(): void { $element = $this->createPartialMock($this->element::class, ['setValueOptions']); @@ -91,6 +96,7 @@ public function testGetValueOptionsDoesntCauseInfiniteLoopIfProxyReturnsEmptyArr $this->assertEquals($options, $element->getValueOptions()); } + #[Test] public function testGetValueOptionsDoesntInvokeProxyIfOptionsNotEmpty(): void { $options = ['foo' => 'bar']; @@ -106,6 +112,7 @@ public function testGetValueOptionsDoesntInvokeProxyIfOptionsNotEmpty(): void $this->assertEquals($options, $this->element->getValueOptions()); } + #[Test] public function testOptionsCanBeSetSingle(): void { $proxy = $this->createMock(Proxy::class); diff --git a/tests/Form/Element/ProxyTest.php b/tests/Form/Element/ProxyTest.php index ba130c5a..228f64a0 100644 --- a/tests/Form/Element/ProxyTest.php +++ b/tests/Form/Element/ProxyTest.php @@ -11,6 +11,7 @@ use DoctrineModule\Form\Element\Exception\InvalidRepositoryResultException; use DoctrineModule\Form\Element\Proxy; use DoctrineModuleTest\Form\Element\TestAsset\FormObject; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use RuntimeException; @@ -43,6 +44,7 @@ protected function setUp(): void $this->proxy = new Proxy(); } + #[Test] public function testExceptionThrownForMissingObjectManager(): void { $this->expectException(RuntimeException::class); @@ -52,6 +54,7 @@ public function testExceptionThrownForMissingObjectManager(): void $this->proxy->getValueOptions(); } + #[Test] public function testExceptionThrownForMissingTargetClass(): void { $this->expectException(RuntimeException::class); @@ -63,6 +66,7 @@ public function testExceptionThrownForMissingTargetClass(): void $this->proxy->getValueOptions(); } + #[Test] public function testExceptionThrownForMissingFindMethodName(): void { $this->expectException(RuntimeException::class); @@ -86,6 +90,7 @@ public function testExceptionThrownForMissingFindMethodName(): void $this->proxy->getValueOptions(); } + #[Test] public function testExceptionFindMethodNameNotExistentInRepository(): void { $objectClass = FormObject::class; @@ -120,6 +125,7 @@ public function testExceptionFindMethodNameNotExistentInRepository(): void $this->proxy->getValueOptions(); } + #[Test] public function testExceptionThrownForMissingRequiredParameter(): void { $objectClass = FormObject::class; @@ -159,6 +165,7 @@ public function testExceptionThrownForMissingRequiredParameter(): void $this->proxy->getValueOptions(); } + #[Test] public function testToStringIsUsedForGetValueOptions(): void { $this->prepareProxy(); @@ -177,6 +184,7 @@ public function testToStringIsUsedForGetValueOptions(): void $this->assertEquals($result[1]['value'], 2); } + #[Test] public function testPropertyGetterUsedForGetValueOptions(): void { $this->prepareProxy(); @@ -195,6 +203,7 @@ public function testPropertyGetterUsedForGetValueOptions(): void $this->assertEquals($result[1]['value'], 2); } + #[Test] public function testPublicPropertyUsedForGetValueOptions(): void { $this->prepareProxy(); @@ -215,6 +224,7 @@ public function testPublicPropertyUsedForGetValueOptions(): void $this->assertEquals($result[1]['value'], 2); } + #[Test] public function testIsMethodOptionUsedForGetValueOptions(): void { $this->prepareProxy(); @@ -234,6 +244,7 @@ public function testIsMethodOptionUsedForGetValueOptions(): void $this->assertEquals($result[1]['value'], 2); } + #[Test] public function testDisplayEmptyItemAndEmptyItemLabelOptionsUsedForGetValueOptions(): void { $this->prepareProxy(); @@ -254,6 +265,7 @@ public function testDisplayEmptyItemAndEmptyItemLabelOptionsUsedForGetValueOptio $this->assertEquals($result[''], '---'); } + #[Test] public function testLabelGeneratorUsedForGetValueOptions(): void { $this->prepareProxy(); @@ -272,6 +284,7 @@ public function testLabelGeneratorUsedForGetValueOptions(): void $this->assertEquals($result[1]['value'], 2); } + #[Test] public function testExceptionThrownForNonCallableLabelGenerator(): void { $this->prepareProxy(); @@ -288,6 +301,7 @@ public function testExceptionThrownForNonCallableLabelGenerator(): void $this->proxy->setOptions(['label_generator' => 'I throw an invalid type error']); } + #[Test] public function testUsingOptionAttributesOfTypeString(): void { $this->prepareProxy(); @@ -321,6 +335,7 @@ public function testUsingOptionAttributesOfTypeString(): void $this->assertEquals($expectedAttributes, $options[1]['attributes']); } + #[Test] public function testUsingOptionAttributesOfTypeCallableReturningString(): void { $this->prepareProxy(); @@ -348,6 +363,7 @@ public function testUsingOptionAttributesOfTypeCallableReturningString(): void $this->assertEquals(['data-id' => 2], $options[1]['attributes']); } + #[Test] public function testRuntimeExceptionOnWrongOptionAttributesValue(): void { $this->prepareProxy(); @@ -365,6 +381,7 @@ public function testRuntimeExceptionOnWrongOptionAttributesValue(): void $this->proxy->getValueOptions(); } + #[Test] public function testCanWorkWithEmptyTables(): void { $this->prepareEmptyProxy(); @@ -373,6 +390,7 @@ public function testCanWorkWithEmptyTables(): void $this->assertEquals([], $result); } + #[Test] public function testCanWorkWithEmptyDataReturnedAsArray(): void { $this->prepareEmptyProxy([]); @@ -381,6 +399,7 @@ public function testCanWorkWithEmptyDataReturnedAsArray(): void $this->assertEquals([], $result); } + #[Test] public function testExceptionThrownForNonTraversableResults(): void { $this->prepareEmptyProxy(new stdClass()); @@ -395,6 +414,7 @@ public function testExceptionThrownForNonTraversableResults(): void $this->proxy->getValueOptions(); } + #[Test] public function testUsingFindMethod(): void { $this->prepareFilteredProxy(); @@ -413,6 +433,7 @@ public function testUsingFindMethod(): void * A \RuntimeException should be thrown when the optgroup_identifier option does not reflect an existing method * within the target object */ + #[Test] public function testExceptionThrownWhenOptgroupIdentifiesNotCallable(): void { $this->prepareProxyWithOptgroupPreset(); @@ -436,6 +457,7 @@ public function testExceptionThrownWhenOptgroupIdentifiesNotCallable(): void * * Entries should be grouped accordingly under the respective keys. */ + #[Test] public function testValueOptionsGeneratedProperlyWithOptgroups(): void { $this->prepareProxyWithOptgroupPreset(); @@ -492,6 +514,7 @@ public function testValueOptionsGeneratedProperlyWithOptgroups(): void * * Both entries should be grouped under the optgroup_default key. */ + #[Test] public function testEmptyOptgroupValueBelongsToOptgroupDefaultIfConfigured(): void { $this->prepareProxy(); @@ -540,6 +563,7 @@ public function testEmptyOptgroupValueBelongsToOptgroupDefaultIfConfigured(): vo * * Entry one should be grouped, entry two shouldn't be. */ + #[Test] public function testEmptyOptgroupValueBelongsToNoOptgroupIfNotConfigured(): void { $this->prepareProxyWithOptgroupPresetThatHasPartiallyEmptyOptgroupValues(); diff --git a/tests/ModuleTest.php b/tests/ModuleTest.php index bd79007e..e36817fd 100644 --- a/tests/ModuleTest.php +++ b/tests/ModuleTest.php @@ -8,6 +8,7 @@ use Laminas\Mvc\Application; use Laminas\Mvc\MvcEvent; use Laminas\ServiceManager\ServiceManager; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application as SymfonyApplication; @@ -60,6 +61,7 @@ protected function setUp(): void } /** @covers \DoctrineModule\Module::getConfig */ + #[Test] public function testGetConfig(): void { $module = new Module(); diff --git a/tests/Paginator/Adapter/CollectionAdapterTest.php b/tests/Paginator/Adapter/CollectionAdapterTest.php index 6e16f486..c90fcb4e 100644 --- a/tests/Paginator/Adapter/CollectionAdapterTest.php +++ b/tests/Paginator/Adapter/CollectionAdapterTest.php @@ -6,6 +6,7 @@ use Doctrine\Common\Collections\ArrayCollection; use DoctrineModule\Paginator\Adapter\Collection as CollectionAdapter; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use function range; @@ -27,6 +28,7 @@ protected function setUp(): void $this->adapter = new CollectionAdapter(new ArrayCollection(range(1, 101))); } + #[Test] public function testGetsItemsAtOffsetZero(): void { $expected = range(1, 10); @@ -34,6 +36,7 @@ public function testGetsItemsAtOffsetZero(): void $this->assertEquals($expected, $actual); } + #[Test] public function testGetsItemsAtOffsetTen(): void { $expected = range(11, 20); @@ -41,11 +44,13 @@ public function testGetsItemsAtOffsetTen(): void $this->assertEquals($expected, $actual); } + #[Test] public function testReturnsCorrectCount(): void { $this->assertEquals(101, $this->adapter->count()); } + #[Test] public function testEmptySet(): void { $adapter = new CollectionAdapter(new ArrayCollection()); diff --git a/tests/Paginator/Adapter/SelectableAdapterTest.php b/tests/Paginator/Adapter/SelectableAdapterTest.php index b8b6f954..ce62b74b 100644 --- a/tests/Paginator/Adapter/SelectableAdapterTest.php +++ b/tests/Paginator/Adapter/SelectableAdapterTest.php @@ -8,6 +8,7 @@ use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Collections\Selectable; use DoctrineModule\Paginator\Adapter\Selectable as SelectableAdapter; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use function range; @@ -18,6 +19,7 @@ class SelectableAdapterTest extends TestCase { /** @covers \DoctrineModule\Paginator\Adapter\Selectable::getItems */ + #[Test] public function testGetItemsAtOffsetZeroWithEmptyCriteria(): void { $selectable = $this->createMock(Selectable::class); @@ -47,6 +49,7 @@ static function (Criteria $criteria) use ($me) { } /** @covers \DoctrineModule\Paginator\Adapter\Selectable::getItems */ + #[Test] public function testGetItemsAtOffsetZeroWithNonEmptyCriteria(): void { $selectable = $this->createMock(Selectable::class); @@ -79,6 +82,7 @@ static function (Criteria $innerCriteria) use ($criteria, $me) { } /** @covers \DoctrineModule\Paginator\Adapter\Selectable::getItems */ + #[Test] public function testGetItemsAtOffsetTenWithEmptyCriteria(): void { $selectable = $this->createMock(Selectable::class); @@ -107,6 +111,7 @@ static function (Criteria $criteria) use ($me) { } /** @covers \DoctrineModule\Paginator\Adapter\Selectable::getItems */ + #[Test] public function testGetItemsAtOffsetTenWithNonEmptyCriteria(): void { $selectable = $this->createMock(Selectable::class); @@ -139,6 +144,7 @@ static function (Criteria $innerCriteria) use ($criteria, $me) { } /** @covers \DoctrineModule\Paginator\Adapter\Selectable::count */ + #[Test] public function testReturnsCorrectCount(): void { $selectable = $this->createMock(Selectable::class); @@ -153,7 +159,7 @@ public function testReturnsCorrectCount(): void static fn (Criteria $criteria) => $criteria->getWhereExpression() === $expression && ($criteria->getOrderings() === ['baz' => Criteria::DESC]) && $criteria->getFirstResult() === null - && $criteria->getMaxResults() === null + && $criteria->getMaxResults() === null, ), ) ->will($this->returnValue(new ArrayCollection(range(1, 101)))); diff --git a/tests/Service/Authentication/AdapterFactoryTest.php b/tests/Service/Authentication/AdapterFactoryTest.php index e50ab88e..256dd38e 100644 --- a/tests/Service/Authentication/AdapterFactoryTest.php +++ b/tests/Service/Authentication/AdapterFactoryTest.php @@ -9,10 +9,12 @@ use DoctrineModule\Service\Authentication\AdapterFactory; use DoctrineModuleTest\Authentication\Adapter\TestAsset\IdentityObject; use Laminas\ServiceManager\ServiceManager; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase as BaseTestCase; class AdapterFactoryTest extends BaseTestCase { + #[Test] public function testWillInstantiateFromFQCN(): void { $name = 'testFactory'; diff --git a/tests/Service/Authentication/AuthenticationServiceFactoryTest.php b/tests/Service/Authentication/AuthenticationServiceFactoryTest.php index 34d67d14..72c6f805 100644 --- a/tests/Service/Authentication/AuthenticationServiceFactoryTest.php +++ b/tests/Service/Authentication/AuthenticationServiceFactoryTest.php @@ -12,10 +12,12 @@ use Laminas\Authentication\AuthenticationService; use Laminas\Authentication\Storage\Session; use Laminas\ServiceManager\ServiceManager; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase as BaseTestCase; class AuthenticationServiceFactoryTest extends BaseTestCase { + #[Test] public function testWillInstantiateFromFQCN(): void { $name = 'testFactory'; diff --git a/tests/Service/Authentication/StorageFactoryTest.php b/tests/Service/Authentication/StorageFactoryTest.php index 9347b269..0ebee01c 100644 --- a/tests/Service/Authentication/StorageFactoryTest.php +++ b/tests/Service/Authentication/StorageFactoryTest.php @@ -11,10 +11,12 @@ use Laminas\Authentication\Storage\Session; use Laminas\Authentication\Storage\StorageInterface; use Laminas\ServiceManager\ServiceManager; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase as BaseTestCase; class StorageFactoryTest extends BaseTestCase { + #[Test] public function testWillInstantiateFromFQCN(): void { $name = 'testFactory'; @@ -47,6 +49,7 @@ public function testWillInstantiateFromFQCN(): void $this->assertInstanceOf(ObjectRepository::class, $adapter); } + #[Test] public function testCanInstantiateStorageFromServiceLocator(): void { $factory = new StorageFactory('testFactory'); diff --git a/tests/Service/CacheFactoryTest.php b/tests/Service/CacheFactoryTest.php index 40f1e7c2..c2e3c6f2 100644 --- a/tests/Service/CacheFactoryTest.php +++ b/tests/Service/CacheFactoryTest.php @@ -14,6 +14,7 @@ use Laminas\Cache\ConfigProvider; use Laminas\Cache\Storage\Adapter\Memory; use Laminas\ServiceManager\ServiceManager; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase as BaseTestCase; use Predis\ClientInterface; @@ -25,6 +26,7 @@ class CacheFactoryTest extends BaseTestCase { /** @covers \DoctrineModule\Service\CacheFactory::createService */ + #[Test] public function testWillSetNamespace(): void { if (! InstalledVersions::satisfies(new VersionParser(), 'doctrine/cache', '^1.0.0')) { @@ -58,6 +60,7 @@ public function testWillSetNamespace(): void * @covers \DoctrineModule\Service\CacheFactory::createService * @group 547 */ + #[Test] public function testCreateLaminasCache(): void { $factory = new CacheFactory('phpunit'); @@ -86,6 +89,7 @@ public function testCreateLaminasCache(): void $this->assertInstanceOf(LaminasStorageCache::class, $cache); } + #[Test] public function testCreatePredisCache(): void { if (! InstalledVersions::satisfies(new VersionParser(), 'doctrine/cache', '^1.0.0')) { @@ -117,6 +121,7 @@ public function testCreatePredisCache(): void $this->assertInstanceOf(PredisCache::class, $cache); } + #[Test] public function testUseServiceFactory(): void { if (! InstalledVersions::satisfies(new VersionParser(), 'doctrine/cache', '^1.0.0')) { diff --git a/tests/Service/DriverFactoryTest.php b/tests/Service/DriverFactoryTest.php index 254df2c9..c197aad5 100644 --- a/tests/Service/DriverFactoryTest.php +++ b/tests/Service/DriverFactoryTest.php @@ -15,6 +15,7 @@ use DoctrineModuleTest\Service\Mock\MetadataDriverMock; use Laminas\Cache\Storage\Adapter\Memory; use Laminas\ServiceManager\ServiceManager; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase as BaseTestCase; use function assert; @@ -24,6 +25,7 @@ */ class DriverFactoryTest extends BaseTestCase { + #[Test] public function testCreateDriver(): void { $serviceManager = new ServiceManager(); @@ -43,6 +45,7 @@ public function testCreateDriver(): void $this->assertInstanceOf(MetadataDriverMock::class, $driver); } + #[Test] public function testCreateDriverChain(): void { $serviceManager = new ServiceManager(); @@ -75,7 +78,7 @@ public function testCreateDriverChain(): void $this->assertInstanceOf(MetadataDriverMock::class, $drivers['Foo\Bar']); } - /** @requires PHP 8.0 */ + #[Test] public function testCreateORMAttributeDriver(): void { $serviceManager = new ServiceManager(); @@ -95,7 +98,7 @@ public function testCreateORMAttributeDriver(): void $this->assertInstanceOf(ORMAttributeDriver::class, $driver); } - /** @requires PHP 8.0 */ + #[Test] public function testCreateMongoDBODMAttributeDriver(): void { $serviceManager = new ServiceManager(); @@ -115,6 +118,7 @@ public function testCreateMongoDBODMAttributeDriver(): void $this->assertInstanceOf(MongoDBODMAttributeDriver::class, $driver); } + #[Test] public function testCreateORMAnnotationDriver(): void { $serviceManager = new ServiceManager(); @@ -139,6 +143,7 @@ public function testCreateORMAnnotationDriver(): void $this->assertInstanceOf(Reader::class, $driver->getReader()); } + #[Test] public function testCreateMongoDBODMAnnotationDriver(): void { $serviceManager = new ServiceManager(); diff --git a/tests/Service/EventManagerFactoryTest.php b/tests/Service/EventManagerFactoryTest.php index db403fb6..62d8e86b 100644 --- a/tests/Service/EventManagerFactoryTest.php +++ b/tests/Service/EventManagerFactoryTest.php @@ -8,6 +8,7 @@ use DoctrineModule\Service\EventManagerFactory; use DoctrineModuleTest\Service\TestAsset\DummyEventSubscriber; use Laminas\ServiceManager\ServiceManager; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase as BaseTestCase; /** @@ -15,6 +16,7 @@ */ class EventManagerFactoryTest extends BaseTestCase { + #[Test] public function testWillInstantiateFromFQCN(): void { $name = 'eventManagerFactory'; @@ -43,6 +45,7 @@ public function testWillInstantiateFromFQCN(): void $this->assertCount(1, $listeners); } + #[Test] public function testWillAttachEventListenersFromConfiguredInstances(): void { $name = 'eventManagerFactory'; @@ -70,6 +73,7 @@ public function testWillAttachEventListenersFromConfiguredInstances(): void $this->assertContains($subscriber, $listeners); } + #[Test] public function testWillAttachEventListenersFromServiceManagerAlias(): void { $name = 'eventManagerFactory'; @@ -98,6 +102,7 @@ public function testWillAttachEventListenersFromServiceManagerAlias(): void $this->assertContains($subscriber, $listeners); } + #[Test] public function testWillRefuseNonExistingSubscriber(): void { $name = 'eventManagerFactory'; diff --git a/tests/ServiceFactory/ModuleDefinedServicesTest.php b/tests/ServiceFactory/ModuleDefinedServicesTest.php index 4cd13b5e..bb338673 100644 --- a/tests/ServiceFactory/ModuleDefinedServicesTest.php +++ b/tests/ServiceFactory/ModuleDefinedServicesTest.php @@ -14,6 +14,8 @@ use Laminas\Cache\Storage\Adapter\Memory; use Laminas\ServiceManager\Exception\ServiceNotFoundException; use Laminas\ServiceManager\ServiceLocatorInterface; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; /** @@ -30,9 +32,9 @@ protected function setUp(): void /** * Verifies that the module defines the correct services - * - * @dataProvider getServicesThatShouldBeDefined */ + #[Test] + #[DataProvider('getServicesThatShouldBeDefined')] public function testModuleDefinedServices(string $serviceName, bool $defined): void { $this->assertSame($defined, $this->serviceManager->has($serviceName)); @@ -40,9 +42,9 @@ public function testModuleDefinedServices(string $serviceName, bool $defined): v /** * Verifies that the module defines the correct services - * - * @dataProvider getServicesThatCanBeFetched */ + #[Test] + #[DataProvider('getServicesThatCanBeFetched')] public function testModuleFetchedService(string $serviceName, string $expectedClass): void { $this->assertInstanceOf($expectedClass, $this->serviceManager->get($serviceName)); @@ -50,9 +52,9 @@ public function testModuleFetchedService(string $serviceName, string $expectedCl /** * Verifies that the module defines the correct services - * - * @dataProvider getServicesThatCannotBeFetched */ + #[Test] + #[DataProvider('getServicesThatCannotBeFetched')] public function testModuleInvalidService(string $serviceName): void { $this->expectException(ServiceNotFoundException::class); @@ -61,7 +63,7 @@ public function testModuleInvalidService(string $serviceName): void } /** @return mixed[][] */ - public function getServicesThatShouldBeDefined(): array + public static function getServicesThatShouldBeDefined(): array { $legacyCacheShouldExist = InstalledVersions::satisfies(new VersionParser(), 'doctrine/cache', '^1.0'); @@ -92,7 +94,7 @@ public function getServicesThatShouldBeDefined(): array } /** @return string[][] */ - public function getServicesThatCanBeFetched(): array + public static function getServicesThatCanBeFetched(): array { if (InstalledVersions::satisfies(new VersionParser(), 'doctrine/cache', '^1.0')) { return [ @@ -110,7 +112,7 @@ public function getServicesThatCanBeFetched(): array } /** @return string[][] */ - public function getServicesThatCannotBeFetched(): array + public static function getServicesThatCannotBeFetched(): array { return [ ['foo'], diff --git a/tests/Validator/NoObjectExistsTest.php b/tests/Validator/NoObjectExistsTest.php index 112533e4..596e5f9d 100644 --- a/tests/Validator/NoObjectExistsTest.php +++ b/tests/Validator/NoObjectExistsTest.php @@ -6,6 +6,7 @@ use Doctrine\Persistence\ObjectRepository; use DoctrineModule\Validator\NoObjectExists; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase as BaseTestCase; use stdClass; @@ -16,6 +17,7 @@ */ class NoObjectExistsTest extends BaseTestCase { + #[Test] public function testCanValidateWithNoAvailableObjectInRepository(): void { $repository = $this->createMock(ObjectRepository::class); @@ -30,6 +32,7 @@ public function testCanValidateWithNoAvailableObjectInRepository(): void $this->assertTrue($validator->isValid('matchValue')); } + #[Test] public function testCannotValidateWithAvailableObjectInRepository(): void { $repository = $this->createMock(ObjectRepository::class); @@ -44,6 +47,7 @@ public function testCannotValidateWithAvailableObjectInRepository(): void $this->assertFalse($validator->isValid('matchValue')); } + #[Test] public function testErrorMessageIsStringInsteadArray(): void { $repository = $this->createMock(ObjectRepository::class); diff --git a/tests/Validator/ObjectExistsTest.php b/tests/Validator/ObjectExistsTest.php index c19ca9c1..89d94b45 100644 --- a/tests/Validator/ObjectExistsTest.php +++ b/tests/Validator/ObjectExistsTest.php @@ -8,6 +8,7 @@ use DoctrineModule\Validator\ObjectExists; use Laminas\Validator\Exception\InvalidArgumentException; use Laminas\Validator\Exception\RuntimeException; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase as BaseTestCase; use stdClass; @@ -20,6 +21,7 @@ */ class ObjectExistsTest extends BaseTestCase { + #[Test] public function testCanValidateWithSingleField(): void { $repository = $this->createMock(ObjectRepository::class); @@ -36,6 +38,7 @@ public function testCanValidateWithSingleField(): void $this->assertTrue($validator->isValid(['matchKey' => 'matchValue'])); } + #[Test] public function testCanValidateWithIntegerId(): void { $repository = $this->createMock(ObjectRepository::class); @@ -52,6 +55,7 @@ public function testCanValidateWithIntegerId(): void $this->assertTrue($validator->isValid(['matchKey' => 123])); } + #[Test] public function testCanValidateWithMultipleFields(): void { $repository = $this->createMock(ObjectRepository::class); @@ -77,6 +81,7 @@ public function testCanValidateWithMultipleFields(): void $this->assertTrue($validator->isValid(['firstMatchValue', 'secondMatchValue'])); } + #[Test] public function testCanValidateFalseOnNoResult(): void { $repository = $this->createMock(ObjectRepository::class); @@ -92,6 +97,7 @@ public function testCanValidateFalseOnNoResult(): void $this->assertFalse($validator->isValid('value')); } + #[Test] public function testWillRefuseMissingRepository(): void { $this->expectException(InvalidArgumentException::class); @@ -99,6 +105,7 @@ public function testWillRefuseMissingRepository(): void new ObjectExists(['fields' => 'field']); } + #[Test] public function testWillRefuseNonObjectRepository(): void { $this->expectException(InvalidArgumentException::class); @@ -106,6 +113,7 @@ public function testWillRefuseNonObjectRepository(): void new ObjectExists(['object_repository' => 'invalid', 'fields' => 'field']); } + #[Test] public function testWillRefuseInvalidRepository(): void { $this->expectException(InvalidArgumentException::class); @@ -113,6 +121,7 @@ public function testWillRefuseInvalidRepository(): void new ObjectExists(['object_repository' => new stdClass(), 'fields' => 'field']); } + #[Test] public function testWillRefuseMissingFields(): void { $this->expectException(InvalidArgumentException::class); @@ -122,6 +131,7 @@ public function testWillRefuseMissingFields(): void ]); } + #[Test] public function testWillRefuseEmptyFields(): void { $this->expectException(InvalidArgumentException::class); @@ -132,6 +142,7 @@ public function testWillRefuseEmptyFields(): void ]); } + #[Test] public function testWillRefuseNonStringFields(): void { $this->expectException(InvalidArgumentException::class); @@ -141,6 +152,7 @@ public function testWillRefuseNonStringFields(): void ]); } + #[Test] public function testWillNotValidateOnFieldsCountMismatch(): void { $this->expectException( @@ -156,6 +168,7 @@ public function testWillNotValidateOnFieldsCountMismatch(): void $validator->isValid(['field1Value']); } + #[Test] public function testWillNotValidateOnFieldKeysMismatch(): void { $this->expectException( @@ -173,6 +186,7 @@ public function testWillNotValidateOnFieldKeysMismatch(): void $validator->isValid(['field1' => 'field1Value']); } + #[Test] public function testErrorMessageIsStringInsteadArray(): void { $repository = $this->createMock(ObjectRepository::class); diff --git a/tests/Validator/Service/NoObjectExistsFactoryTest.php b/tests/Validator/Service/NoObjectExistsFactoryTest.php index aa7a9174..d30718d3 100644 --- a/tests/Validator/Service/NoObjectExistsFactoryTest.php +++ b/tests/Validator/Service/NoObjectExistsFactoryTest.php @@ -11,6 +11,7 @@ use DoctrineModule\Validator\Service\NoObjectExistsFactory; use DoctrineModuleTest\Validator\TestAsset\DummyClass; use Laminas\ServiceManager\ServiceLocatorInterface; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -34,6 +35,7 @@ protected function setUp(): void } /** @coversNothing */ + #[Test] public function testCallable(): void { $this->assertIsCallable($this->object); @@ -46,6 +48,7 @@ public function testCallable(): void * @covers ::getObjectManager * @covers ::getFields */ + #[Test] public function testInvoke(): void { $options = [ @@ -83,6 +86,7 @@ public function testInvoke(): void * @covers ::getObjectManager * @covers ::getFields */ + #[Test] public function testInvokeWithObjectManagerGiven(): void { $repository = $this->createMock(ObjectRepository::class); @@ -114,6 +118,7 @@ public function testInvokeWithObjectManagerGiven(): void } /** @covers ::merge */ + #[Test] public function testInvokeWithMerge(): void { $options = [ @@ -148,6 +153,7 @@ public function testInvokeWithMerge(): void } /** @covers ::getRepository */ + #[Test] public function testInvokeWithoutTargetClass(): void { $this->expectException(ServiceCreationException::class); @@ -160,6 +166,7 @@ public function testInvokeWithoutTargetClass(): void ); } + #[Test] public function testInvokeWithOptions(): void { $options = [ diff --git a/tests/Validator/Service/ObjectExistsFactoryTest.php b/tests/Validator/Service/ObjectExistsFactoryTest.php index 34a38664..d36b1b35 100644 --- a/tests/Validator/Service/ObjectExistsFactoryTest.php +++ b/tests/Validator/Service/ObjectExistsFactoryTest.php @@ -9,6 +9,7 @@ use DoctrineModule\Validator\ObjectExists; use DoctrineModule\Validator\Service\ObjectExistsFactory; use DoctrineModuleTest\Validator\TestAsset\DummyClass; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -32,6 +33,7 @@ protected function setUp(): void } /** @covers ::__invoke */ + #[Test] public function testInvoke(): void { $options = [ diff --git a/tests/Validator/Service/UniqueObjectFactoryTest.php b/tests/Validator/Service/UniqueObjectFactoryTest.php index 46f4b97a..e6270397 100644 --- a/tests/Validator/Service/UniqueObjectFactoryTest.php +++ b/tests/Validator/Service/UniqueObjectFactoryTest.php @@ -9,6 +9,7 @@ use DoctrineModule\Validator\Service\UniqueObjectFactory; use DoctrineModule\Validator\UniqueObject; use DoctrineModuleTest\Validator\TestAsset\DummyClass; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -32,6 +33,7 @@ protected function setUp(): void } /** @covers ::__invoke */ + #[Test] public function testInvoke(): void { $options = [ diff --git a/tests/Validator/UniqueObjectTest.php b/tests/Validator/UniqueObjectTest.php index 14aa14fc..632ede85 100644 --- a/tests/Validator/UniqueObjectTest.php +++ b/tests/Validator/UniqueObjectTest.php @@ -11,6 +11,7 @@ use DoctrineModule\Validator\UniqueObject; use InvalidArgumentException; use Laminas\Validator\Exception\RuntimeException; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase as BaseTestCase; use stdClass; @@ -22,6 +23,7 @@ */ class UniqueObjectTest extends BaseTestCase { + #[Test] public function testCanValidateWithNotAvailableObjectInRepository(): void { $repository = $this->createMock(ObjectRepository::class); @@ -41,6 +43,7 @@ public function testCanValidateWithNotAvailableObjectInRepository(): void $this->assertTrue($validator->isValid('matchValue')); } + #[Test] public function testCanValidateIfThereIsTheSameObjectInTheRepository(): void { $match = new stdClass(); @@ -81,6 +84,7 @@ public function testCanValidateIfThereIsTheSameObjectInTheRepository(): void $this->assertTrue($validator->isValid(['matchKey' => 'matchValue', 'id' => 'identifier'])); } + #[Test] public function testCannotValidateIfThereIsAnotherObjectWithTheSameValueInTheRepository(): void { $match = new stdClass(); @@ -121,6 +125,7 @@ public function testCannotValidateIfThereIsAnotherObjectWithTheSameValueInTheRep $this->assertFalse($validator->isValid(['matchKey' => 'matchValue', 'id' => 'another identifier'])); } + #[Test] public function testCanFetchIdentifierFromContext(): void { $match = new stdClass(); @@ -162,6 +167,7 @@ public function testCanFetchIdentifierFromContext(): void $this->assertTrue($validator->isValid('matchValue', ['id' => 'identifier'])); } + #[Test] public function testThrowsAnExceptionOnUsedButMissingContext(): void { $this->expectException(RuntimeException::class); @@ -187,6 +193,7 @@ public function testThrowsAnExceptionOnUsedButMissingContext(): void $validator->isValid('matchValue'); } + #[Test] public function testThrowsAnExceptionOnMissingIdentifier(): void { $this->expectException(RuntimeException::class); @@ -225,6 +232,7 @@ public function testThrowsAnExceptionOnMissingIdentifier(): void $validator->isValid('matchValue'); } + #[Test] public function testThrowsAnExceptionOnMissingIdentifierInContext(): void { $this->expectException(RuntimeException::class); @@ -264,6 +272,7 @@ public function testThrowsAnExceptionOnMissingIdentifierInContext(): void $validator->isValid('matchValue', []); } + #[Test] public function testThrowsAnExceptionOnMissingObjectManager(): void { $this->expectException(InvalidArgumentException::class); @@ -280,6 +289,7 @@ public function testThrowsAnExceptionOnMissingObjectManager(): void ]); } + #[Test] public function testThrowsAnExceptionOnWrongObjectManager(): void { $this->expectException(InvalidArgumentException::class); @@ -299,6 +309,7 @@ public function testThrowsAnExceptionOnWrongObjectManager(): void ]); } + #[Test] public function testCanValidateWithNotAvailableObjectInRepositoryByDateTimeObject(): void { $date = new DateTime('17 March 2014'); @@ -320,6 +331,7 @@ public function testCanValidateWithNotAvailableObjectInRepositoryByDateTimeObjec $this->assertTrue($validator->isValid($date)); } + #[Test] public function testCanFetchIdentifierFromObjectContext(): void { $context = new stdClass(); @@ -363,6 +375,7 @@ public function testCanFetchIdentifierFromObjectContext(): void $this->assertTrue($validator->isValid('matchValue', $context)); } + #[Test] public function testErrorMessageIsStringInsteadArray(): void { $match = new stdClass(); From 1640553e8e56b934ff4fc700fe2046a3483c1d97 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Mon, 5 Aug 2024 18:52:36 -0600 Subject: [PATCH 3/4] Change ->will to ->willReturn --- .../Adapter/ObjectRepositoryTest.php | 18 +++++++++--------- .../Storage/ObjectRepositoryTest.php | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/Authentication/Adapter/ObjectRepositoryTest.php b/tests/Authentication/Adapter/ObjectRepositoryTest.php index 04c971ce..23df70c0 100644 --- a/tests/Authentication/Adapter/ObjectRepositoryTest.php +++ b/tests/Authentication/Adapter/ObjectRepositoryTest.php @@ -117,13 +117,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([ @@ -145,7 +145,7 @@ public function testAuthentication(): void $result->getIdentity(), ); - $method->will($this->returnValue(null)); + $method->willReturn(null); $result = $adapter->authenticate(); @@ -164,7 +164,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([ @@ -181,7 +181,7 @@ public function testAuthenticationWithPublicProperties(): void $this->assertTrue($result->isValid()); - $method->will($this->returnValue(null)); + $method->willReturn(null); $result = $adapter->authenticate(); @@ -198,7 +198,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([ @@ -226,7 +226,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([ @@ -260,7 +260,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([ @@ -295,7 +295,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 9007e670..5514dc1a 100644 --- a/tests/Authentication/Storage/ObjectRepositoryTest.php +++ b/tests/Authentication/Storage/ObjectRepositoryTest.php @@ -29,13 +29,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, From fe4f98de86028aebbf288009590aab48cc89352b Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Mon, 5 Aug 2024 18:58:16 -0600 Subject: [PATCH 4/4] gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 6cc8134c..21fa8269 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ /phpcs.xml /phpunit.xml /vendor/ +/.idea +/coverage/ +/.phpunit.cache/