Skip to content

Commit 2f5fc44

Browse files
committed
Laravel 12; remove psalm
1 parent 6d11415 commit 2f5fc44

File tree

4 files changed

+41
-91
lines changed

4 files changed

+41
-91
lines changed

.github/workflows/static-analysis.yml

-26
This file was deleted.

composer.json

+11-13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515
"source": "https://github.com/api-skeletons/laravel-api-problem",
1616
"chat": "https://gitter.im/API-Skeletons/open-source"
1717
},
18+
"require": {
19+
"php": "^8.1",
20+
"doctrine/instantiator": "^2.0",
21+
"laravel/framework": "^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0"
22+
},
23+
"require-dev": {
24+
"doctrine/coding-standard": "^12.0",
25+
"orchestra/testbench": "^v10.1",
26+
"php-parallel-lint/php-parallel-lint": "^1.4",
27+
"phpunit/phpunit": "^11.5"
28+
},
1829
"config": {
1930
"sort-packages": true,
2031
"allow-plugins": {
@@ -48,20 +59,7 @@
4859
"test": [
4960
"vendor/bin/parallel-lint src test",
5061
"vendor/bin/phpcs",
51-
"vendor/bin/psalm",
5262
"vendor/bin/phpunit"
5363
]
54-
},
55-
"require": {
56-
"php": "^8.1",
57-
"doctrine/instantiator": "^2.0",
58-
"laravel/framework": "^8.0 || ^9.0 || ^10.0 || ^11.0"
59-
},
60-
"require-dev": {
61-
"doctrine/coding-standard": "^12.0",
62-
"orchestra/testbench": "^7.41",
63-
"php-parallel-lint/php-parallel-lint": "^1.4",
64-
"phpunit/phpunit": "^9.5",
65-
"vimeo/psalm": "^4.15"
6664
}
6765
}

psalm.xml

-15
This file was deleted.

test/ApiProblemTest.php

+30-37
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
use ApiSkeletons\Laravel\ApiProblem\ApiProblem;
88
use ApiSkeletons\Laravel\ApiProblem\Exception;
99
use ApiSkeletons\Laravel\ApiProblem\Facades\ApiProblem as ApiProblemFacade;
10-
use http\Exception\InvalidArgumentException;
1110
use Illuminate\Http\JsonResponse;
1211
use ReflectionObject;
1312
use TypeError;
1413

