mirror of
https://github.com/pestphp/pest.git
synced 2026-03-10 17:57:23 +01:00
implemented support for PHPUnit's @depends
This commit is contained in:
@ -53,6 +53,11 @@ trait TestCase
|
||||
$this->setGroups($groups);
|
||||
}
|
||||
|
||||
public function addDependencies(array $tests): void
|
||||
{
|
||||
$this->setDependencies($tests);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the test case name. Note that, in Pest
|
||||
* we ignore withDataset argument as the description
|
||||
@ -130,16 +135,16 @@ trait TestCase
|
||||
/**
|
||||
* Runs the test.
|
||||
*/
|
||||
public function __test(): void
|
||||
public function __test()
|
||||
{
|
||||
$this->__callClosure($this->__test, func_get_args());
|
||||
return $this->__callClosure($this->__test, func_get_args());
|
||||
}
|
||||
|
||||
private function __callClosure(Closure $closure, array $arguments): void
|
||||
private function __callClosure(Closure $closure, array $arguments)
|
||||
{
|
||||
ExceptionTrace::ensure(function () use ($closure, $arguments) {
|
||||
call_user_func_array(Closure::bind($closure, $this, get_class($this)), $arguments);
|
||||
});
|
||||
return ExceptionTrace::ensure(function () use ($closure, $arguments) {
|
||||
return call_user_func_array(Closure::bind($closure, $this, get_class($this)), $arguments);
|
||||
})->getValue();
|
||||
}
|
||||
|
||||
public function getPrintableTestCaseName(): string
|
||||
|
||||
@ -132,10 +132,11 @@ final class TestCaseFactory
|
||||
$proxies = $this->proxies;
|
||||
$factoryTest = $this->test;
|
||||
|
||||
$test = function () use ($chains, $proxies, $factoryTest): void {
|
||||
$test = function () use ($chains, $proxies, $factoryTest) {
|
||||
$proxies->proxy($this);
|
||||
$chains->chain($this);
|
||||
call_user_func(Closure::bind($factoryTest, $this, get_class($this)), ...func_get_args());
|
||||
|
||||
return call_user_func(Closure::bind($factoryTest, $this, get_class($this)), ...func_get_args());
|
||||
};
|
||||
|
||||
$className = $this->makeClassFromFilename($this->filename);
|
||||
|
||||
@ -84,6 +84,20 @@ final class TestCall
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function dependsOn(string ...$tests): TestCall
|
||||
{
|
||||
$this->testCaseFactory
|
||||
->factoryProxies
|
||||
->add(Backtrace::file(), Backtrace::line(), 'addDependencies', [$tests]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function depends(string ...$tests): TestCall
|
||||
{
|
||||
return $this->dependsOn(...$tests);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the test suite only this test case.
|
||||
*/
|
||||
|
||||
@ -18,10 +18,10 @@ final class ExceptionTrace
|
||||
* Ensures the given closure reports
|
||||
* the good execution context.
|
||||
*/
|
||||
public static function ensure(Closure $closure): void
|
||||
public static function ensure(Closure $closure): Mixed
|
||||
{
|
||||
try {
|
||||
$closure();
|
||||
return new Mixed($closure());
|
||||
} catch (Throwable $throwable) {
|
||||
if (Str::startsWith($message = $throwable->getMessage(), self::UNDEFINED_METHOD)) {
|
||||
$message = str_replace(self::UNDEFINED_METHOD, 'Call to undefined method ', $message);
|
||||
|
||||
32
src/Support/Mixed.php
Normal file
32
src/Support/Mixed.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Support;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Mixed
|
||||
{
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __construct($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user