-
Notifications
You must be signed in to change notification settings - Fork 465
[8.1] Support never
return type
#1184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
davedevelopment
merged 3 commits into
mockery:master
from
ghostwriter:bugfix/support-never-return-type
Jul 21, 2022
Merged
[8.1] Support never
return type
#1184
davedevelopment
merged 3 commits into
mockery:master
from
ghostwriter:bugfix/support-never-return-type
Jul 21, 2022
+50
−1
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
I'm not sure how to go about testing the Would love some feedback and or guidance. |
@ghostwriter this is one way, but might be too flaky to bother diff --git tests/PHP81/Php81LanguageFeaturesTest.php tests/PHP81/Php81LanguageFeaturesTest.php
index 52b9933..59eadaf 100644
--- tests/PHP81/Php81LanguageFeaturesTest.php
+++ tests/PHP81/Php81LanguageFeaturesTest.php
@@ -92,6 +92,27 @@ class Php81LanguageFeaturesTest extends MockeryTestCase
$this->expectException(RuntimeException::class);
$mock->throws();
}
+
+ /** @test */
+ public function it_can_mock_a_class_with_a_never_returning_type_hint_with_exit()
+ {
+ $mock = Mockery::mock(NeverReturningTypehintClass::class)->makePartial();
+
+ $pid = pcntl_fork();
+
+ if (-1 == $pid) {
+ $this->markTestSkipped("Couldn't fork for exit test");
+
+ return;
+ } else if ($pid) {
+ pcntl_waitpid($pid, $status);
+ $this->assertEquals(123, pcntl_wexitstatus($status));
+
+ return;
+ }
+
+ $mock->exits();
+ }
}
interface LoggerInterface
@@ -154,7 +175,7 @@ class NeverReturningTypehintClass
public function exits(): never
{
- exit;
+ exit(123);
}
}
class IntersectionTypeHelperClass |
26ece39
to
78e0fb7
Compare
That's perfect @davedevelopment👌🏾, Thank you! |
78e0fb7
to
8a7b8fb
Compare
Co-Authored-By: Dave Marshall <dave@atstsolutions.co.uk> Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
8a7b8fb
to
ec2443a
Compare
Any chance this could be looked at? It would help us integrate tests that are currently failing as one of our projects has recently updated to PHP 8.1. |
Thank you! |
This was referenced Apr 19, 2023
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch resolves #1167, via the following changes:
return
statement for anever
return typehint.A function/method that is declared with the
never
return type indicates that it will neverreturn
a value, and always throws an exception or terminates with adie/exit
call.