From 3ff71a4563c3753817ff437f25d12ff352f90aad Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Fri, 1 Oct 2021 15:52:02 +0200 Subject: [PATCH 1/4] adds failing test --- tests/Features/Exceptions.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Features/Exceptions.php b/tests/Features/Exceptions.php index 9970c2a9..8d252e3b 100644 --- a/tests/Features/Exceptions.php +++ b/tests/Features/Exceptions.php @@ -1,5 +1,7 @@ expectException(InvalidArgumentException::class); @@ -37,3 +39,11 @@ it('can just define the message if given condition is true', function () { it('can just define the message if given condition is 1', function () { throw new Exception('Something bad happened'); })->throwsIf(1, 'Something bad happened'); + +it('can handle a skipped test if it is trying to catch an exception', function () { + expect(1)->toBe(2); +})->throws(ExpectationFailedException::class)->skip('this test should be skipped')->only(); + +it('debug', function () { + expect(2)->toBe(2); +})->skip('this test should be skipped')->only(); From e042bf7d3aafbb5d418f4858a9d7ca850a5b3e3d Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Fri, 1 Oct 2021 15:52:45 +0200 Subject: [PATCH 2/4] removes expection expectations if test is marked as skipped --- src/Factories/TestCaseFactory.php | 4 ++++ src/Support/HigherOrderMessageCollection.php | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index bc75f5c1..d2a98c88 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -140,6 +140,10 @@ final class TestCaseFactory $proxies = $this->proxies; $factoryTest = $this->test; + if ($chains->hasMessage('markTestSkipped')) { + $proxies->forgetMessage('expectException'); + } + /** * @return mixed */ diff --git a/src/Support/HigherOrderMessageCollection.php b/src/Support/HigherOrderMessageCollection.php index a6634685..68e5c3df 100644 --- a/src/Support/HigherOrderMessageCollection.php +++ b/src/Support/HigherOrderMessageCollection.php @@ -69,4 +69,24 @@ final class HigherOrderMessageCollection 0, ); } + + public function hasMessage(string $name): bool + { + foreach ($this->messages as $message) { + if ($message->name === $name) { + return true; + } + } + + return false; + } + + public function forgetMessage(string $name): void + { + foreach ($this->messages as $index => $message) { + if ($message->name === $name) { + unset($this->messages[$index]); + } + } + } } From 2a649bdfc06e9564614f1d101f434751da22e3ad Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Sat, 2 Oct 2021 09:09:47 +0200 Subject: [PATCH 3/4] revert previous solution and invert chain and proxy calls in TestCaseFactory.php --- src/Factories/TestCaseFactory.php | 6 +----- src/Support/HigherOrderMessageCollection.php | 20 -------------------- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index d2a98c88..42c3ca6e 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -140,16 +140,12 @@ final class TestCaseFactory $proxies = $this->proxies; $factoryTest = $this->test; - if ($chains->hasMessage('markTestSkipped')) { - $proxies->forgetMessage('expectException'); - } - /** * @return mixed */ $test = function () use ($chains, $proxies, $factoryTest) { - $proxies->proxy($this); $chains->chain($this); + $proxies->proxy($this); /* @phpstan-ignore-next-line */ return call_user_func(Closure::bind($factoryTest, $this, get_class($this)), ...func_get_args()); diff --git a/src/Support/HigherOrderMessageCollection.php b/src/Support/HigherOrderMessageCollection.php index 68e5c3df..a6634685 100644 --- a/src/Support/HigherOrderMessageCollection.php +++ b/src/Support/HigherOrderMessageCollection.php @@ -69,24 +69,4 @@ final class HigherOrderMessageCollection 0, ); } - - public function hasMessage(string $name): bool - { - foreach ($this->messages as $message) { - if ($message->name === $name) { - return true; - } - } - - return false; - } - - public function forgetMessage(string $name): void - { - foreach ($this->messages as $index => $message) { - if ($message->name === $name) { - unset($this->messages[$index]); - } - } - } } From b0fbe541816b5813062c3bbec5a151cfb987f5f8 Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Sat, 2 Oct 2021 09:15:52 +0200 Subject: [PATCH 4/4] removes duplicated test --- tests/Features/Exceptions.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/Features/Exceptions.php b/tests/Features/Exceptions.php index 8d252e3b..22d9d4ea 100644 --- a/tests/Features/Exceptions.php +++ b/tests/Features/Exceptions.php @@ -43,7 +43,3 @@ it('can just define the message if given condition is 1', function () { it('can handle a skipped test if it is trying to catch an exception', function () { expect(1)->toBe(2); })->throws(ExpectationFailedException::class)->skip('this test should be skipped')->only(); - -it('debug', function () { - expect(2)->toBe(2); -})->skip('this test should be skipped')->only();