mirror of
https://github.com/pestphp/pest.git
synced 2026-03-10 01:37:21 +01:00
feat(describe): continues work around hooks
This commit is contained in:
@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace Pest\PendingCalls;
|
||||
|
||||
use Closure;
|
||||
use Pest\PendingCalls;
|
||||
use Pest\PendingCalls\Concerns\Describable;
|
||||
use Pest\Support\Backtrace;
|
||||
use Pest\Support\ChainableClosure;
|
||||
@ -41,6 +40,8 @@ final class AfterEachCall
|
||||
$this->closure = $closure instanceof Closure ? $closure : NullClosure::create();
|
||||
|
||||
$this->proxies = new HigherOrderMessageCollection();
|
||||
|
||||
$this->describing = DescribeCall::describing();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,22 +49,22 @@ final class AfterEachCall
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
PendingCalls::afterEach($this, function (string $describing = null) {
|
||||
$proxies = $this->proxies;
|
||||
$describing = $this->describing;
|
||||
|
||||
$afterEachTestCase = ChainableClosure::when(
|
||||
fn () => is_null($describing) || $this->__describeDescription === $describing, // @phpstan-ignore-line
|
||||
ChainableClosure::from(fn () => $proxies->chain($this), $this->closure)->bindTo($this, self::class), // @phpstan-ignore-line
|
||||
)->bindTo($this, self::class);
|
||||
$proxies = $this->proxies;
|
||||
|
||||
assert($afterEachTestCase instanceof Closure);
|
||||
$afterEachTestCase = ChainableClosure::when(
|
||||
fn () => is_null($describing) || $this->__describeDescription === $describing, // @phpstan-ignore-line
|
||||
ChainableClosure::fromSameObject(fn () => $proxies->chain($this), $this->closure)->bindTo($this, self::class), // @phpstan-ignore-line
|
||||
)->bindTo($this, self::class);
|
||||
|
||||
$this->testSuite->afterEach->set(
|
||||
$this->filename,
|
||||
$this,
|
||||
$afterEachTestCase,
|
||||
);
|
||||
});
|
||||
assert($afterEachTestCase instanceof Closure);
|
||||
|
||||
$this->testSuite->afterEach->set(
|
||||
$this->filename,
|
||||
$this,
|
||||
$afterEachTestCase,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace Pest\PendingCalls;
|
||||
|
||||
use Closure;
|
||||
use Pest\PendingCalls;
|
||||
use Pest\PendingCalls\Concerns\Describable;
|
||||
use Pest\Support\Backtrace;
|
||||
use Pest\Support\ChainableClosure;
|
||||
@ -47,6 +46,8 @@ final class BeforeEachCall
|
||||
|
||||
$this->testCallProxies = new HigherOrderMessageCollection();
|
||||
$this->testCaseProxies = new HigherOrderMessageCollection();
|
||||
|
||||
$this->describing = DescribeCall::describing();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,29 +55,28 @@ final class BeforeEachCall
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
PendingCalls::beforeEach($this, function (string $describing = null) {
|
||||
$testCaseProxies = $this->testCaseProxies;
|
||||
$describing = $this->describing;
|
||||
$testCaseProxies = $this->testCaseProxies;
|
||||
|
||||
$beforeEachTestCall = function (TestCall $testCall) use ($describing): void {
|
||||
if (is_null($describing) || ($this->describing === $testCall->describing && $testCall->describing === $describing)) {
|
||||
$this->testCallProxies->chain($testCall);
|
||||
}
|
||||
};
|
||||
$beforeEachTestCall = function (TestCall $testCall) use ($describing): void {
|
||||
if ($describing === $this->describing && $describing === $testCall->describing) {
|
||||
$this->testCallProxies->chain($testCall);
|
||||
}
|
||||
};
|
||||
|
||||
$beforeEachTestCase = ChainableClosure::when(
|
||||
fn () => is_null($describing) || $this->__describeDescription === $describing, // @phpstan-ignore-line
|
||||
ChainableClosure::from(fn () => $testCaseProxies->chain($this), $this->closure)->bindTo($this, self::class), // @phpstan-ignore-line
|
||||
)->bindTo($this, self::class);
|
||||
$beforeEachTestCase = ChainableClosure::when(
|
||||
fn () => is_null($describing) || $this->__describeDescription === $describing, // @phpstan-ignore-line
|
||||
ChainableClosure::fromSameObject(fn () => $testCaseProxies->chain($this), $this->closure)->bindTo($this, self::class), // @phpstan-ignore-line
|
||||
)->bindTo($this, self::class);
|
||||
|
||||
assert($beforeEachTestCase instanceof Closure);
|
||||
assert($beforeEachTestCase instanceof Closure);
|
||||
|
||||
$this->testSuite->beforeEach->set(
|
||||
$this->filename,
|
||||
$this,
|
||||
$beforeEachTestCall,
|
||||
$beforeEachTestCase,
|
||||
);
|
||||
});
|
||||
$this->testSuite->beforeEach->set(
|
||||
$this->filename,
|
||||
$this,
|
||||
$beforeEachTestCall,
|
||||
$beforeEachTestCase,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,7 +86,6 @@ final class BeforeEachCall
|
||||
*/
|
||||
public function __call(string $name, array $arguments): self
|
||||
{
|
||||
|
||||
if (method_exists(TestCall::class, $name)) {
|
||||
$this->testCallProxies->add(Backtrace::file(), Backtrace::line(), $name, $arguments);
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ declare(strict_types=1);
|
||||
namespace Pest\PendingCalls;
|
||||
|
||||
use Closure;
|
||||
use Pest\PendingCalls;
|
||||
use Pest\Support\Backtrace;
|
||||
use Pest\TestSuite;
|
||||
|
||||
/**
|
||||
@ -13,6 +13,11 @@ use Pest\TestSuite;
|
||||
*/
|
||||
final class DescribeCall
|
||||
{
|
||||
/**
|
||||
* The current describe call.
|
||||
*/
|
||||
private static ?string $describing = null;
|
||||
|
||||
/**
|
||||
* Creates a new Pending Call.
|
||||
*/
|
||||
@ -25,9 +30,26 @@ final class DescribeCall
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* What is the current describing.
|
||||
*/
|
||||
public static function describing(): ?string
|
||||
{
|
||||
return self::$describing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the Call.
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
PendingCalls::endDescribe($this);
|
||||
self::$describing = $this->description;
|
||||
|
||||
try {
|
||||
($this->tests)();
|
||||
} finally {
|
||||
self::$describing = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -35,12 +57,14 @@ final class DescribeCall
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
*/
|
||||
public function __call(string $name, array $arguments): self
|
||||
public function __call(string $name, array $arguments): BeforeEachCall
|
||||
{
|
||||
foreach (PendingCalls::$testCalls as [$testCall]) {
|
||||
$testCall->{$name}(...$arguments); // @phpstan-ignore-line
|
||||
}
|
||||
$filename = Backtrace::file();
|
||||
|
||||
return $this;
|
||||
$beforeEachCall = new BeforeEachCall(TestSuite::getInstance(), $filename);
|
||||
|
||||
$beforeEachCall->describing = $this->description;
|
||||
|
||||
return $beforeEachCall->{$name}(...$arguments);
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,6 @@ use Pest\Factories\Covers\CoversClass;
|
||||
use Pest\Factories\Covers\CoversFunction;
|
||||
use Pest\Factories\Covers\CoversNothing;
|
||||
use Pest\Factories\TestCaseMethodFactory;
|
||||
use Pest\PendingCalls;
|
||||
use Pest\PendingCalls\Concerns\Describable;
|
||||
use Pest\Plugins\Only;
|
||||
use Pest\Support\Backtrace;
|
||||
@ -52,6 +51,8 @@ final class TestCall
|
||||
|
||||
$this->descriptionLess = $description === null;
|
||||
|
||||
$this->describing = DescribeCall::describing();
|
||||
|
||||
$this->testSuite->beforeEach->get($this->filename)[0]($this);
|
||||
}
|
||||
|
||||
@ -344,10 +345,11 @@ final class TestCall
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
PendingCalls::test($this, function () {
|
||||
if ($this->describing) {
|
||||
$this->testCaseMethod->description = '`'.$this->describing.'` '.$this->testCaseMethod->description;
|
||||
$this->testCaseMethod->describing = $this->describing;
|
||||
}
|
||||
|
||||
$this->testSuite->tests->set($this->testCaseMethod);
|
||||
});
|
||||
$this->testSuite->tests->set($this->testCaseMethod);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user