mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
feat: only registers globals if necessary
This commit is contained in:
2
bin/pest
2
bin/pest
@ -11,6 +11,8 @@ use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
(static function () {
|
||||
$_SERVER['__PEST__'] = true;
|
||||
|
||||
// Ensures Collision's Printer is registered.
|
||||
$_SERVER['COLLISION_PRINTER'] = 'DefaultPrinter';
|
||||
|
||||
|
||||
@ -14,7 +14,8 @@ use Pest\Support\HigherOrderTapProxy;
|
||||
use Pest\TestSuite;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
if (! function_exists('expect')) {
|
||||
if (array_key_exists('__PEST__', $_SERVER)) {
|
||||
if (! function_exists('expect')) {
|
||||
/**
|
||||
* Creates a new expectation.
|
||||
*
|
||||
@ -27,9 +28,9 @@ if (! function_exists('expect')) {
|
||||
{
|
||||
return new Expectation($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('beforeAll')) {
|
||||
if (! function_exists('beforeAll')) {
|
||||
/**
|
||||
* Runs the given closure before all tests in the current file.
|
||||
*/
|
||||
@ -37,9 +38,9 @@ if (! function_exists('beforeAll')) {
|
||||
{
|
||||
TestSuite::getInstance()->beforeAll->set($closure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('beforeEach')) {
|
||||
if (! function_exists('beforeEach')) {
|
||||
/**
|
||||
* Runs the given closure before each test in the current file.
|
||||
*
|
||||
@ -51,9 +52,9 @@ if (! function_exists('beforeEach')) {
|
||||
|
||||
return new BeforeEachCall(TestSuite::getInstance(), $filename, $closure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('dataset')) {
|
||||
if (! function_exists('dataset')) {
|
||||
/**
|
||||
* Registers the given dataset.
|
||||
*
|
||||
@ -64,9 +65,9 @@ if (! function_exists('dataset')) {
|
||||
$scope = DatasetInfo::scope(Backtrace::datasetsFile());
|
||||
DatasetsRepository::set($name, $dataset, $scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('uses')) {
|
||||
if (! function_exists('uses')) {
|
||||
/**
|
||||
* The uses function binds the given
|
||||
* arguments to test closures.
|
||||
@ -79,9 +80,9 @@ if (! function_exists('uses')) {
|
||||
|
||||
return new UsesCall($filename, array_values($classAndTraits));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('test')) {
|
||||
if (! function_exists('test')) {
|
||||
/**
|
||||
* Adds the given closure as a test. The first argument
|
||||
* is the test description; the second argument is
|
||||
@ -99,9 +100,9 @@ if (! function_exists('test')) {
|
||||
|
||||
return new TestCall(TestSuite::getInstance(), $filename, $description, $closure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('it')) {
|
||||
if (! function_exists('it')) {
|
||||
/**
|
||||
* Adds the given closure as a test. The first argument
|
||||
* is the test description; the second argument is
|
||||
@ -118,9 +119,9 @@ if (! function_exists('it')) {
|
||||
|
||||
return $test;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('todo')) {
|
||||
if (! function_exists('todo')) {
|
||||
/**
|
||||
* Adds the given todo test. Internally, this test
|
||||
* is marked as incomplete. Yet, Collision, Pest's
|
||||
@ -135,9 +136,9 @@ if (! function_exists('todo')) {
|
||||
'__TODO__',
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('afterEach')) {
|
||||
if (! function_exists('afterEach')) {
|
||||
/**
|
||||
* Runs the given closure after each test in the current file.
|
||||
*
|
||||
@ -149,9 +150,9 @@ if (! function_exists('afterEach')) {
|
||||
|
||||
return new AfterEachCall(TestSuite::getInstance(), $filename, $closure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('afterAll')) {
|
||||
if (! function_exists('afterAll')) {
|
||||
/**
|
||||
* Runs the given closure after all tests in the current file.
|
||||
*/
|
||||
@ -159,4 +160,5 @@ if (! function_exists('afterAll')) {
|
||||
{
|
||||
TestSuite::getInstance()->afterAll->set($closure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user