keboola/php-test-utils

PHP test utilities skeleton.

0.0.3 2025-09-16 09:52 UTC

This package is auto-updated.

Last update: 2025-09-17 09:31:53 UTC


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 via putenv.

License

MIT licensed, see LICENSE file.