From d969eaac2ceb98c788a2cca6614fa2dc63116222 Mon Sep 17 00:00:00 2001 From: luke Date: Wed, 8 Dec 2021 08:58:42 +0000 Subject: [PATCH 1/3] Adds support for chaining `hasNoExpectations` to the test method. --- src/PendingCalls/TestCall.php | 7 +++++++ tests/Features/HasNoExpectations.php | 11 +++++++++++ 2 files changed, 18 insertions(+) create mode 100644 tests/Features/HasNoExpectations.php diff --git a/src/PendingCalls/TestCall.php b/src/PendingCalls/TestCall.php index 0d1cd17c..7823cda6 100644 --- a/src/PendingCalls/TestCall.php +++ b/src/PendingCalls/TestCall.php @@ -160,6 +160,13 @@ final class TestCall return $this; } + public function hasNoExpectations(): TestCall + { + $this->testCaseMethod->proxies->add(Backtrace::file(), Backtrace::line(), 'expectNotToPerformAssertions', []); + + return $this; + } + /** * Saves the property accessors to be used on the target. */ diff --git a/tests/Features/HasNoExpectations.php b/tests/Features/HasNoExpectations.php new file mode 100644 index 00000000..a5804466 --- /dev/null +++ b/tests/Features/HasNoExpectations.php @@ -0,0 +1,11 @@ +expectNotToPerformAssertions(); + + $result = 1 + 1; +}); + +it('allows performing no expectations without being risky', function () { + $result = 1 + 1; +})->hasNoExpectations(); From e1a30e3c9206599ffe90bd90a2553b26558d10b8 Mon Sep 17 00:00:00 2001 From: luke Date: Wed, 8 Dec 2021 09:01:16 +0000 Subject: [PATCH 2/3] Add method comment. --- src/PendingCalls/TestCall.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/PendingCalls/TestCall.php b/src/PendingCalls/TestCall.php index 7823cda6..53405722 100644 --- a/src/PendingCalls/TestCall.php +++ b/src/PendingCalls/TestCall.php @@ -160,6 +160,9 @@ final class TestCall return $this; } + /** + * Informs the test runner that no expectations happen in this test. + */ public function hasNoExpectations(): TestCall { $this->testCaseMethod->proxies->add(Backtrace::file(), Backtrace::line(), 'expectNotToPerformAssertions', []); From 53c20d9cd2877f8a0f18df940a22d2e5562de1dc Mon Sep 17 00:00:00 2001 From: Luke Downing Date: Tue, 22 Mar 2022 13:19:23 +0000 Subject: [PATCH 3/3] Renames method to `throwsNoExceptions`. --- src/PendingCalls/TestCall.php | 6 ++++-- .../{HasNoExpectations.php => ThrowsNoExceptions.php} | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) rename tests/Features/{HasNoExpectations.php => ThrowsNoExceptions.php} (90%) diff --git a/src/PendingCalls/TestCall.php b/src/PendingCalls/TestCall.php index 53405722..56172023 100644 --- a/src/PendingCalls/TestCall.php +++ b/src/PendingCalls/TestCall.php @@ -161,9 +161,11 @@ final class TestCall } /** - * Informs the test runner that no expectations happen in this test. + * Informs the test runner that no expectations happen in this test, + * and its purpose is simply to check whether the given code can + * be executed without throwing exceptions. */ - public function hasNoExpectations(): TestCall + public function throwsNoExceptions(): TestCall { $this->testCaseMethod->proxies->add(Backtrace::file(), Backtrace::line(), 'expectNotToPerformAssertions', []); diff --git a/tests/Features/HasNoExpectations.php b/tests/Features/ThrowsNoExceptions.php similarity index 90% rename from tests/Features/HasNoExpectations.php rename to tests/Features/ThrowsNoExceptions.php index a5804466..98f38574 100644 --- a/tests/Features/HasNoExpectations.php +++ b/tests/Features/ThrowsNoExceptions.php @@ -8,4 +8,4 @@ it('allows access to the underlying expectNotToPerformAssertions method', functi it('allows performing no expectations without being risky', function () { $result = 1 + 1; -})->hasNoExpectations(); +})->throwsNoExceptions();