-1

I'm working on a Symfony project and due to most stuff working better in PhpStorm, I decided to move over to using PhpStorm.

If I'm writing PHPUnit tests, I use the following code a bunch of times:

$this->assertTrue($client->getResponse()->isSuccessful());

This is to test whether a route exists. However, PhpStorm gives the following error when hovering over isSuccessful():

Method 'isSuccessful() not found in \Symfony\Component\HttpKernel\Response

And when I use $client->getResponse()-> I get no quick select popup to select a method from.

I've tried adding the packages from Symfony that contains the code from $client and getResponse() to the External Libraries with PHP Include Path, like this:

PHP include path

However, this still doesn't solve it (this is what I had to do for PHPUnit to make assertTrue appear in the quick select when using $this->

How do I make this work correctly? I have the Symfony plugin enabled.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Joshua Bakker
  • 2,288
  • 3
  • 30
  • 63
  • Not a Symfony user here (more Laravel one) .. but I see `Symfony\Component\**HttpFoundation**\Response` class and not `Symfony\Component\**HttpKernel**\Response`. Could be wrong class resolution by IDE (`Response`) or bad PHPDoc signature... – LazyOne Aug 20 '19 at 12:56
  • `$client` is of type `KernelBrowser`, which extends `Client` from `framework-bundle`, which extends `HttpKernelBrowser`. That class contains the PHPDoc ` * @method Response getResponse() A Response instance` (this `Response` has no typing apparently) and the class extends `Client` from `http-kernel`. That contains the same `@method` (which is from type `HttpFoundation/Response`, and the class extends `AbstractBrowser`, which extends from `Client` in `browser-kit` which contains the real `getResponse` method. Sorry for the hard explaination but AFAIK it doesn't use the `HttpKernel/Response`. – Joshua Bakker Aug 20 '19 at 13:06
  • For me it works OK even in Laravel app. Code is (will not execute as needs proper params for constructor, but shows how it works in IDE): `$client = new HttpKernelBrowser(null); $client->getResponse()->isSuccessful();` -- no warnings for `isSuccessful()` as `getResponse()` correctly detected as returning instance of `Symfony\Component\HttpFoundation\Response`. – LazyOne Aug 20 '19 at 13:07
  • However, I use the following to create my `$client` (should've mentioned): `$client = $this->createClient();` which returns `KernelBrowser` instead of `HttpKernelBrowser`. Maybe that has something to do with it? – Joshua Bakker Aug 20 '19 at 13:10
  • 1
    So right now I may suggest: 1) try `File | Invalidate caches` and restart IDE; 2) Place caret on `getResponse` in `$client->getResponse()->` line and see what type it is (Ctrl+Q or "View | Quick Documentation"). Based on your initial message it resolves to the wrong class/namespace... – LazyOne Aug 20 '19 at 13:10
  • *"which returns KernelBrowser instead of HttpKernelBrowser"* -- Sadly I do not have KernelBrowser class in my codebase (must be an additional composer package).. so not sure about it. – LazyOne Aug 20 '19 at 13:12
  • Thanks, the `File | Invalidate caches` did work, though I'm not sure what actually fixed the problem entirely. – Joshua Bakker Aug 20 '19 at 13:14
  • If you can create a blank project (with all dependencies) that would illustrate the issue that I can download and try on my computer, I can have a deeper look at what might be causing the issue. – LazyOne Aug 20 '19 at 13:15
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/198183/discussion-between-joshua-bakker-and-lazyone). – Joshua Bakker Aug 20 '19 at 13:15

1 Answers1

-1

Okay, I think the reason why it didn't work at first was because I didn't create the project but instead cloned a project from our server.

With a new project, it worked how it should. With my cloned project, I had to click Invalidate Caches / Restart... in the File menu. This fixed the problem.

(thanks to LazyOne for telling me to try the Invalidate Caches thing).

--

According to LazyOne it doesn't matter it's a cloned repo. It's mostly just a project with corrupt indexes/caches. Invalidate Caches fixed the bug.

Joshua Bakker
  • 2,288
  • 3
  • 30
  • 63
  • 1
    TBH the way how you get your source code should make no difference .. as IDE keeps indexes separate for each project (for project code; based on file path AFAIK). So it must be something else that caused this (e.g. caches/indexes corruption; some plugins can introduce such issues, e.g. .gitignore plugin did it quite few times in the past). In any case: "Invalidate Caches" is the usual suggestion when something suddenly stopped working / code analysis shows unexpected things. Glad it helped. – LazyOne Aug 20 '19 at 15:34