Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 12; remove psalm #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
run: "vendor/bin/phpunit --coverage-clover=coverage.xml"

- name: "Upload coverage file"
uses: "actions/upload-artifact@v2"
uses: "actions/upload-artifact@v4"
with:
name: "phpunit-${{ matrix.php-version }}-${{ matrix.dependencies }}-${{ matrix.dbal-version }}.coverage"
path: "coverage.xml"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
Expand Down
26 changes: 0 additions & 26 deletions .github/workflows/static-analysis.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.lock
/.phpcs-cache
/coverage/
/.phpunit.cache/
.phpunit.result.cache
24 changes: 11 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
"source": "https://github.com/api-skeletons/laravel-api-problem",
"chat": "https://gitter.im/API-Skeletons/open-source"
},
"require": {
"php": "^8.1",
"doctrine/instantiator": "^2.0",
"laravel/framework": "^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0"
},
"require-dev": {
"doctrine/coding-standard": "^12.0",
"orchestra/testbench": "^v10.1",
"php-parallel-lint/php-parallel-lint": "^1.4",
"phpunit/phpunit": "^11.5"
},
"config": {
"sort-packages": true,
"allow-plugins": {
Expand Down Expand Up @@ -48,20 +59,7 @@
"test": [
"vendor/bin/parallel-lint src test",
"vendor/bin/phpcs",
"vendor/bin/psalm",
"vendor/bin/phpunit"
]
},
"require": {
"php": "^8.1",
"doctrine/instantiator": "^2.0",
"laravel/framework": "^8.0 || ^9.0 || ^10.0 || ^11.0"
},
"require-dev": {
"doctrine/coding-standard": "^12.0",
"orchestra/testbench": "^7.41",
"php-parallel-lint/php-parallel-lint": "^1.4",
"phpunit/phpunit": "^9.5",
"vimeo/psalm": "^4.15"
}
}
15 changes: 0 additions & 15 deletions psalm.xml

This file was deleted.

67 changes: 30 additions & 37 deletions test/ApiProblemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
use ApiSkeletons\Laravel\ApiProblem\ApiProblem;
use ApiSkeletons\Laravel\ApiProblem\Exception;
use ApiSkeletons\Laravel\ApiProblem\Facades\ApiProblem as ApiProblemFacade;
use http\Exception\InvalidArgumentException;
use Illuminate\Http\JsonResponse;
use ReflectionObject;
use TypeError;

