mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +01:00
Wrap functions in function_exists
This commit is contained in:
@ -12,95 +12,111 @@ use Pest\Support\HigherOrderTapProxy;
|
|||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
/**
|
if (!function_exists('beforeAll')) {
|
||||||
* Runs the given closure before all tests in the current file.
|
/**
|
||||||
*/
|
* Runs the given closure before all tests in the current file.
|
||||||
function beforeAll(Closure $closure): void
|
*/
|
||||||
{
|
function beforeAll(Closure $closure): void
|
||||||
TestSuite::getInstance()->beforeAll->set($closure);
|
{
|
||||||
}
|
TestSuite::getInstance()->beforeAll->set($closure);
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs the given closure before each test in the current file.
|
|
||||||
*
|
|
||||||
* @return BeforeEachCall|TestCase|mixed
|
|
||||||
*/
|
|
||||||
function beforeEach(Closure $closure = null): BeforeEachCall
|
|
||||||
{
|
|
||||||
$filename = Backtrace::file();
|
|
||||||
|
|
||||||
return new BeforeEachCall(TestSuite::getInstance(), $filename, $closure);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers the given dataset.
|
|
||||||
*
|
|
||||||
* @param Closure|iterable<int|string, mixed> $dataset
|
|
||||||
*/
|
|
||||||
function dataset(string $name, $dataset): void
|
|
||||||
{
|
|
||||||
Datasets::set($name, $dataset);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The uses function binds the given
|
|
||||||
* arguments to test closures.
|
|
||||||
*/
|
|
||||||
function uses(string ...$classAndTraits): UsesCall
|
|
||||||
{
|
|
||||||
$filename = Backtrace::file();
|
|
||||||
|
|
||||||
return new UsesCall($filename, $classAndTraits);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the given closure as a test. The first argument
|
|
||||||
* is the test description; the second argument is
|
|
||||||
* a closure that contains the test expectations.
|
|
||||||
*
|
|
||||||
* @return TestCall|TestCase|mixed
|
|
||||||
*/
|
|
||||||
function test(string $description = null, Closure $closure = null)
|
|
||||||
{
|
|
||||||
if ($description === null && TestSuite::getInstance()->test !== null) {
|
|
||||||
return new HigherOrderTapProxy(TestSuite::getInstance()->test);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$filename = Backtrace::testFile();
|
|
||||||
|
|
||||||
return new TestCall(TestSuite::getInstance(), $filename, $description, $closure);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
if (!function_exists('beforeEach')) {
|
||||||
* Adds the given closure as a test. The first argument
|
/**
|
||||||
* is the test description; the second argument is
|
* Runs the given closure before each test in the current file.
|
||||||
* a closure that contains the test expectations.
|
*
|
||||||
*
|
* @return BeforeEachCall|TestCase|mixed
|
||||||
* @return TestCall|TestCase|mixed
|
*/
|
||||||
*/
|
function beforeEach(Closure $closure = null): BeforeEachCall
|
||||||
function it(string $description, Closure $closure = null): TestCall
|
{
|
||||||
{
|
$filename = Backtrace::file();
|
||||||
$description = sprintf('it %s', $description);
|
|
||||||
|
|
||||||
return test($description, $closure);
|
return new BeforeEachCall(TestSuite::getInstance(), $filename, $closure);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
if (!function_exists('dataset')) {
|
||||||
* Runs the given closure after each test in the current file.
|
/**
|
||||||
*
|
* Registers the given dataset.
|
||||||
* @return AfterEachCall|TestCase|mixed
|
*
|
||||||
*/
|
* @param Closure|iterable<int|string, mixed> $dataset
|
||||||
function afterEach(Closure $closure = null): AfterEachCall
|
*/
|
||||||
{
|
function dataset(string $name, $dataset): void
|
||||||
$filename = Backtrace::file();
|
{
|
||||||
|
Datasets::set($name, $dataset);
|
||||||
return new AfterEachCall(TestSuite::getInstance(), $filename, $closure);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
if (!function_exists('uses')) {
|
||||||
* Runs the given closure after all tests in the current file.
|
/**
|
||||||
*/
|
* The uses function binds the given
|
||||||
function afterAll(Closure $closure): void
|
* arguments to test closures.
|
||||||
{
|
*/
|
||||||
TestSuite::getInstance()->afterAll->set($closure);
|
function uses(string ...$classAndTraits): UsesCall
|
||||||
|
{
|
||||||
|
$filename = Backtrace::file();
|
||||||
|
|
||||||
|
return new UsesCall($filename, $classAndTraits);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('test')) {
|
||||||
|
/**
|
||||||
|
* Adds the given closure as a test. The first argument
|
||||||
|
* is the test description; the second argument is
|
||||||
|
* a closure that contains the test expectations.
|
||||||
|
*
|
||||||
|
* @return TestCall|TestCase|mixed
|
||||||
|
*/
|
||||||
|
function test(string $description = null, Closure $closure = null)
|
||||||
|
{
|
||||||
|
if ($description === null && TestSuite::getInstance()->test !== null) {
|
||||||
|
return new HigherOrderTapProxy(TestSuite::getInstance()->test);
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = Backtrace::testFile();
|
||||||
|
|
||||||
|
return new TestCall(TestSuite::getInstance(), $filename, $description, $closure);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('it')) {
|
||||||
|
/**
|
||||||
|
* Adds the given closure as a test. The first argument
|
||||||
|
* is the test description; the second argument is
|
||||||
|
* a closure that contains the test expectations.
|
||||||
|
*
|
||||||
|
* @return TestCall|TestCase|mixed
|
||||||
|
*/
|
||||||
|
function it(string $description, Closure $closure = null): TestCall
|
||||||
|
{
|
||||||
|
$description = sprintf('it %s', $description);
|
||||||
|
|
||||||
|
return test($description, $closure);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('afterEach')) {
|
||||||
|
/**
|
||||||
|
* Runs the given closure after each test in the current file.
|
||||||
|
*
|
||||||
|
* @return AfterEachCall|TestCase|mixed
|
||||||
|
*/
|
||||||
|
function afterEach(Closure $closure = null): AfterEachCall
|
||||||
|
{
|
||||||
|
$filename = Backtrace::file();
|
||||||
|
|
||||||
|
return new AfterEachCall(TestSuite::getInstance(), $filename, $closure);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('afterAll')) {
|
||||||
|
/**
|
||||||
|
* Runs the given closure after all tests in the current file.
|
||||||
|
*/
|
||||||
|
function afterAll(Closure $closure): void
|
||||||
|
{
|
||||||
|
TestSuite::getInstance()->afterAll->set($closure);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user