Skip to content

Commit

Permalink
improve feedback message on skip
Browse files Browse the repository at this point in the history
  • Loading branch information
dansysanalyst committed May 12, 2024
1 parent b51382a commit 2bb6ecc
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ function powergrid(): PowerGridComponent
function requiresMySQL()
{
if (DB::getDriverName() !== 'mysql') {
test()->markTestSkipped('This test requires MySQL database');
test()->skipWithReason('This test requires MySQL database');
}

return test();
}
function skipOnMySQL()
function skipOnMySQL(string $reason = '')
{
if (DB::getDriverName() === 'mysql') {
test()->markTestSkipped('This test does not run on MySQL');
test()->skipWithReason('Skipping on MySQL', $reason);
}

return test();
Expand All @@ -50,16 +50,16 @@ function skipOnMySQL()
function requiresSQLite()
{
if (DB::getDriverName() !== 'sqlite') {
test()->markTestSkipped('This test requires SQLite database');
test()->skipWithReason('This test requires SQLite database');
}

return test();
}

function skipOnSQLite()
function skipOnSQLite(string $reason = '')
{
if (DB::getDriverName() === 'sqlite') {
test()->markTestSkipped('This test does not run on SQLite');
test()->skipWithReason('Skipping on SQLite', $reason);
}

return test();
Expand All @@ -68,16 +68,16 @@ function skipOnSQLite()
function requiresPostgreSQL()
{
if (DB::getDriverName() !== 'pgsql') {
test()->markTestSkipped('This test requires PostgreSQL database');
test()->skipWithReason('This test requires PostgreSQL database');
}

return test();
}

function skipOnPostgreSQL()
function skipOnPostgreSQL(string $reason = '')
{
if (DB::getDriverName() === 'pgsql') {
test()->markTestSkipped('This test does not run on PostgreSQL');
test()->skipWithReason('Skipping on PostgreSQL', $reason);
}

return test();
Expand All @@ -88,7 +88,7 @@ function requiresOpenSpout()
$isInstalled = \Composer\InstalledVersions::isInstalled('openspout/openspout');

if (!$isInstalled) {
test()->markTestSkipped('This test requires openspout/openspout');
test()->skipWithReason('test requires openspout/openspout');
}

return test();
Expand All @@ -98,3 +98,12 @@ function fixturePath(string $filepath): string
{
return str_replace('/', DIRECTORY_SEPARATOR, __DIR__ . '/Concerns/Fixtures/' . ltrim($filepath, '/'));
}

function skipWithReason(string $default, string $reason = ''): void
{
$reason = str($reason)->whenNotEmpty(fn ($r) => $r->prepend(': '))
->prepend($default)
->toString();

test()->markTestSkipped($reason);
}

0 comments on commit 2bb6ecc

Please sign in to comment.