1. Go to this page and download the library: Download zalas/phpunit-globals library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zalas / phpunit-globals example snippets
use PHPUnit\Framework\TestCase;
use Zalas\PHPUnit\Globals\Attribute\Env;
use Zalas\PHPUnit\Globals\Attribute\Server;
use Zalas\PHPUnit\Globals\Attribute\Putenv;
#[Env('FOO', 'bar')]
class ExampleTest extends TestCase
{
#[Env('APP_ENV', 'foo')]
#[Env('APP_DEBUG', '0')]
#[Server('APP_ENV', 'bar')]
#[Server('APP_DEBUG', '1')]
#[Putenv('APP_HOST', 'localhost')]
public function test_global_variables()
{
$this->assertSame('bar', $_ENV['FOO']);
$this->assertSame('foo', $_ENV['APP_ENV']);
$this->assertSame('0', $_ENV['APP_DEBUG']);
$this->assertSame('bar', $_SERVER['APP_ENV']);
$this->assertSame('1', $_SERVER['APP_DEBUG']);
$this->assertSame('localhost', \getenv('APP_HOST'));
}
}
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
#[Env('APP_ENV', unset: true)]
#[Server('APP_DEBUG', unset: true)]
#[Putenv('APP_HOST', unset: true)]
public function test_global_variables()
{
$this->assertArrayNotHasKey('APP_ENV', $_ENV);
$this->assertArrayNotHasKey('APP_DEBUG', $_SERVER);
$this->assertArrayNotHasKey('APP_HOST', \getenv());
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.