1514
final class ApiProblemTest extends TestCase
1615
{
1716
/** @psalm-return array<string, array{0: int}> */
18-
public function statusCodes(): array
17+
public static function statusCodes(): array
1918
{
2019
return [
2120
'200' => [200],
@@ -42,25 +41,21 @@ public function testResponseWithFacade(): void
4241
$this->assertInstanceOf(JsonResponse::class, ApiProblemFacade::response('Testing', 500));
4342
}
4443

45-
/**
46-
* @dataProvider statusCodes
47-
*/
44+
/** @dataProvider statusCodes */
4845
public function testStatusIsUsedVerbatim(int $status): void
4946
{
5047
$apiProblem = new ApiProblem($status, 'foo');
51-
$payload = $apiProblem->toArray();
48+
$payload = $apiProblem->toArray();
5249
$this->assertArrayHasKey('status', $payload);
5350
$this->assertEquals($status, $payload['status']);
5451
}
5552

56-
/**
57-
* @requires PHP 7.0
58-
*/
53+
/** @requires PHP 7.0 */
5954
public function testErrorAsDetails(): void
6055
{
61-
$error = new TypeError('error message', 705);
56+
$error = new TypeError('error message', 705);
6257
$apiProblem = new ApiProblem(500, $error);
63-
$payload = $apiProblem->toArray();
58+
$payload = $apiProblem->toArray();
6459

6560
$this->assertArrayHasKey('title', $payload);
6661
$this->assertEquals('TypeError', $payload['title']);
@@ -72,33 +67,33 @@ public function testErrorAsDetails(): void
7267

7368
public function testExceptionCodeIsUsedForStatus(): void
7469
{
75-
$exception = new \Exception('exception message', 401);
70+
$exception = new \Exception('exception message', 401);
7671
$apiProblem = new ApiProblem('500', $exception);
77-
$payload = $apiProblem->toArray();
72+
$payload = $apiProblem->toArray();
7873
$this->assertArrayHasKey('status', $payload);
7974
$this->assertEquals($exception->getCode(), $payload['status']);
8075
}
8176

8277
public function testDetailStringIsUsedVerbatim(): void
8378
{
8479
$apiProblem = new ApiProblem('500', 'foo');
85-
$payload = $apiProblem->toArray();
80+
$payload = $apiProblem->toArray();
8681
$this->assertArrayHasKey('detail', $payload);
8782
$this->assertEquals('foo', $payload['detail']);
8883
}
8984

9085
public function testExceptionMessageIsUsedForDetail(): void
9186
{
92-
$exception = new \Exception('exception message');
87+
$exception = new \Exception('exception message');
9388
$apiProblem = new ApiProblem('500', $exception);
94-
$payload = $apiProblem->toArray();
89+
$payload = $apiProblem->toArray();
9590
$this->assertArrayHasKey('detail', $payload);
9691
$this->assertEquals($exception->getMessage(), $payload['detail']);
9792
}
9893

9994
public function testExceptionsCanTriggerInclusionOfStackTraceInDetails(): void
10095
{
101-
$exception = new \Exception('exception message');
96+
$exception = new \Exception('exception message');
10297
$apiProblem = new ApiProblem('500', $exception);
10398
$apiProblem->setDetailIncludesStackTrace(true);
10499
$payload = $apiProblem->toArray();
@@ -109,7 +104,7 @@ public function testExceptionsCanTriggerInclusionOfStackTraceInDetails(): void
109104

110105
public function testExceptionsCanTriggerInclusionOfNestedExceptions(): void
111106
{
112-
$exceptionChild = new \Exception('child exception');
107+
$exceptionChild = new \Exception('child exception');
113108
$exceptionParent = new \Exception('parent exception', 0, $exceptionChild);
114109

115110
$apiProblem = new ApiProblem('500', $exceptionParent);
@@ -130,13 +125,13 @@ public function testExceptionsCanTriggerInclusionOfNestedExceptions(): void
130125
public function testTypeUrlIsUsedVerbatim(): void
131126
{
132127
$apiProblem = new ApiProblem('500', 'foo', 'http://status.dev:8080/details.md');
133-
$payload = $apiProblem->toArray();
128+
$payload = $apiProblem->toArray();
134129
$this->assertArrayHasKey('type', $payload);
135130
$this->assertEquals('http://status.dev:8080/details.md', $payload['type']);
136131
}
137132

138133
/** @psalm-return array<string, array{0: int}> */
139-
public function knownStatusCodes(): array
134+
public static function knownStatusCodes(): array
140135
{
141136
return [
142137
'404' => [404],
@@ -146,14 +141,12 @@ public function knownStatusCodes(): array
146141
];
147142
}
148143

149-
/**
150-
* @dataProvider knownStatusCodes
151-
*/
144+
/** @dataProvider knownStatusCodes */
152145
public function testKnownStatusResultsInKnownTitle(int $status): void
153146
{
154147
$apiProblem = new ApiProblem($status, 'foo');
155-
$r = new ReflectionObject($apiProblem);
156-
$p = $r->getProperty('problemStatusTitles');
148+
$r = new ReflectionObject($apiProblem);
149+
$p = $r->getProperty('problemStatusTitles');
157150
$p->setAccessible(true);
158151
$titles = $p->getValue($apiProblem);
159152

@@ -165,15 +158,15 @@ public function testKnownStatusResultsInKnownTitle(int $status): void
165158
public function testUnknownStatusResultsInUnknownTitle(): void
166159
{
167160
$apiProblem = new ApiProblem(420, 'foo');
168-
$payload = $apiProblem->toArray();
161+
$payload = $apiProblem->toArray();
169162
$this->assertArrayHasKey('title', $payload);
170163
$this->assertEquals('Unknown', $payload['title']);
171164
}
172165

173166
public function testProvidedTitleIsUsedVerbatim(): void
174167
{
175168
$apiProblem = new ApiProblem('500', 'foo', 'http://status.dev:8080/details.md', 'some title');
176-
$payload = $apiProblem->toArray();
169+
$payload = $apiProblem->toArray();
177170
$this->assertArrayHasKey('title', $payload);
178171
$this->assertEquals('some title', $payload['title']);
179172
}
@@ -185,7 +178,7 @@ public function testCanPassArbitraryDetailsToConstructor(): void
185178
'Invalid input',
186179
'http://example.com/api/problem/400',
187180
'Invalid entity',
188-
['foo' => 'bar']
181+
['foo' => 'bar'],
189182
);
190183
$this->assertEquals('bar', $problem->foo);
191184
}
@@ -197,9 +190,9 @@ public function testArraySerializationIncludesArbitraryDetails(): void
197190
'Invalid input',
198191
'http://example.com/api/problem/400',
199192
'Invalid entity',
200-
['foo' => 'bar']
193+
['foo' => 'bar'],
201194
);
202-
$array = $problem->toArray();
195+
$array = $problem->toArray();
203196
$this->assertArrayHasKey('foo', $array);
204197
$this->assertEquals('bar', $array['foo']);
205198
}
@@ -211,9 +204,9 @@ public function testArbitraryDetailsShouldNotOverwriteRequiredFieldsInArraySeria
211204
'Invalid input',
212205
'http://example.com/api/problem/400',
213206
'Invalid entity',
214-
['title' => 'SHOULD NOT GET THIS']
207+
['title' => 'SHOULD NOT GET THIS'],
215208
);
216-
$array = $problem->toArray();
209+
$array = $problem->toArray();
217210
$this->assertArrayHasKey('title', $array);
218211
$this->assertEquals('Invalid entity', $array['title']);
219212
}
@@ -223,7 +216,7 @@ public function testUsesTitleFromExceptionWhenProvided(): void
223216
$exception = new Exception\DomainException('exception message', 401);
224217
$exception->setTitle('problem title');
225218
$apiProblem = new ApiProblem('401', $exception);
226-
$payload = $apiProblem->toArray();
219+
$payload = $apiProblem->toArray();
227220
$this->assertArrayHasKey('title', $payload);
228221
$this->assertEquals($exception->getTitle(), $payload['title']);
229222
}
@@ -233,7 +226,7 @@ public function testUsesTypeFromExceptionWhenProvided(): void
233226
$exception = new Exception\DomainException('exception message', 401);
234227
$exception->setType('http://example.com/api/help/401');
235228
$apiProblem = new ApiProblem('401', $exception);
236-
$payload = $apiProblem->toArray();
229+
$payload = $apiProblem->toArray();
237230
$this->assertArrayHasKey('type', $payload);
238231
$this->assertEquals($exception->getType(), $payload['type']);
239232
}
@@ -243,13 +236,13 @@ public function testUsesAdditionalDetailsFromExceptionWhenProvided(): void
243236
$exception = new Exception\DomainException('exception message', 401);
244237
$exception->setAdditionalDetails(['foo' => 'bar']);
245238
$apiProblem = new ApiProblem('401', $exception);
246-
$payload = $apiProblem->toArray();
239+
$payload = $apiProblem->toArray();
247240
$this->assertArrayHasKey('foo', $payload);
248241
$this->assertEquals('bar', $payload['foo']);
249242
}
250243

251244
/** @psalm-return array<string, array{0: int}> */
252-
public function invalidStatusCodes(): array
245+
public static function invalidStatusCodes(): array
253246
{
254247
return [
255248
'-1' => [-1],
@@ -266,7 +259,7 @@ public function invalidStatusCodes(): array
266259
*/
267260
public function testInvalidHttpStatusCodesAreCastTo500(int $code): void
268261
{
269-
$e = new \Exception('Testing', $code);
262+
$e = new \Exception('Testing', $code);
270263
$problem = new ApiProblem($code, $e);
271264
$this->assertEquals(500, $problem->status);
272265
}

0 commit comments

Comments
 (0)