diff --git a/site/app/Test/TestCaseRunner.php b/site/app/Test/TestCaseRunner.php index d743445e9..b6b81a6c3 100644 --- a/site/app/Test/TestCaseRunner.php +++ b/site/app/Test/TestCaseRunner.php @@ -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 $test * @return void @@ -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); + } + } diff --git a/site/disallowed-calls.neon b/site/disallowed-calls.neon index f83d3f7b7..d3ce6fa1a 100644 --- a/site/disallowed-calls.neon +++ b/site/disallowed-calls.neon @@ -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: diff --git a/site/phpstan-vendor.neon b/site/phpstan-vendor.neon index 6bfca0e5e..7df1da75b 100644 --- a/site/phpstan-vendor.neon +++ b/site/phpstan-vendor.neon @@ -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' diff --git a/site/tests/CompanyInfo/CompanyRegisterAresTest.phpt b/site/tests/CompanyInfo/CompanyRegisterAresTest.phpt index 82fa1ee72..0d4221cce 100644 --- a/site/tests/CompanyInfo/CompanyRegisterAresTest.phpt +++ b/site/tests/CompanyInfo/CompanyRegisterAresTest.phpt @@ -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'; @@ -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', diff --git a/site/tests/CompanyInfo/CompanyRegisterRegisterUzTest.phpt b/site/tests/CompanyInfo/CompanyRegisterRegisterUzTest.phpt index b24284aa7..430a77e82 100644 --- a/site/tests/CompanyInfo/CompanyRegisterRegisterUzTest.phpt +++ b/site/tests/CompanyInfo/CompanyRegisterRegisterUzTest.phpt @@ -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'; @@ -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',