diff --git a/.phpstan.neon b/.phpstan.neon index 497960f..5567202 100644 --- a/.phpstan.neon +++ b/.phpstan.neon @@ -5,7 +5,7 @@ includes: - vendor/phpstan/phpstan-phpunit/extension.neon parameters: - level: 8 + level: 9 paths: - src/ @@ -53,6 +53,18 @@ parameters: path: tests/BC/ElementTest.php # parameter is required by Art4\JsonApiClient\Element + - + message: "#^Parameter \\#1 \\$string of class Art4\\\\JsonApiClient\\\\Input\\\\RequestStringInput constructor expects string, mixed given\\.$#" + count: 1 + path: tests/Unit/Input/RequestStringInputTest.php + # We are providing an invalid parameter to test the exception message + + - + message: "#^Parameter \\#1 \\$string of class Art4\\\\JsonApiClient\\\\Input\\\\ResponseStringInput constructor expects string, mixed given\\.$#" + count: 1 + path: tests/Unit/Input/ResponseStringInputTest.php + # We are providing an invalid parameter to test the exception message + - message: "#^Parameter \\#1 \\$key of method Art4\\\\JsonApiClient\\\\V1\\\\ResourceNull\\:\\:has\\(\\) expects Art4\\\\JsonApiClient\\\\Helper\\\\AccessKey\\|int\\|string, array given\\.$#" count: 1 diff --git a/src/Helper/AccessKey.php b/src/Helper/AccessKey.php index b647d9a..bed0120 100644 --- a/src/Helper/AccessKey.php +++ b/src/Helper/AccessKey.php @@ -22,7 +22,7 @@ final class AccessKey extends SplStack /** * Transforms the Key to a string * - * @param mixed $key + * @param int|string $key * * @return AccessKey */ diff --git a/src/V1/Link.php b/src/V1/Link.php index 6489924..5e585b1 100644 --- a/src/V1/Link.php +++ b/src/V1/Link.php @@ -61,8 +61,7 @@ public function get($key) /** * Set a link * - * @param string $name The Name - * @param string|object $link The Link + * @param mixed $link The Link */ private function setAsLink(string $name, $link): void { diff --git a/tests/Functional/ParsingTest.php b/tests/Functional/ParsingTest.php index 18a67f1..7e4957c 100644 --- a/tests/Functional/ParsingTest.php +++ b/tests/Functional/ParsingTest.php @@ -39,12 +39,9 @@ public static function createParserProvider(): array } /** - * @test * @dataProvider createParserProvider - * - * @param mixed $parser */ - public function testParseSimpleResourceWithDifferentParser($parser): void + public function testParseSimpleResourceWithDifferentParser(callable $parser): void { $string = $this->getJsonString('01_simple_resource.json'); $document = $parser($string); @@ -178,6 +175,7 @@ public function testParseCompleteResourceObjectWithMultipleRelationships(): void $this->assertTrue($document->has('included')); $this->assertTrue($document->has('data')); + /** @var Accessable */ $resources = $document->get('data'); $this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceCollection', $resources); @@ -186,6 +184,8 @@ public function testParseCompleteResourceObjectWithMultipleRelationships(): void $this->assertSame($resources->getKeys(), [0]); $this->assertTrue($resources->has(0)); + + /** @var Accessable */ $resource = $resources->get(0); $this->assertFalse($resource->has('meta')); @@ -195,24 +195,28 @@ public function testParseCompleteResourceObjectWithMultipleRelationships(): void $this->assertTrue($resource->has('relationships')); $this->assertTrue($resource->has('links')); + /** @var Accessable */ $attributes = $resource->get('attributes'); $this->assertInstanceOf('Art4\JsonApiClient\V1\Attributes', $attributes); $this->assertTrue($attributes->has('title')); $this->assertSame($attributes->get('title'), 'JSON API paints my bikeshed!'); + /** @var Accessable */ $collection = $resource->get('relationships'); $this->assertInstanceOf('Art4\JsonApiClient\V1\RelationshipCollection', $collection); $this->assertTrue($collection->has('author')); $this->assertTrue($collection->has('comments')); + /** @var Accessable */ $author = $collection->get('author'); $this->assertInstanceOf('Art4\JsonApiClient\V1\Relationship', $author); $this->assertTrue($author->has('links')); $this->assertTrue($author->has('data')); + /** @var Accessable */ $links = $author->get('links'); $this->assertInstanceOf('Art4\JsonApiClient\V1\RelationshipLink', $links); @@ -221,18 +225,21 @@ public function testParseCompleteResourceObjectWithMultipleRelationships(): void $this->assertTrue($links->has('related')); $this->assertSame($links->get('related'), 'http://example.com/articles/1/author'); + /** @var Accessable */ $data = $author->get('data'); $this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceIdentifier', $data); $this->assertSame($data->get('type'), 'people'); $this->assertSame($data->get('id'), '9'); + /** @var Accessable */ $comments = $collection->get('comments'); $this->assertInstanceOf('Art4\JsonApiClient\V1\Relationship', $comments); $this->assertTrue($comments->has('links')); $this->assertTrue($comments->has('data')); + /** @var Accessable */ $links = $comments->get('links'); $this->assertInstanceOf('Art4\JsonApiClient\V1\RelationshipLink', $links); @@ -241,35 +248,42 @@ public function testParseCompleteResourceObjectWithMultipleRelationships(): void $this->assertTrue($links->has('related')); $this->assertSame($links->get('related'), 'http://example.com/articles/1/comments'); + /** @var Accessable */ $data_array = $comments->get('data'); $this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceIdentifierCollection', $data_array); $this->assertCount(2, $data_array->getKeys()); + /** @var Accessable */ $identifier = $data_array->get(0); $this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceIdentifier', $identifier); $this->assertSame($identifier->get('type'), 'comments'); $this->assertSame($identifier->get('id'), '5'); + /** @var Accessable */ $identifier = $data_array->get(1); $this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceIdentifier', $identifier); $this->assertSame($identifier->get('type'), 'comments'); $this->assertSame($identifier->get('id'), '12'); + /** @var Accessable */ $links = $resource->get('links'); $this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceItemLink', $links); $this->assertTrue($links->has('self')); $this->assertSame($links->get('self'), 'http://example.com/articles/1'); + /** @var Accessable */ $includes = $document->get('included'); $this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceCollection', $includes); $this->assertSame($includes->getKeys(), [0, 1, 2]); $this->assertTrue($includes->has(0)); + + /** @var Accessable */ $include = $includes->get(0); $this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceItem', $include); @@ -278,6 +292,7 @@ public function testParseCompleteResourceObjectWithMultipleRelationships(): void $this->assertTrue($include->has('attributes')); $this->assertTrue($include->has('links')); + /** @var Accessable */ $attributes = $include->get('attributes'); $this->assertInstanceOf('Art4\JsonApiClient\V1\Attributes', $attributes); @@ -288,6 +303,7 @@ public function testParseCompleteResourceObjectWithMultipleRelationships(): void $this->assertTrue($attributes->has('twitter')); $this->assertSame($attributes->get('twitter'), 'dgeb'); + /** @var Accessable */ $links = $include->get('links'); $this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceItemLink', $links); @@ -295,6 +311,8 @@ public function testParseCompleteResourceObjectWithMultipleRelationships(): void $this->assertSame($links->get('self'), 'http://example.com/people/9'); $this->assertTrue($includes->has(1)); + + /** @var Accessable */ $include = $includes->get(1); $this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceItem', $include); diff --git a/tests/Unit/Input/RequestStringInputTest.php b/tests/Unit/Input/RequestStringInputTest.php index 5256afa..665d562 100644 --- a/tests/Unit/Input/RequestStringInputTest.php +++ b/tests/Unit/Input/RequestStringInputTest.php @@ -17,9 +17,6 @@ class RequestStringInputTest extends TestCase { use HelperTrait; - /** - * @test - */ public function testGetAsObjectFromStringReturnsObject(): void { $input = new RequestStringInput('{}'); @@ -29,11 +26,8 @@ public function testGetAsObjectFromStringReturnsObject(): void /** * @dataProvider jsonValuesProviderWithoutString - * @test - * - * @param mixed $input */ - public function testCreateWithoutStringThrowsException($input): void + public function testCreateWithoutStringThrowsException(mixed $input): void { $this->expectException(InputException::class); $this->expectExceptionMessage( @@ -44,9 +38,6 @@ public function testCreateWithoutStringThrowsException($input): void /** * @dataProvider jsonValuesAsStringProviderWithoutObject - * @test - * - * @param string $input */ public function testGetAsObjectWithInvalidStringsThrowsException(string $input): void { diff --git a/tests/Unit/Input/ResponseStringInputTest.php b/tests/Unit/Input/ResponseStringInputTest.php index c554f1b..d7e0755 100644 --- a/tests/Unit/Input/ResponseStringInputTest.php +++ b/tests/Unit/Input/ResponseStringInputTest.php @@ -17,9 +17,6 @@ class ResponseStringInputTest extends TestCase { use HelperTrait; - /** - * @test - */ public function testGetAsObjectFromStringReturnsObject(): void { $input = new ResponseStringInput('{}'); @@ -29,11 +26,8 @@ public function testGetAsObjectFromStringReturnsObject(): void /** * @dataProvider jsonValuesProviderWithoutString - * @test - * - * @param mixed $input */ - public function testCreateWithoutStringThrowsException($input): void + public function testCreateWithoutStringThrowsException(mixed $input): void { $this->expectException(InputException::class); $this->expectExceptionMessage( @@ -44,9 +38,6 @@ public function testCreateWithoutStringThrowsException($input): void /** * @dataProvider jsonValuesAsStringProviderWithoutObject - * @test - * - * @param string $input */ public function testGetAsObjectWithInvalidStringsThrowsException(string $input): void {