From c7630a71ab3a29016e553b5cb38b3aaa3a40157e Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 11 Jun 2021 11:32:51 -0500 Subject: [PATCH 1/2] qa: add Psalm and its PHPUnit plugin as dev requirements Also provide initial configuration for Psalm. Signed-off-by: Matthew Weier O'Phinney --- composer.json | 6 ++++-- composer.lock | 2 +- psalm.xml.dist | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 psalm.xml.dist diff --git a/composer.json b/composer.json index 42fcdedb..06d4dd19 100644 --- a/composer.json +++ b/composer.json @@ -42,9 +42,9 @@ }, "require-dev": { "doctrine/dbal": "^2.12.1 || ^3.0.0", - "doctrine/orm": "^2.7.5", "doctrine/doctrine-mongo-odm-module": "^1.0 || ^2.0.2 || ^3.0.2", "doctrine/doctrine-orm-module": "^2.1.3", + "doctrine/orm": "^2.7.5", "laminas-api-tools/api-tools-provider": "^1.2", "laminas/laminas-coding-standard": "~2.1.4", "laminas/laminas-i18n": "^2.7.3", @@ -53,7 +53,9 @@ "laminas/laminas-test": "^2.6.1 || ^3.0.1", "phpspec/prophecy-phpunit": "^2.0", "phpunit/phpunit": "^9.5.0", - "symfony/yaml": "^2.3 || ^3.0 || ^4.0" + "psalm/plugin-phpunit": "^0.15", + "symfony/yaml": "^2.3 || ^3.0 || ^4.0", + "vimeo/psalm": "^4.7" }, "suggest": { "doctrine/doctrine-mongo-odm-module": "^1.0 || ^2.0.2 || ^3.0.2, if you wish to use the Doctrine ODM", diff --git a/composer.lock b/composer.lock index 561cce01..028f12d0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9690f5460202ac20cf521738a0376263", + "content-hash": "bc532c98f0e3470797aec8cc89d26f5a", "packages": [ { "name": "brick/varexporter", diff --git a/psalm.xml.dist b/psalm.xml.dist new file mode 100644 index 00000000..b0bd5ec7 --- /dev/null +++ b/psalm.xml.dist @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From b058e8c991826543af2553390a030fad964613d1 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 11 Jun 2021 11:38:59 -0500 Subject: [PATCH 2/2] qa: apply suggestions from Psalm and establish a baseline Signed-off-by: Matthew Weier O'Phinney --- psalm-baseline.xml | 1250 +++++++++++++++++ src/Filter/Service/ODMFilterManager.php | 1 + src/Filter/Service/ORMFilterManager.php | 1 + src/Module.php | 1 + test/Filter/ODMFilterTest.php | 26 +- test/Filter/ODMTypeCasterTest.php | 16 +- test/Filter/ORMFilterTest.php | 34 +- test/Filter/ORMTypeCasterTest.php | 38 +- test/Hydrator/Strategy/CollectionLinkTest.php | 2 +- test/OrderBy/ODMOrderByTest.php | 2 +- test/OrderBy/ORMOrderByTest.php | 4 +- test/Query/Provider/DefaultOdmTest.php | 16 +- test/Query/Provider/DefaultOrmTest.php | 16 +- test/assets/module/Db/src/Db/Entity/Album.php | 15 +- .../assets/module/Db/src/Db/Entity/Artist.php | 15 +- .../DbMongo/src/DbMongo/Document/Meta.php | 21 +- 16 files changed, 1369 insertions(+), 89 deletions(-) create mode 100644 psalm-baseline.xml diff --git a/psalm-baseline.xml b/psalm-baseline.xml new file mode 100644 index 00000000..d74bbcea --- /dev/null +++ b/psalm-baseline.xml @@ -0,0 +1,1250 @@ + + + + + $params['type_caster'] ?? new TypeCaster() + + + $queryBuilder + + + + + $format + $option['field'] + $option['field'] + $option['field'] + $option['from'] + $option['to'] + + + $format + $from + $to + + + + + $format + $option['field'] + $option['field'] + $option['value'] + + + $format + $value + + + + + $format + $option['field'] + $option['field'] + $option['value'] + + + $format + $value + + + + + $format + $option['field'] + $option['field'] + $option['value'] + + + $format + $value + + + + + $format + $option['field'] + $option['field'] + $value + + + $format + $queryValues[] + $value + + + + + $option['field'] + + + + + $option['field'] + + + + + $format + $option['field'] + $option['field'] + $option['value'] + + + $format + $value + + + + + $format + $option['field'] + $option['field'] + $option['value'] + + + $format + $value + + + + + $option['field'] + $option['value'] + + + + + $format + $option['field'] + $option['field'] + $option['value'] + + + $format + $value + + + + + $format + $option['field'] + $option['field'] + $value + + + $format + $queryValues[] + $value + + + + + $option['field'] + $option['value'] + + + + + $value + $value + + + $metadata->fieldMappings[$field] + + + + + $params['type_caster'] ?? new TypeCaster() + + + $queryBuilder + + + + + $condition['type'] + $dqlParts['where']->getParts() + + + $condition['type'] + + + $condition + $filter + + + filter + getParts + + + + + $format + $format + $option['alias'] + $option['field'] + $option['field'] + $option['field'] + $option['from'] + $option['to'] + + + $format + $from + $to + + + + + $format + $option['field'] + $option['value'] + + + $format + $value + + + $option['alias'] + $option['field'] + + + + + $format + $option['field'] + $option['value'] + + + $format + $value + + + $option['alias'] + $option['field'] + + + + + $format + $option['field'] + $option['value'] + + + $format + $value + + + $option['alias'] + $option['field'] + + + + + $format + $option['field'] + $value + + + $format + $queryValues[] + $value + + + $option['alias'] + $option['field'] + + + + + $option['alias'] + $option['condition'] + $option['conditionType'] + $option['indexBy'] + + + $option['field'] + $option['parentAlias'] + + + + + $format + $option['field'] + $option['value'] + + + $format + $value + + + $option['alias'] + $option['field'] + + + + + $option['alias'] + $option['field'] + + + + + $option['alias'] + $option['field'] + + + + + $option['alias'] + $option['condition'] + $option['conditionType'] + $option['indexBy'] + + + $option['field'] + $option['parentAlias'] + + + + + $format + $option['field'] + $option['value'] + + + $format + $value + + + $option['alias'] + $option['field'] + + + + + $format + $option['field'] + $option['value'] + + + $format + $value + + + $option['alias'] + $option['field'] + + + + + $option['alias'] + $option['field'] + + + + + $format + $option['field'] + $option['value'] + + + $format + $value + + + $option['alias'] + $option['field'] + + + + + $format + $option['field'] + $value + + + $format + $queryValues[] + $value + + + $option['alias'] + $option['field'] + + + + + $option['alias'] + $option['field'] + + + + + $condition['type'] + $dqlParts['where']->getParts() + + + $condition['type'] + + + $condition + $filter + + + filter + getParts + + + + + $value + $value + $value + $value + $value + $value + + + $metadata->fieldMappings[$field] + + + format + + + + + getServiceLocator + + + $e->getCode() + + + $option['type'] + + + $option['type'] + + + $filter + $option + + + TypeCastInterface + + + filter + + + $serviceLocator->get(TypeCaster::class) + + + $instanceOf + + + + + getServiceLocator + + + $e->getCode() + + + $option['type'] + + + $option['type'] + + + $filter + $option + + + TypeCastInterface + + + filter + + + $serviceLocator->get(TypeCaster::class) + + + $instanceOf + + + + + $value + + + + + $value + + + + + $serviceManager + + + array|ArrayAccess + + + get + + + include __DIR__ . '/../config/module.config.php' + + + + + $params[0] + + + $queryBuilder + + + + + $option['direction'] + $option['direction'] + $option['field'] + + + + + $params[0] + + + $queryBuilder + + + + + $option['direction'] + $option['direction'] + + + $option['alias'] + $option['field'] + + + + + $e->getCode() + + + $option['type'] + + + $option['type'] + + + $option + $orderByHandler + + + orderBy + + + $instanceOf + + + + + $e->getCode() + + + $option['type'] + + + $option['type'] + + + $option + $orderByHandler + + + orderBy + + + $instanceOf + + + + + $metadata + + + $serviceLocator + + + $queryBuilder + $queryBuilder + $request[$this->getFilterKey()] + $request[$this->getOrderByKey()] + + + $config['api-tools-doctrine-querybuilder-options'] + $request[$this->getFilterKey()] + $request[$this->getOrderByKey()] + + + $config + $queryBuilder + $queryBuilder + $request + + + ODMFilterManager + ODMOrderByManager + array + int + string + string + + + count + execute + find + find + getQuery + toArray + + + $config['api-tools-doctrine-querybuilder-options'] + $config['filter_key'] + $config['order_by_key'] + $queryBuilder->getQuery()->execute()->count() + $this->getServiceLocator()->get(ODMFilterManager::class) + $this->getServiceLocator()->get(ODMOrderByManager::class) + + + getQuery + + + createQueryBuilder + createQueryBuilder + getQuery + + + + + $container + + + getServiceLocator + + + + + $serviceLocator + + + $queryBuilder + $queryBuilder + $request[$this->getFilterKey()] + $request[$this->getOrderByKey()] + + + $config['api-tools-doctrine-querybuilder-options'] + $request[$this->getFilterKey()] + $request[$this->getOrderByKey()] + + + $config + $queryBuilder + $request + + + ORMFilterManager + ORMOrderByManager + array + string + string + + + from + select + toArray + + + $config['api-tools-doctrine-querybuilder-options'] + $config['filter_key'] + $config['order_by_key'] + $this->getServiceLocator()->get(ORMFilterManager::class) + $this->getServiceLocator()->get(ORMOrderByManager::class) + + + getQuery + + + createQueryBuilder + getQuery + + + + + $container + + + getServiceLocator + + + + + HydratorPluginManagerInterface::class + + + HydratorPluginManagerInterface + + + + + $result + + + $config['dbname'] + $config['doctrine'] + $config['port'] + $config['server'] + $metadata[0] + + + $collection + $config + $config + $db + $filterManager + $metadata + $objectManager + $objectManager + $queryBuilder + $result + + + createQueryBuilder + execute + filter + flush + getAllMetadata + getMetadataFactory + getQuery + persist + persist + persist + persist + persist + remove + + + $config['port'] + $config['server'] + + + $db->meta + + + getConfig + + + + + $result + $result + $result + + + + + $objectManager + $result + + + $albumOneId + $albumSixId + $filterManager + $objectManager + $queryBuilder + $result + $this->objectManager + + + filter + from + getId + getId + getQuery + getResult + select + + + getId + getId + + + createQueryBuilder + + + + + $result + $result + $result + $result + $result + $result + $result + $result + + + + + Driver::class + + + + + Driver::class + + + + + setMethods + setMethods + + + $actual + + + array + + + getRoute + getRouteOptions + getRouteParams + method + will + + + expects + + + getTypeClass + + + + + $config['dbname'] + $config['doctrine'] + $config['port'] + $config['server'] + $metadata[0] + + + $collection + $config + $config + $db + $meta + $meta + $metadata + $objectManager + $objectManager + $orderByManager + $queryBuilder + $result + $result + + + createQueryBuilder + execute + flush + getAllMetadata + getMetadataFactory + getName + getName + getQuery + orderBy + persist + persist + persist + persist + persist + remove + + + $config['port'] + $config['server'] + + + $db->meta + + + getConfig + + + + + $objectManager + $result + $result + + + $metadata[0] + + + $artist + $artist + $metadata + $objectManager + $objectManager + $orderByManager + $queryBuilder + $result + $result + + + createQueryBuilder + from + getAllMetadata + getMetadataFactory + getName + getName + getQuery + getResult + orderBy + select + + + + + Driver::class + + + + + Driver::class + + + + + assertSame + assertSame + assertSame + assertSame + assertSame + + + $resourceEvent->reveal() + $resourceEvent->reveal() + $resourceEvent->reveal() + $resourceEvent->reveal() + $resourceEvent->reveal() + $resourceEvent->reveal() + $this->queryBuilder->reveal() + $this->queryBuilder->reveal() + $this->queryBuilder->reveal() + $this->queryBuilder->reveal() + $this->queryBuilder->reveal() + $this->queryBuilder->reveal() + + + $count + + + shouldBeCalledTimes + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + + + createQuery + createQuery + createQuery + createQuery + createQuery + createQuery + find + get + get + get + get + get + get + get + get + get + get + get + getCollectionTotal + getMetadataFactory + getMetadataFactory + getMetadataFactory + getMetadataFactory + getMetadataFactory + getPaginatedQuery + getQuery + has + has + has + has + has + has + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + + + + + assertSame + assertSame + assertSame + assertSame + assertSame + + + $this->objectManager->reveal() + + + $resourceEvent->reveal() + $resourceEvent->reveal() + $resourceEvent->reveal() + $resourceEvent->reveal() + $resourceEvent->reveal() + $resourceEvent->reveal() + $this->queryBuilder->reveal() + $this->queryBuilder->reveal() + $this->queryBuilder->reveal() + $this->queryBuilder->reveal() + $this->queryBuilder->reveal() + + + $count + + + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + willReturn + + + createQuery + createQuery + createQuery + createQuery + createQuery + createQuery + get + get + get + get + get + get + get + get + get + get + get + getClassMetadata + getClassMetadata + getClassMetadata + getClassMetadata + getClassMetadata + getCollectionTotal + getMetadataFactory + getPaginatedQuery + getQuery + getQuery + has + has + has + has + has + has + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + reveal + + + + + void + + + $config['modules'] + + + $config + + + $config + + + getNumberOfRequiredParameters + + + + + $artist + $createdAt + $id + $name + + + getArtist + getCreatedAt + getId + getName + + + + + $album + $createdAt + $id + $name + + + getAlbum + getCreatedAt + getId + getName + + + $this->album[] + $this->album[] + + + add + removeElement + + + $album instanceof Album + $album instanceof Album + + + + + array + + + include __DIR__ . '/../../config/module.config.php' + + + + + $values + + + $createdAt + $description + $id + $name + + + getCreatedAt + getDescription + getId + getName + + + $values['createdAt'] ?? null + + + $values['createdAt'] + $values['name'] + + + $name + + + $values['createdAt'] ?? null + + + + + array + + + include __DIR__ . '/../../config/module.config.php' + + + + + DocumentRepository + + + diff --git a/src/Filter/Service/ODMFilterManager.php b/src/Filter/Service/ODMFilterManager.php index 033803ed..4241984a 100644 --- a/src/Filter/Service/ODMFilterManager.php +++ b/src/Filter/Service/ODMFilterManager.php @@ -31,6 +31,7 @@ class ODMFilterManager extends AbstractPluginManager /** * @param iterable $filters + * @return void */ public function filter(QueryBuilder $queryBuilder, Metadata $metadata, $filters) { diff --git a/src/Filter/Service/ORMFilterManager.php b/src/Filter/Service/ORMFilterManager.php index 7b0d09ce..41b90cbc 100644 --- a/src/Filter/Service/ORMFilterManager.php +++ b/src/Filter/Service/ORMFilterManager.php @@ -31,6 +31,7 @@ class ORMFilterManager extends AbstractPluginManager /** * @param object $metadata * @param iterable $filters + * @return void */ public function filter(QueryBuilder $queryBuilder, $metadata, $filters) { diff --git a/src/Module.php b/src/Module.php index 26a97ab2..7072d4f3 100644 --- a/src/Module.php +++ b/src/Module.php @@ -23,6 +23,7 @@ public function getConfig() return include __DIR__ . '/../config/module.config.php'; } + /** @return void */ public function init(ModuleManager $moduleManager) { $serviceManager = $moduleManager->getEvent()->getParam('ServiceManager'); diff --git a/test/Filter/ODMFilterTest.php b/test/Filter/ODMFilterTest.php index 18014984..8e952593 100644 --- a/test/Filter/ODMFilterTest.php +++ b/test/Filter/ODMFilterTest.php @@ -81,7 +81,7 @@ public function setUp(): void $objectManager->flush(); } - public function testEquals() + public function testEquals(): void { $filters = [ ['field' => 'name', 'type' => 'eq', 'value' => 'MetaOne'], @@ -121,7 +121,7 @@ public function testEquals() $this->assertEquals(2, $this->countResult($filters)); } - public function testNotEquals() + public function testNotEquals(): void { $filters = [ ['field' => 'name', 'type' => 'neq', 'value' => 'MetaOne'], @@ -161,7 +161,7 @@ public function testNotEquals() $this->assertEquals(3, $this->countResult($filters)); } - public function testLessThan() + public function testLessThan(): void { $filters = [ [ @@ -203,7 +203,7 @@ public function testLessThan() $this->assertEquals(3, $this->countResult($filters)); } - public function testLessThanOrEquals() + public function testLessThanOrEquals(): void { $filters = [ [ @@ -255,7 +255,7 @@ public function testLessThanOrEquals() $this->assertEquals(4, $this->countResult($filters)); } - public function testGreaterThan() + public function testGreaterThan(): void { $filters = [ [ @@ -300,7 +300,7 @@ public function testGreaterThan() $this->assertEquals(1, $this->countResult($filters)); } - public function testGreaterThanOrEquals() + public function testGreaterThanOrEquals(): void { $filters = [ [ @@ -354,7 +354,7 @@ public function testGreaterThanOrEquals() $this->assertEquals(3, $this->countResult($filters)); } - public function testIsNull() + public function testIsNull(): void { $filters = [ [ @@ -425,7 +425,7 @@ public function testIsNull() $this->assertEquals(5, $this->countResult($filters)); } - public function testIsNotNull() + public function testIsNotNull(): void { $filters = [ [ @@ -496,7 +496,7 @@ public function testIsNotNull() $this->assertEquals(0, $this->countResult($filters)); } - public function testIn() + public function testIn(): void { // Date handling in IN and NOTIN doesn't seem to work at all, so just test with strings @@ -541,7 +541,7 @@ public function testIn() $this->assertEquals(1, $this->countResult($filters)); } - public function testNotIn() + public function testNotIn(): void { $filters = [ [ @@ -585,7 +585,7 @@ public function testNotIn() $this->assertEquals(4, $this->countResult($filters)); } - public function testBetween() + public function testBetween(): void { $filters = [ [ @@ -626,7 +626,7 @@ public function testBetween() $this->assertEquals(2, $this->countResult($filters)); } - public function testLike() + public function testLike(): void { $filters = [ [ @@ -677,7 +677,7 @@ public function testLike() $this->assertEquals(4, $this->countResult($filters)); } - public function testRegex() + public function testRegex(): void { $filters = [ [ diff --git a/test/Filter/ODMTypeCasterTest.php b/test/Filter/ODMTypeCasterTest.php index 4e8dcac0..09f4ce89 100644 --- a/test/Filter/ODMTypeCasterTest.php +++ b/test/Filter/ODMTypeCasterTest.php @@ -24,7 +24,7 @@ protected function setUp(): void $this->typeCaster = new TypeCaster(); } - public function testTypeCastingToInteger() + public function testTypeCastingToInteger(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -42,7 +42,7 @@ public function testTypeCastingToInteger() $this->assertSame(2144211244, $result); } - public function testTypeCastingToBoolean() + public function testTypeCastingToBoolean(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -64,7 +64,7 @@ public function testTypeCastingToBoolean() $this->assertSame(false, $result); } - public function testTypeCastingToFloat() + public function testTypeCastingToFloat(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -82,7 +82,7 @@ public function testTypeCastingToFloat() $this->assertSame(1.242, $result); } - public function testTypeCastingToString() + public function testTypeCastingToString(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -101,7 +101,7 @@ public function testTypeCastingToString() $this->assertSame('1', $result); } - public function testTypeCastingToDate() + public function testTypeCastingToDate(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -120,7 +120,7 @@ public function testTypeCastingToDate() $this->assertEquals($result->format('Y-m-d H:i:s'), '2019-09-01 12:19:01'); } - public function testNoTypeCastingToDateWhenFlaggedSo() + public function testNoTypeCastingToDateWhenFlaggedSo(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -138,7 +138,7 @@ public function testNoTypeCastingToDateWhenFlaggedSo() $this->assertSame($result, $value); } - public function testTypeCastingToDateImmutable() + public function testTypeCastingToDateImmutable(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -157,7 +157,7 @@ public function testTypeCastingToDateImmutable() $this->assertEquals($result->format('Y-m-d H:i:s'), '2019-09-01 12:19:01'); } - public function testNoTypeCastingToDateImmutableWhenFlaggedSo() + public function testNoTypeCastingToDateImmutableWhenFlaggedSo(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ diff --git a/test/Filter/ORMFilterTest.php b/test/Filter/ORMFilterTest.php index eec63550..380d8aaa 100644 --- a/test/Filter/ORMFilterTest.php +++ b/test/Filter/ORMFilterTest.php @@ -101,7 +101,7 @@ public function setUp(): void $objectManager->flush(); } - public function testOrX() + public function testOrX(): void { $filters = [ [ @@ -149,7 +149,7 @@ public function testOrX() self::assertEquals(1, $this->countResult($filters)); } - public function testAndX() + public function testAndX(): void { $filters = [ [ @@ -198,7 +198,7 @@ public function testAndX() self::assertEquals(2, $this->countResult($filters)); } - public function testEquals() + public function testEquals(): void { $filters = [ [ @@ -242,7 +242,7 @@ public function testEquals() self::assertEquals(2, $this->countResult($filters)); } - public function testNotEquals() + public function testNotEquals(): void { $filters = [ [ @@ -286,7 +286,7 @@ public function testNotEquals() self::assertEquals(2, $this->countResult($filters)); } - public function testLessThan() + public function testLessThan(): void { $filters = [ [ @@ -328,7 +328,7 @@ public function testLessThan() self::assertEquals(3, $this->countResult($filters)); } - public function testLessThanOrEquals() + public function testLessThanOrEquals(): void { $filters = [ [ @@ -380,7 +380,7 @@ public function testLessThanOrEquals() self::assertEquals(4, $this->countResult($filters)); } - public function testGreaterThan() + public function testGreaterThan(): void { $filters = [ [ @@ -425,7 +425,7 @@ public function testGreaterThan() self::assertEquals(1, $this->countResult($filters)); } - public function testGreaterThanOrEquals() + public function testGreaterThanOrEquals(): void { $filters = [ [ @@ -479,10 +479,10 @@ public function testGreaterThanOrEquals() self::assertEquals(3, $this->countResult($filters)); } - public function testIsNull() + public function testIsNull(): void { $serviceManager = $this->getApplication()->getServiceManager(); - $objectManager = $serviceManager->get('doctrine.entitymanager.orm_default'); + $serviceManager->get('doctrine.entitymanager.orm_default'); $filters = [ [ @@ -520,7 +520,7 @@ public function testIsNull() self::assertEquals(2, $this->countResult($filters)); } - public function testIsNotNull() + public function testIsNotNull(): void { $filters = [ [ @@ -558,7 +558,7 @@ public function testIsNotNull() self::assertEquals(5, $this->countResult($filters)); } - public function testIn() + public function testIn(): void { $filters = [ [ @@ -597,7 +597,7 @@ public function testIn() self::assertEquals(1, $this->countResult($filters)); } - public function testNotIn() + public function testNotIn(): void { $filters = [ [ @@ -638,7 +638,7 @@ public function testNotIn() self::assertEquals(3, $this->countResult($filters)); } - public function testBetween() + public function testBetween(): void { $filters = [ [ @@ -771,7 +771,7 @@ public function testNotLike(): void self::assertEquals(1, $this->countResult($filters)); } - public function testIsMemberOf() + public function testIsMemberOf(): void { $albumOneId = $this->objectManager ->getRepository('Db\Entity\Album') @@ -803,7 +803,7 @@ public function testIsMemberOf() self::assertEquals(0, $this->countResult($filters)); } - public function testInnerJoin() + public function testInnerJoin(): void { $filters = [ [ @@ -852,7 +852,7 @@ public function testInnerJoin() self::assertEquals(2, $this->countResult($filters, Album::class)); } - public function testLeftJoin() + public function testLeftJoin(): void { $filters = [ [ diff --git a/test/Filter/ORMTypeCasterTest.php b/test/Filter/ORMTypeCasterTest.php index 1932917f..aaa34dd9 100644 --- a/test/Filter/ORMTypeCasterTest.php +++ b/test/Filter/ORMTypeCasterTest.php @@ -24,7 +24,7 @@ protected function setUp(): void $this->typeCaster = new TypeCaster(); } - public function testTypeCastingToString() + public function testTypeCastingToString(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -43,7 +43,7 @@ public function testTypeCastingToString() $this->assertSame('1', $result); } - public function testTypeCastingToInteger() + public function testTypeCastingToInteger(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -61,7 +61,7 @@ public function testTypeCastingToInteger() $this->assertSame(2144211244, $result); } - public function testTypeCastingToSmallint() + public function testTypeCastingToSmallint(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -79,7 +79,7 @@ public function testTypeCastingToSmallint() $this->assertSame(2, $result); } - public function testTypeCastingToBoolean() + public function testTypeCastingToBoolean(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -101,7 +101,7 @@ public function testTypeCastingToBoolean() $this->assertSame(false, $result); } - public function testTypeCastingToDecimal() + public function testTypeCastingToDecimal(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -119,7 +119,7 @@ public function testTypeCastingToDecimal() $this->assertSame(1.141, $result); } - public function testTypeCastingToFloat() + public function testTypeCastingToFloat(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -137,7 +137,7 @@ public function testTypeCastingToFloat() $this->assertSame(1.242, $result); } - public function testTypeCastingToDate() + public function testTypeCastingToDate(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -157,7 +157,7 @@ public function testTypeCastingToDate() $this->assertEquals($result->format('H:i:s'), '00:00:00'); } - public function testNoTypeCastingToDateWhenFlaggedSo() + public function testNoTypeCastingToDateWhenFlaggedSo(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -175,7 +175,7 @@ public function testNoTypeCastingToDateWhenFlaggedSo() $this->assertSame($result, $value); } - public function testTypeCastingToDateImmutable() + public function testTypeCastingToDateImmutable(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -195,7 +195,7 @@ public function testTypeCastingToDateImmutable() $this->assertEquals($result->format('H:i:s'), '00:00:00'); } - public function testNoTypeCastingToDateImmutableWhenFlaggedSo() + public function testNoTypeCastingToDateImmutableWhenFlaggedSo(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -213,7 +213,7 @@ public function testNoTypeCastingToDateImmutableWhenFlaggedSo() $this->assertSame($result, $value); } - public function testTypeCastingToTime() + public function testTypeCastingToTime(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -232,7 +232,7 @@ public function testTypeCastingToTime() $this->assertEquals($result->format('H:i:s'), '12:01:55'); } - public function testNoTypeCastingToTimeWhenFlaggedSo() + public function testNoTypeCastingToTimeWhenFlaggedSo(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -250,7 +250,7 @@ public function testNoTypeCastingToTimeWhenFlaggedSo() $this->assertSame($result, $value); } - public function testTypeCastingToTimeImmutable() + public function testTypeCastingToTimeImmutable(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -269,7 +269,7 @@ public function testTypeCastingToTimeImmutable() $this->assertEquals($result->format('H:i:s'), '12:01:55'); } - public function testNoTypeCastingToTimeImmutableWhenFlaggedSo() + public function testNoTypeCastingToTimeImmutableWhenFlaggedSo(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -287,7 +287,7 @@ public function testNoTypeCastingToTimeImmutableWhenFlaggedSo() $this->assertSame($result, $value); } - public function testTypeCastingToDateTime() + public function testTypeCastingToDateTime(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -307,7 +307,7 @@ public function testTypeCastingToDateTime() $this->assertEquals($result->format('H:i:s'), '12:03:44'); } - public function testNoTypeCastingToDateTimeWhenFlaggedSo() + public function testNoTypeCastingToDateTimeWhenFlaggedSo(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -325,7 +325,7 @@ public function testNoTypeCastingToDateTimeWhenFlaggedSo() $this->assertSame($result, $value); } - public function testTypeCastingToDateTimeImmutable() + public function testTypeCastingToDateTimeImmutable(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -345,7 +345,7 @@ public function testTypeCastingToDateTimeImmutable() $this->assertEquals($result->format('H:i:s'), '12:03:44'); } - public function testNoTypeCastingToDateTimeImmutableWhenFlaggedSo() + public function testNoTypeCastingToDateTimeImmutableWhenFlaggedSo(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ @@ -363,7 +363,7 @@ public function testNoTypeCastingToDateTimeImmutableWhenFlaggedSo() $this->assertSame($result, $value); } - public function testTypeCastingForUnknownFieldType() + public function testTypeCastingForUnknownFieldType(): void { $metadata = new stdClass(); $metadata->fieldMappings = [ diff --git a/test/Hydrator/Strategy/CollectionLinkTest.php b/test/Hydrator/Strategy/CollectionLinkTest.php index 5e226d37..814af605 100644 --- a/test/Hydrator/Strategy/CollectionLinkTest.php +++ b/test/Hydrator/Strategy/CollectionLinkTest.php @@ -208,7 +208,7 @@ public function mappingDataProvider(): array * @param array $mapping * @param array $expected */ - public function testStuff(array $mapping, array $expected) + public function testStuff(array $mapping, array $expected): void { $this->mockValue->expects($this->any()) ->method('getMapping') diff --git a/test/OrderBy/ODMOrderByTest.php b/test/OrderBy/ODMOrderByTest.php index 000a20c6..ab1257cc 100644 --- a/test/OrderBy/ODMOrderByTest.php +++ b/test/OrderBy/ODMOrderByTest.php @@ -78,7 +78,7 @@ public function setUp(): void $objectManager->flush(); } - public function testField() + public function testField(): void { $orderBy = [ ['type' => 'field', 'field' => 'name', 'direction' => 'asc'], diff --git a/test/OrderBy/ORMOrderByTest.php b/test/OrderBy/ORMOrderByTest.php index 846e516b..84df41d6 100644 --- a/test/OrderBy/ORMOrderByTest.php +++ b/test/OrderBy/ORMOrderByTest.php @@ -48,7 +48,7 @@ public function setUp(): void $objectManager = $serviceManager->get('doctrine.entitymanager.orm_default'); $tool = new SchemaTool($objectManager); - $res = $tool->createSchema($objectManager->getMetadataFactory()->getAllMetadata()); + $tool->createSchema($objectManager->getMetadataFactory()->getAllMetadata()); $artist1 = new Entity\Artist(); $artist1->setName('ABBA'); @@ -77,7 +77,7 @@ public function setUp(): void $objectManager->flush(); } - public function testField() + public function testField(): void { $orderBy = [ [ diff --git a/test/Query/Provider/DefaultOdmTest.php b/test/Query/Provider/DefaultOdmTest.php index 6871f4a9..d1122f85 100644 --- a/test/Query/Provider/DefaultOdmTest.php +++ b/test/Query/Provider/DefaultOdmTest.php @@ -56,7 +56,7 @@ public function setUp(): void $this->provider->setObjectManager($this->objectManager->reveal()); } - public function testCreateQueryWithoutParams() + public function testCreateQueryWithoutParams(): void { $resourceEvent = $this->getResourceEvent(); @@ -65,7 +65,7 @@ public function testCreateQueryWithoutParams() $this->assertInstanceOf(QueryBuilder::class, $result); } - public function testCreateQueryWithFilterParameter() + public function testCreateQueryWithFilterParameter(): void { $entityClass = 'foo.entity.class'; @@ -90,7 +90,7 @@ public function testCreateQueryWithFilterParameter() $this->assertSame($this->queryBuilder->reveal(), $result); } - public function testCreateQueryWithRenamedFilterParameter() + public function testCreateQueryWithRenamedFilterParameter(): void { $entityClass = 'foo.entity.class'; @@ -119,7 +119,7 @@ public function testCreateQueryWithRenamedFilterParameter() $this->assertSame($this->queryBuilder->reveal(), $result); } - public function testCreateQueryWithOrderByParameter() + public function testCreateQueryWithOrderByParameter(): void { $entityClass = 'foo.entity.class'; @@ -144,7 +144,7 @@ public function testCreateQueryWithOrderByParameter() $this->assertSame($this->queryBuilder->reveal(), $result); } - public function testCreateQueryWithRenamedOrderByParameter() + public function testCreateQueryWithRenamedOrderByParameter(): void { $entityClass = 'foo.entity.class'; @@ -173,7 +173,7 @@ public function testCreateQueryWithRenamedOrderByParameter() $this->assertSame($this->queryBuilder->reveal(), $result); } - public function testCreateQueryWithFilterAndOrderByParameters() + public function testCreateQueryWithFilterAndOrderByParameters(): void { $entityClass = 'foo.entity.class'; @@ -206,14 +206,14 @@ public function testCreateQueryWithFilterAndOrderByParameters() $this->assertSame($this->queryBuilder->reveal(), $result); } - public function testGetPaginatedQuery() + public function testGetPaginatedQuery(): void { $adapter = $this->provider->getPaginatedQuery($this->queryBuilder->reveal()); $this->assertInstanceOf(DoctrineOdmAdapter::class, $adapter); } - public function testGetCollectionTotal() + public function testGetCollectionTotal(): void { $entityClass = 'foo.entity.class'; diff --git a/test/Query/Provider/DefaultOrmTest.php b/test/Query/Provider/DefaultOrmTest.php index 94cc5ce0..18607249 100644 --- a/test/Query/Provider/DefaultOrmTest.php +++ b/test/Query/Provider/DefaultOrmTest.php @@ -58,7 +58,7 @@ public function setUp(): void $this->provider->setObjectManager($this->objectManager->reveal()); } - public function testCreateQueryWithoutParams() + public function testCreateQueryWithoutParams(): void { $resourceEvent = $this->getResourceEvent(); @@ -67,7 +67,7 @@ public function testCreateQueryWithoutParams() $this->assertInstanceOf(QueryBuilder::class, $result); } - public function testCreateQueryWithFilterParameter() + public function testCreateQueryWithFilterParameter(): void { $entityClass = 'foo.entity.class'; @@ -89,7 +89,7 @@ public function testCreateQueryWithFilterParameter() $this->assertSame($this->queryBuilder->reveal(), $result); } - public function testCreateQueryWithRenamedFilterParameter() + public function testCreateQueryWithRenamedFilterParameter(): void { $entityClass = 'foo.entity.class'; @@ -115,7 +115,7 @@ public function testCreateQueryWithRenamedFilterParameter() $this->assertSame($this->queryBuilder->reveal(), $result); } - public function testCreateQueryWithOrderByParameter() + public function testCreateQueryWithOrderByParameter(): void { $entityClass = 'foo.entity.class'; @@ -137,7 +137,7 @@ public function testCreateQueryWithOrderByParameter() $this->assertSame($this->queryBuilder->reveal(), $result); } - public function testCreateQueryWithRenamedOrderByParameter() + public function testCreateQueryWithRenamedOrderByParameter(): void { $entityClass = 'foo.entity.class'; @@ -163,7 +163,7 @@ public function testCreateQueryWithRenamedOrderByParameter() $this->assertSame($this->queryBuilder->reveal(), $result); } - public function testCreateQueryWithFilterAndOrderByParameters() + public function testCreateQueryWithFilterAndOrderByParameters(): void { $entityClass = 'foo.entity.class'; @@ -193,7 +193,7 @@ public function testCreateQueryWithFilterAndOrderByParameters() $this->assertSame($this->queryBuilder->reveal(), $result); } - public function testGetPaginatedQuery() + public function testGetPaginatedQuery(): void { $query = $this->prophesize(AbstractQuery::class); $this->queryBuilder->getQuery()->willReturn($query->reveal()); @@ -203,7 +203,7 @@ public function testGetPaginatedQuery() $this->assertInstanceOf(DoctrineOrmAdapter::class, $adapter); } - public function testGetCollectionTotal() + public function testGetCollectionTotal(): void { $entityClass = 'foo.entity.class'; diff --git a/test/assets/module/Db/src/Db/Entity/Album.php b/test/assets/module/Db/src/Db/Entity/Album.php index b2efcc14..7ac5f267 100644 --- a/test/assets/module/Db/src/Db/Entity/Album.php +++ b/test/assets/module/Db/src/Db/Entity/Album.php @@ -24,7 +24,10 @@ public function getName() return $this->name; } - public function setName($value) + /** + * @return static + */ + public function setName(string $value): self { $this->name = $value; @@ -36,7 +39,10 @@ public function getCreatedAt() return $this->createdAt; } - public function setCreatedAt(DateTime $value) + /** + * @return static + */ + public function setCreatedAt(DateTime $value): self { $this->createdAt = $value; @@ -48,7 +54,10 @@ public function getArtist() return $this->artist; } - public function setArtist($value) + /** + * @return static + */ + public function setArtist(Artist $value): self { $this->artist = $value; diff --git a/test/assets/module/Db/src/Db/Entity/Artist.php b/test/assets/module/Db/src/Db/Entity/Artist.php index 74070505..65920292 100644 --- a/test/assets/module/Db/src/Db/Entity/Artist.php +++ b/test/assets/module/Db/src/Db/Entity/Artist.php @@ -31,7 +31,10 @@ public function getName() return $this->name; } - public function setName($value) + /** + * @return static + */ + public function setName(string $value): self { $this->name = $value; @@ -43,7 +46,10 @@ public function getCreatedAt() return $this->createdAt; } - public function setCreatedAt(DateTime $value) + /** + * @return static + */ + public function setCreatedAt(DateTime $value): self { $this->createdAt = $value; @@ -82,9 +88,12 @@ public function addAlbum($album) * Remove album * * @param Album $album + * * @throws Exception + * + * @return void */ - public function removeAlbum($album) + public function removeAlbum($album): void { if ($album instanceof Album) { $this->album[] = $album; diff --git a/test/assets/module/DbMongo/src/DbMongo/Document/Meta.php b/test/assets/module/DbMongo/src/DbMongo/Document/Meta.php index b956692d..23a9a301 100644 --- a/test/assets/module/DbMongo/src/DbMongo/Document/Meta.php +++ b/test/assets/module/DbMongo/src/DbMongo/Document/Meta.php @@ -20,7 +20,10 @@ public function getName() return $this->name; } - public function setName($value) + /** + * @return static + */ + public function setName(string $value): self { $this->name = $value; @@ -34,7 +37,7 @@ public function getCreatedAt() return $this->createdAt; } - public function setCreatedAt(DateTime $value) + public function setCreatedAt(DateTime $value): void { $this->createdAt = $value; } @@ -46,12 +49,17 @@ public function getDescription() return $this->description; } - public function setDescription($value) + public function setDescription(string $value): void { $this->description = $value; } - public function getArrayCopy() + /** + * @return array + * + * @psalm-return array{name: mixed, createdAt: mixed, description: mixed} + */ + public function getArrayCopy(): array { return [ 'name' => $this->getName(), @@ -60,9 +68,10 @@ public function getArrayCopy() ]; } - public function exchangeArray($values) + public function exchangeArray($values): void { - $this->setName($values['name'] ?? null); + $name = $values['name'] ?? ''; + $this->setName((string) $name); $this->setCreatedAt($values['createdAt'] ?? null); } }