keboola / php-test-utils
PHP test utilities skeleton.
0.0.3
2025-09-16 09:52 UTC
Requires (Dev)
- infection/infection: ^0.31
- keboola/coding-standard: >=14.0.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.3
- symfony/dotenv: ^7.0|^8.0
README
Utilities to make writing PHPUnit tests easier. Currently provides helpers for working with environment variables so that they're properly validated:
use PHPUnit\Framework\TestCase; use Keboola\PhpTestUtils\TestEnvVarsTrait; final class MyEnvTest extends TestCase { use TestEnvVarsTrait; public function testOptionalEnv(): void { $clientOptions = new ClientOptions( url: new ServiceClient(self::getRequiredEnv('HOSTNAME_SUFFIX'))->getConnectionServiceUrl(), token: self::getRequiredEnv('TEST_STORAGE_API_TOKEN_SNOWFLAKE'), ); }
- getOptionalEnv(name): returns the env var value as a non-empty string, or
null
if not set/empty. - getRequiredEnv(name): returns the env var value as a non-empty string; fails the env if missing.
- overrideEnv(name, value|null): sets or unsets the variable consistently in
$_ENV
and the process viaputenv
.
License
MIT licensed, see LICENSE file.