diff --git a/phpcs.xml b/phpcs.xml index 25daefa..d8343ef 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -24,4 +24,9 @@ /test/ + + + + 0 + diff --git a/psalm-baseline.xml b/psalm-baseline.xml index a39c7d4..81c3dc8 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,32 +1,8 @@ - - - - assert(is_array($configured)) - assert(is_array($spec)) - is_array($configured) - is_array($spec) - is_string($spec['url']) - isset($spec['url']) && is_string($spec['url']) - - - is_array($content) - is_string($spec['token']) - isset($spec['token']) - isset($spec['token']) && is_string($spec['token']) - - - MissingFile - - - - - $queries - $queries - - - array<string, array{0: Query, 1: string}> - array<string, array{0: Query, 1: string}> - + + + + withHttpResponse + diff --git a/psalm.xml b/psalm.xml index 1015d2f..e8b8171 100644 --- a/psalm.xml +++ b/psalm.xml @@ -2,10 +2,14 @@ + xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" + errorBaseline="psalm-baseline.xml" + findUnusedPsalmSuppress="true" + findUnusedCode="true" + findUnusedBaselineEntry="true" +> @@ -13,20 +17,6 @@ - - - - - - - - - - - - - - diff --git a/src/Api.php b/src/Api.php index 8639cd0..666e5fa 100644 --- a/src/Api.php +++ b/src/Api.php @@ -114,7 +114,6 @@ public static function get( /** * phpcs:disable Generic.Files.LineLength.TooLong, Squiz.Commenting.FunctionComment.SpacingAfterParamType - * @param T|null $instance * @param class-string|class-string|class-string $type * * @template T of object diff --git a/src/Document/Fragment/Factory.php b/src/Document/Fragment/Factory.php index d219497..875e8ce 100644 --- a/src/Document/Fragment/Factory.php +++ b/src/Document/Fragment/Factory.php @@ -29,10 +29,6 @@ final class Factory { use DataAssertionBehaviour; - public function __construct() - { - } - public function __invoke(mixed $data): Fragment { return self::factory($data); diff --git a/test/Smoke/TestCase.php b/test/Smoke/TestCase.php index c9871f5..44c7726 100644 --- a/test/Smoke/TestCase.php +++ b/test/Smoke/TestCase.php @@ -64,7 +64,6 @@ protected static function compileEndPoints(): array return $endpoints; } - /** @psalm-suppress MissingFile */ $content = require $configPath; if (! is_array($content)) { return $endpoints; diff --git a/test/Unit/JsonTest.php b/test/Unit/JsonTest.php index 25b7803..b3fe992 100644 --- a/test/Unit/JsonTest.php +++ b/test/Unit/JsonTest.php @@ -95,4 +95,10 @@ public function testThatThePayloadIsPreservedByTheException(): void ); } } + + public function testSuccessfulDecode(): void + { + $value = Json::decode('{"foo":"bar"}', true); + self::assertSame(['foo' => 'bar'], $value); + } } diff --git a/test/Unit/PredicateTest.php b/test/Unit/PredicateTest.php index e662031..fec9af0 100644 --- a/test/Unit/PredicateTest.php +++ b/test/Unit/PredicateTest.php @@ -328,6 +328,7 @@ public function testPredicatesCanBeCastToString(string $fragment, string|int|flo /** * @param scalar|list $value * + * @psalm-suppress PossiblyUnusedParam * @dataProvider atProvider */ public function testSetState(string $fragment, string|int|float|bool|array $value, string $expect): void diff --git a/test/Unit/QueryTest.php b/test/Unit/QueryTest.php index ccd932d..271a4bb 100644 --- a/test/Unit/QueryTest.php +++ b/test/Unit/QueryTest.php @@ -69,12 +69,20 @@ public static function queryProvider(): array /** @return array */ public static function defaultUrlProvider(): array { - $queries = self::queryProvider(); - $queries['Standard Form'][1] = 'https://example.com/api/v2?page=1&pageSize=20'; - $queries['Collection'][1] = sprintf('https://example.com?q=%s&page=1&pageSize=20', urlencode('[[:d = any(document.type, ["doc-type"])]]')); - $queries['With Query'][1] = 'https://example.com/?term=something&page=1&pageSize=20'; - - return $queries; + return [ + 'Standard Form' => [ + new Query(FormSpec::factory('everything', self::formData()->everything)), + 'https://example.com/api/v2?page=1&pageSize=20', + ], + 'With Query' => [ + new Query(FormSpec::factory('withQuery', self::formData()->withQuery)), + 'https://example.com/?term=something&page=1&pageSize=20', + ], + 'Collection' => [ + new Query(FormSpec::factory('collection', self::formData()->collection)), + sprintf('https://example.com?q=%s&page=1&pageSize=20', urlencode('[[:d = any(document.type, ["doc-type"])]]')), + ], + ]; } /** @dataProvider defaultUrlProvider */ @@ -86,12 +94,20 @@ public function testDefaultUrl(Query $query, string $expectedUrl): void /** @return array */ public static function queryUrlProvider(): array { - $queries = self::queryProvider(); - $queries['Standard Form'][1] = 'https://example.com/api/v2?page=1&pageSize=20&q=foo'; - $queries['Collection'][1] = sprintf('https://example.com?q=%s&q=foo&page=1&pageSize=20', urlencode('[[:d = any(document.type, ["doc-type"])]]')); - $queries['With Query'][1] = 'https://example.com/?term=something&page=1&pageSize=20&q=foo'; - - return $queries; + return [ + 'Standard Form' => [ + new Query(FormSpec::factory('everything', self::formData()->everything)), + 'https://example.com/api/v2?page=1&pageSize=20&q=foo', + ], + 'With Query' => [ + new Query(FormSpec::factory('withQuery', self::formData()->withQuery)), + 'https://example.com/?term=something&page=1&pageSize=20&q=foo', + ], + 'Collection' => [ + new Query(FormSpec::factory('collection', self::formData()->collection)), + sprintf('https://example.com?q=%s&q=foo&page=1&pageSize=20', urlencode('[[:d = any(document.type, ["doc-type"])]]')), + ], + ]; } /** @dataProvider queryUrlProvider */ diff --git a/test/Unit/Value/FormSpecTest.php b/test/Unit/Value/FormSpecTest.php index 94b3b66..cd9ffa2 100644 --- a/test/Unit/Value/FormSpecTest.php +++ b/test/Unit/Value/FormSpecTest.php @@ -38,6 +38,8 @@ protected function setUp(): void public function testBasicAccessors(): void { + $this->assertEquals('My Form', $this->form->name()); + $this->assertEquals('something', $this->form->rel()); $this->assertEquals('GET', $this->form->method()); $this->assertEquals('https://example.com', $this->form->action()); $this->assertEquals('whatever', $this->form->encType()); diff --git a/test/Unit/Value/TypeTest.php b/test/Unit/Value/TypeTest.php index 7dd5153..cfa5340 100644 --- a/test/Unit/Value/TypeTest.php +++ b/test/Unit/Value/TypeTest.php @@ -22,6 +22,11 @@ public function testNewInstance(): void public function testJsonEncode(): void { + self::assertEquals( + ['baz' => 'bat'], + Type::new('baz', 'bat')->jsonSerialize(), + ); + self::assertEquals( '{"foo":"bar"}', json_encode(Type::new('foo', 'bar'), JSON_THROW_ON_ERROR),