-
-
Notifications
You must be signed in to change notification settings - Fork 483
feat: extension for MakesHttpRequests #1481
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
Conversation
|
Hi, Thanks for the PR! But I do not understand why is this needed. If I look at the types for the |
|
I also believed this to be the case, but it is not. I built a demo repo you can try out https://github.com/peterfox/rector-status-rule-demo. If you use it with Larastan or not, it won't work because, for some reason, the return type found by PHPStan on those methods is I'm not sure if it's because it's a trait or something like that, but the only way I could make PHPStan give the correct return type was by adding the method as a doctag to the TestCase above the class. /*
* @method TestResponse get(string $path, array $headers)
*/ |
|
I just cloned your example repository, and made the following changes: diff --git a/phpstan.neon b/phpstan.neon
index f04455f..4578715 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -5,6 +5,7 @@ parameters:
paths:
- app/
+ - tests
# Level 9 is the highest level
level: 5
diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php
index 1eafba6..b377872 100644
--- a/tests/Feature/ExampleTest.php
+++ b/tests/Feature/ExampleTest.php
@@ -16,6 +16,8 @@ public function test_the_application_returns_a_successful_response()
{
$response = $this->get('/');
+ \PHPStan\dumpType($response);
+
$response->assertStatus(200);
}
}
Then when I run Also, tested the same thing in another project. Same result. I can't produce getting |
|
Also if I run Rector on your repo: so looks like it works correctly. |
|
@canvural thank you for showing me that technique to perform a debug. I can confirm that you're right PHPStan is dumping the correct type as you've demonstrated with your code. It looks rector is still failing for me which is a bit of a head scratcher. Would you be able to just provide me what versions you're using for Larastan, PHPStan, Rector and PHP if possible? |
|
I just did
But I also realized your repo uses your branch for the Larastan. I changed it to 2.2.9, still the same result though. |
|
Thank you, it does appear we're on the same versions, I wasn't sure if maybe it was a PHP version missmatch. To check, you might want to run Thank you for helping with this by the way. I greatly appreciate this goes beyond a maintainer's normal workflow. |
|
Yeah when I ran |
|
😆 well, I'm glad it's not just me then, though I hoped it was just something dumb I'd done. This might be a bug in rector somehow. The next step is to find out if that's the case, I guess. Are you okay with this PR staying open in the meantime? |
|
Honestly I don't think this PR will be the solution. The extension here kinda doesn't make sense. If you really find an issue later, you can open a new one. Hope you understand. PS. I'll also take a look at this issue, because it's interesting. |
|
@canvural totally understand 👍 . Please let me know if you find something or if I can help. Thank you for taking the time to sanity-check my PR at least. |
Changes
Adds an extension called
TestCaseMakesHttpRequestsExtensionand renamesTestCaseExtensiontoTestCaseMockeryExtension.The purpose of
TestCaseMakesHttpRequestsExtensionis to apply the return type ofIlluminate\Testing\TestResponseto HTTP request testing methods such asget,getJsonandpostetc.At current, these methods will return a
mixedtype meaning PHPStan can't process tests using these methods effectively.I'm new to making changes to PHPStan codebases and rules so if there's a better way of doing this or something I've missed in the PR, please feel free to guide me in the best way of handling this.
Breaking changes
None