diff --git a/src/Concerns/Testable.php b/src/Concerns/Testable.php index 1b248cc1..5c9e8b1f 100644 --- a/src/Concerns/Testable.php +++ b/src/Concerns/Testable.php @@ -142,7 +142,7 @@ trait Testable } $this->{$property} = ($this->{$property} instanceof Closure) - ? ChainableClosure::fromSameObject($this->{$property}, $hook) + ? ChainableClosure::bound($this->{$property}, $hook) : $hook; } @@ -190,7 +190,7 @@ trait Testable $beforeEach = TestSuite::getInstance()->beforeEach->get(self::$__filename)[1]; if ($this->__beforeEach instanceof Closure) { - $beforeEach = ChainableClosure::fromSameObject($this->__beforeEach, $beforeEach); + $beforeEach = ChainableClosure::bound($this->__beforeEach, $beforeEach); } $this->__callClosure($beforeEach, func_get_args()); @@ -204,7 +204,7 @@ trait Testable $afterEach = TestSuite::getInstance()->afterEach->get(self::$__filename); if ($this->__afterEach instanceof Closure) { - $afterEach = ChainableClosure::fromSameObject($this->__afterEach, $afterEach); + $afterEach = ChainableClosure::bound($this->__afterEach, $afterEach); } $this->__callClosure($afterEach, func_get_args()); diff --git a/src/PendingCalls.php b/src/PendingCalls.php deleted file mode 100644 index b5cbf04d..00000000 --- a/src/PendingCalls.php +++ /dev/null @@ -1,18 +0,0 @@ - is_null($describing) || $this->__describing === $describing, // @phpstan-ignore-line - ChainableClosure::fromSameObject(fn () => $proxies->chain($this), $this->closure)->bindTo($this, self::class), // @phpstan-ignore-line + ChainableClosure::bound(fn () => $proxies->chain($this), $this->closure)->bindTo($this, self::class), // @phpstan-ignore-line )->bindTo($this, self::class); assert($afterEachTestCase instanceof Closure); diff --git a/src/PendingCalls/BeforeEachCall.php b/src/PendingCalls/BeforeEachCall.php index 7543cf39..b51dafd2 100644 --- a/src/PendingCalls/BeforeEachCall.php +++ b/src/PendingCalls/BeforeEachCall.php @@ -58,7 +58,7 @@ final class BeforeEachCall $describing = $this->describing; $testCaseProxies = $this->testCaseProxies; - $beforeEachTestCall = function (TestCall $testCall) use ($describing) : void { + $beforeEachTestCall = function (TestCall $testCall) use ($describing): void { if ($describing !== $this->describing) { return; } @@ -70,7 +70,7 @@ final class BeforeEachCall $beforeEachTestCase = ChainableClosure::when( fn (): bool => is_null($describing) || $this->__describing === $describing, // @phpstan-ignore-line - ChainableClosure::fromSameObject(fn () => $testCaseProxies->chain($this), $this->closure)->bindTo($this, self::class), // @phpstan-ignore-line + ChainableClosure::bound(fn () => $testCaseProxies->chain($this), $this->closure)->bindTo($this, self::class), // @phpstan-ignore-line )->bindTo($this, self::class); assert($beforeEachTestCase instanceof Closure); diff --git a/src/Repositories/AfterEachRepository.php b/src/Repositories/AfterEachRepository.php index a3e823b2..ef88f375 100644 --- a/src/Repositories/AfterEachRepository.php +++ b/src/Repositories/AfterEachRepository.php @@ -28,7 +28,7 @@ final class AfterEachRepository if (array_key_exists($filename, $this->state)) { $fromAfterEachTestCase = $this->state[$filename]; - $afterEachTestCase = ChainableClosure::fromSameObject($fromAfterEachTestCase, $afterEachTestCase) + $afterEachTestCase = ChainableClosure::bound($fromAfterEachTestCase, $afterEachTestCase) ->bindTo($afterEachCall, $afterEachCall::class); } @@ -44,7 +44,7 @@ final class AfterEachRepository { $afterEach = $this->state[$filename] ?? NullClosure::create(); - return ChainableClosure::fromSameObject(function (): void { + return ChainableClosure::bound(function (): void { if (class_exists(Mockery::class)) { if ($container = Mockery::getContainer()) { /* @phpstan-ignore-next-line */ diff --git a/src/Repositories/BeforeEachRepository.php b/src/Repositories/BeforeEachRepository.php index 02fcc8a0..3a923df7 100644 --- a/src/Repositories/BeforeEachRepository.php +++ b/src/Repositories/BeforeEachRepository.php @@ -27,8 +27,8 @@ final class BeforeEachRepository if (array_key_exists($filename, $this->state)) { [$fromBeforeEachTestCall, $fromBeforeEachTestCase] = $this->state[$filename]; - $beforeEachTestCall = ChainableClosure::fromDifferentObjects($fromBeforeEachTestCall, $beforeEachTestCall); - $beforeEachTestCase = ChainableClosure::fromSameObject($fromBeforeEachTestCase, $beforeEachTestCase)->bindTo($beforeEachCall, $beforeEachCall::class); + $beforeEachTestCall = ChainableClosure::unbound($fromBeforeEachTestCall, $beforeEachTestCall); + $beforeEachTestCase = ChainableClosure::bound($fromBeforeEachTestCase, $beforeEachTestCase)->bindTo($beforeEachCall, $beforeEachCall::class); } assert($beforeEachTestCall instanceof Closure); diff --git a/src/Support/ChainableClosure.php b/src/Support/ChainableClosure.php index f5f27c66..b0257d11 100644 --- a/src/Support/ChainableClosure.php +++ b/src/Support/ChainableClosure.php @@ -29,9 +29,9 @@ final class ChainableClosure } /** - * Calls the given `$closure` and chains the `$next` closure. + * Calls the given `$closure` and chains the `$next` closure, "bound" to the same object. */ - public static function fromSameObject(Closure $closure, Closure $next): Closure + public static function bound(Closure $closure, Closure $next): Closure { return function () use ($closure, $next): void { if (! is_object($this)) { // @phpstan-ignore-line @@ -44,9 +44,9 @@ final class ChainableClosure } /** - * Calls the given `$closure` and chains the `$next` closure. + * Calls the given `$closure` and chains the `$next` closure, "unbound" of any object. */ - public static function fromDifferentObjects(Closure $closure, Closure $next): Closure + public static function unbound(Closure $closure, Closure $next): Closure { return function () use ($closure, $next): void { $closure(...func_get_args());