final class ApiProblemTest extends TestCase
{
/** @psalm-return array<string, array{0: int}> */
public function statusCodes(): array
public static function statusCodes(): array
{
return [
'200' => [200],
Expand All @@ -42,25 +41,21 @@ public function testResponseWithFacade(): void
$this->assertInstanceOf(JsonResponse::class, ApiProblemFacade::response('Testing', 500));
}

/**
* @dataProvider statusCodes
*/
/** @dataProvider statusCodes */
public function testStatusIsUsedVerbatim(int $status): void
{
$apiProblem = new ApiProblem($status, 'foo');
$payload = $apiProblem->toArray();
$payload = $apiProblem->toArray();
$this->assertArrayHasKey('status', $payload);
$this->assertEquals($status, $payload['status']);
}

/**
* @requires PHP 7.0
*/
/** @requires PHP 7.0 */
public function testErrorAsDetails(): void
{
$error = new TypeError('error message', 705);
$error = new TypeError('error message', 705);
$apiProblem = new ApiProblem(500, $error);
$payload = $apiProblem->toArray();
$payload = $apiProblem->toArray();

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

public function testExceptionCodeIsUsedForStatus(): void
{
$exception = new \Exception('exception message', 401);
$exception = new \Exception('exception message', 401);
$apiProblem = new ApiProblem('500', $exception);
$payload = $apiProblem->toArray();
$payload = $apiProblem->toArray();
$this->assertArrayHasKey('status', $payload);
$this->assertEquals($exception->getCode(), $payload['status']);
}

public function testDetailStringIsUsedVerbatim(): void
{
$apiProblem = new ApiProblem('500', 'foo');
$payload = $apiProblem->toArray();
$payload = $apiProblem->toArray();
$this->assertArrayHasKey('detail', $payload);
$this->assertEquals('foo', $payload['detail']);
}

public function testExceptionMessageIsUsedForDetail(): void
{
$exception = new \Exception('exception message');
$exception = new \Exception('exception message');
$apiProblem = new ApiProblem('500', $exception);
$payload = $apiProblem->toArray();
$payload = $apiProblem->toArray();
$this->assertArrayHasKey('detail', $payload);
$this->assertEquals($exception->getMessage(), $payload['detail']);
}

public function testExceptionsCanTriggerInclusionOfStackTraceInDetails(): void
{
$exception = new \Exception('exception message');
$exception = new \Exception('exception message');
$apiProblem = new ApiProblem('500', $exception);
$apiProblem->setDetailIncludesStackTrace(true);
$payload = $apiProblem->toArray();
Expand All @@ -109,7 +104,7 @@ public function testExceptionsCanTriggerInclusionOfStackTraceInDetails(): void

public function testExceptionsCanTriggerInclusionOfNestedExceptions(): void
{
$exceptionChild = new \Exception('child exception');
$exceptionChild = new \Exception('child exception');
$exceptionParent = new \Exception('parent exception', 0, $exceptionChild);

$apiProblem = new ApiProblem('500', $exceptionParent);
Expand All @@ -130,13 +125,13 @@ public function testExceptionsCanTriggerInclusionOfNestedExceptions(): void
public function testTypeUrlIsUsedVerbatim(): void
{
$apiProblem = new ApiProblem('500', 'foo', 'http://status.dev:8080/details.md');
$payload = $apiProblem->toArray();
$payload = $apiProblem->toArray();
$this->assertArrayHasKey('type', $payload);
$this->assertEquals('http://status.dev:8080/details.md', $payload['type']);
}

/** @psalm-return array<string, array{0: int}> */
public function knownStatusCodes(): array
public static function knownStatusCodes(): array
{
return [
'404' => [404],
Expand All @@ -146,14 +141,12 @@ public function knownStatusCodes(): array
];
}

/**
* @dataProvider knownStatusCodes
*/
/** @dataProvider knownStatusCodes */
public function testKnownStatusResultsInKnownTitle(int $status): void
{
$apiProblem = new ApiProblem($status, 'foo');
$r = new ReflectionObject($apiProblem);
$p = $r->getProperty('problemStatusTitles');
$r = new ReflectionObject($apiProblem);
$p = $r->getProperty('problemStatusTitles');
$p->setAccessible(true);
$titles = $p->getValue($apiProblem);

Expand All @@ -165,15 +158,15 @@ public function testKnownStatusResultsInKnownTitle(int $status): void
public function testUnknownStatusResultsInUnknownTitle(): void
{
$apiProblem = new ApiProblem(420, 'foo');
$payload = $apiProblem->toArray();
$payload = $apiProblem->toArray();
$this->assertArrayHasKey('title', $payload);
$this->assertEquals('Unknown', $payload['title']);
}

public function testProvidedTitleIsUsedVerbatim(): void
{
$apiProblem = new ApiProblem('500', 'foo', 'http://status.dev:8080/details.md', 'some title');
$payload = $apiProblem->toArray();
$payload = $apiProblem->toArray();
$this->assertArrayHasKey('title', $payload);
$this->assertEquals('some title', $payload['title']);
}
Expand All @@ -185,7 +178,7 @@ public function testCanPassArbitraryDetailsToConstructor(): void
'Invalid input',
'http://example.com/api/problem/400',
'Invalid entity',
['foo' => 'bar']
['foo' => 'bar'],
);
$this->assertEquals('bar', $problem->foo);
}
Expand All @@ -197,9 +190,9 @@ public function testArraySerializationIncludesArbitraryDetails(): void
'Invalid input',
'http://example.com/api/problem/400',
'Invalid entity',
['foo' => 'bar']
['foo' => 'bar'],
);
$array = $problem->toArray();
$array = $problem->toArray();
$this->assertArrayHasKey('foo', $array);
$this->assertEquals('bar', $array['foo']);
}
Expand All @@ -211,9 +204,9 @@ public function testArbitraryDetailsShouldNotOverwriteRequiredFieldsInArraySeria
'Invalid input',
'http://example.com/api/problem/400',
'Invalid entity',
['title' => 'SHOULD NOT GET THIS']
['title' => 'SHOULD NOT GET THIS'],
);
$array = $problem->toArray();
$array = $problem->toArray();
$this->assertArrayHasKey('title', $array);
$this->assertEquals('Invalid entity', $array['title']);
}
Expand All @@ -223,7 +216,7 @@ public function testUsesTitleFromExceptionWhenProvided(): void
$exception = new Exception\DomainException('exception message', 401);
$exception->setTitle('problem title');
$apiProblem = new ApiProblem('401', $exception);
$payload = $apiProblem->toArray();
$payload = $apiProblem->toArray();
$this->assertArrayHasKey('title', $payload);
$this->assertEquals($exception->getTitle(), $payload['title']);
}
Expand All @@ -233,7 +226,7 @@ public function testUsesTypeFromExceptionWhenProvided(): void
$exception = new Exception\DomainException('exception message', 401);
$exception->setType('http://example.com/api/help/401');
$apiProblem = new ApiProblem('401', $exception);
$payload = $apiProblem->toArray();
$payload = $apiProblem->toArray();
$this->assertArrayHasKey('type', $payload);
$this->assertEquals($exception->getType(), $payload['type']);
}
Expand All @@ -243,13 +236,13 @@ public function testUsesAdditionalDetailsFromExceptionWhenProvided(): void
$exception = new Exception\DomainException('exception message', 401);
$exception->setAdditionalDetails(['foo' => 'bar']);
$apiProblem = new ApiProblem('401', $exception);
$payload = $apiProblem->toArray();
$payload = $apiProblem->toArray();
$this->assertArrayHasKey('foo', $payload);
$this->assertEquals('bar', $payload['foo']);
}

/** @psalm-return array<string, array{0: int}> */
public function invalidStatusCodes(): array
public static function invalidStatusCodes(): array
{
return [
'-1' => [-1],
Expand All @@ -266,7 +259,7 @@ public function invalidStatusCodes(): array
*/
public function testInvalidHttpStatusCodesAreCastTo500(int $code): void
{
$e = new \Exception('Testing', $code);
$e = new \Exception('Testing', $code);
$problem = new ApiProblem($code, $e);
$this->assertEquals(500, $problem->status);
}
Expand Down
Loading