Skip to content

Commit

Permalink
Workaround to show CI errors
Browse files Browse the repository at this point in the history
  • Loading branch information
3m1n3nc3 committed Aug 28, 2024
1 parent 50fbeb6 commit 358fc9a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@php vendor/bin/testbench serve"
],
"analyse": "vendor/bin/phpstan analyse",
"test": "XDEBUG_MODE=coverage ./vendor/bin/pest --coverage",
"test": "XDEBUG_MODE=coverage ./vendor/bin/pest --coverage --display-errors --testdox",
"test-coverage": "vendor/bin/pest --coverage",
"format": "vendor/bin/pint"
},
Expand Down
3 changes: 2 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
</source>
<php>
<server name="APP_ENV" value="testing" />
<server name="APP_DEBUG" value="true" />
<server name="BCRYPT_ROUNDS" value="4" />
<server name="CACHE_DRIVER" value="array" />
<server name="DB_CONNECTION" value="sqlite" />
Expand All @@ -46,4 +47,4 @@
<server name="QUEUE_CONNECTION" value="sync" />
<server name="SESSION_DRIVER" value="array" />
</php>
</phpunit>
</phpunit>
26 changes: 19 additions & 7 deletions tests/Feature/CollectionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
User::factory(10)->create();

Route::get('test/users', function () {
return new UserCollection(User::paginate(6));
return present(fn() => new UserCollection(User::paginate(6)));
});

$response = $this->get('/test/users');

!json_validate($response->content()) && $response->dump();

$response->assertOk();

$this->assertArrayHasKey('links', $response->collect());
Expand All @@ -39,11 +41,13 @@
User::factory(10)->create();

Route::get('test/users', function () {
return new UserCollection(User::paginate(6));
return present(fn() => new UserCollection(User::paginate(6)));
});

$response = $this->get('/test/users');

!json_validate($response->content()) && $response->dump();

$response->assertOk();

$this->assertArrayHasKey('currentPage', $response->collect('meta'));
Expand All @@ -65,11 +69,13 @@
User::factory(10)->create();

Route::get('test/users', function () {
return new UserCollection(User::paginate(6));
return present(fn() => new UserCollection(User::paginate(6)));
});

$response = $this->get('/test/users');

!json_validate($response->content()) && $response->dump();

$response->assertOk();

$this->assertArrayHasKey('firstItem', $response->collect('links'));
Expand All @@ -85,11 +91,13 @@
User::factory(10)->create();

Route::get('test/users', function () {
return new UserCollection(User::paginate(6));
return present(fn() => new UserCollection(User::paginate(6)));
});

$response = $this->get('/test/users');

!json_validate($response->content()) && $response->dump();

$response->assertOk();

$this->assertArrayNotHasKey('links', $response->collect());
Expand All @@ -103,11 +111,13 @@
User::factory(10)->create();

Route::get('test/users', function () {
return new UserCollection(User::paginate(6));
return present(fn() => new UserCollection(User::paginate(6)));
});

$response = $this->get('/test/users');

!json_validate($response->content()) && $response->dump();

$response->assertOk();

$this->assertArrayNotHasKey('meta', $response->collect());
Expand All @@ -121,13 +131,15 @@
User::factory(10)->create();

Route::get('test/users', function () {
return new UserCollection(User::paginate(6));
return present(fn() => new UserCollection(User::paginate(6)));
});

$response = $this->get('/test/users');

!json_validate($response->content()) && $response->dump();

$response->assertOk();

$this->assertArrayNotHasKey('meta', $response->collect());
$this->assertArrayNotHasKey('links', $response->collect());
});
});
29 changes: 28 additions & 1 deletion tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,33 @@
function loadEnv()
{
// Load the .env file
$dotenv = \Dotenv\Dotenv::createImmutable(__DIR__.'/..');
$dotenv = \Dotenv\Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->safeLoad();
}

if (! function_exists('json_validate')) {
function json_validate($json, $depth = 512, $flags = 0)
{
return json_validate($json, $depth, $flags);

if (!is_string($json)) {
return false;
}

try {
json_decode($json, false, $depth, $flags | JSON_THROW_ON_ERROR);
return true;
} catch (\JsonException $e) {
return false;
}
}
}

function present(callable $method)
{
try {
return $method();
} catch (\Throwable $th) {
return $th->getMessage() . " on line " . $th->getLine();
}
}

0 comments on commit 358fc9a

Please sign in to comment.