Skip to content

Commit

Permalink
Skip tests with TestCaseRunner::skip() instead of Environment::skip()
Browse files Browse the repository at this point in the history
Because TestCaseRunner::skip() can skip skipping if an environment variable is set.
  • Loading branch information
spaze committed Oct 16, 2023
1 parent 51d03d8 commit cf0a18e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
15 changes: 15 additions & 0 deletions site/app/Test/TestCaseRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@
use Nette\Utils\Type;
use ReflectionException;
use ReflectionMethod;
use Tester\Environment;
use Tester\TestCase;

class TestCaseRunner
{

private const ENV_VAR_NAME = 'TEST_CASE_RUNNER_INCLUDE_SKIPPED';
private const ENV_VAR_VALUE = '1';
public const ENV_VAR = self::ENV_VAR_NAME . '=' . self::ENV_VAR_VALUE;


/**
* @param class-string<TestCase> $test
* @return void
Expand Down Expand Up @@ -50,4 +56,13 @@ public static function run(string $test): void
(new $test(...$params))->run();
}


public static function skip(string $message): void
{
if (getenv(self::ENV_VAR_NAME) === self::ENV_VAR_VALUE) {
return;
}
Environment::skip($message);
}

}
6 changes: 6 additions & 0 deletions site/disallowed-calls.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ parameters:
-
function: 'setcookie()'
message: 'use methods from MichalSpacekCz\Http\Cookies'
disallowedStaticCalls:
-
method: 'Tester\Environment::skip()'
message: 'use TestCaseRunner::skip() instead, it can ignore skipping with an environment variable'
allowInMethods:
- 'MichalSpacekCz\Test\TestCaseRunner::skip()'
disallowedMethodCalls:
-
method:
Expand Down
5 changes: 5 additions & 0 deletions site/phpstan-vendor.neon
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ parameters:
message: 'use logger instead, debug bar is not visible in production'
allowIn:
- vendor/tracy/tracy/src/Tracy/functions.php
-
method: 'Tester\Environment::skip()'
message: 'use TestCaseRunner::skip() instead, it can ignore skipping with an environment variable'
allowIn:
- vendor/nette/tester/src/Framework/TestCase.php
disallowedSuperglobals:
-
superglobal: '$_SERVER'
Expand Down
6 changes: 1 addition & 5 deletions site/tests/CompanyInfo/CompanyRegisterAresTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use MichalSpacekCz\Test\Http\Client\HttpClientMock;
use MichalSpacekCz\Test\TestCaseRunner;
use Nette\Schema\Processor;
use Tester\Assert;
use Tester\Environment;
use Tester\TestCase;

require __DIR__ . '/../bootstrap.php';
Expand All @@ -32,10 +31,7 @@ class CompanyRegisterAresTest extends TestCase

public function testGetDetails(): void
{
if (getenv(Environment::VariableRunner)) {
$file = basename(__FILE__);
Environment::skip("The test uses the Internet, to not skip the test run it with `php {$file}`");
}
TestCaseRunner::skip('The test uses the Internet, to not skip the test case run it with `' . TestCaseRunner::ENV_VAR . '`');
$expected = new CompanyInfoDetails(
200,
'OK',
Expand Down
6 changes: 1 addition & 5 deletions site/tests/CompanyInfo/CompanyRegisterRegisterUzTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use MichalSpacekCz\CompanyInfo\Exceptions\CompanyNotFoundException;
use MichalSpacekCz\Http\Client\HttpClient;
use MichalSpacekCz\Test\TestCaseRunner;
use Tester\Assert;
use Tester\Environment;
use Tester\TestCase;

require __DIR__ . '/../bootstrap.php';
Expand All @@ -28,10 +27,7 @@ class CompanyRegisterRegisterUzTest extends TestCase

public function testGetDetails(): void
{
if (getenv(Environment::VariableRunner)) {
$file = basename(__FILE__);
Environment::skip("The test uses the Internet, to not skip the test run it with `php {$file}`");
}
TestCaseRunner::skip('The test uses the Internet, to not skip the test case run it with `' . TestCaseRunner::ENV_VAR . '`');
$expected = new CompanyInfoDetails(
200,
'OK',
Expand Down

0 comments on commit cf0a18e

Please sign in to comment.