Skip to content
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

Phake annotation recognition and mock class method completion #19

Open
cuberinooo opened this issue May 8, 2023 · 2 comments
Open

Phake annotation recognition and mock class method completion #19

cuberinooo opened this issue May 8, 2023 · 2 comments

Comments

@cuberinooo
Copy link

Sry for taking too long here are the issues in more details:

Phake Annotation:

Phake brings the feature that you can use annotation for mocking.
E.g.

#[\Phake\Mock]
private YourClassThatYouWantToMock $class;

and you will need to put this on your setUp Method:
\Phake::initAnnotations($this);

Unfortunately the plugin does not recognize the Annotation (see screenshot):
undefined class Mock

and if I import this the IDE will call "Import is not used" as you can see here:
mock_package is not used

Mock class method auto completion:

Lets say we have the following class that we want to mock:

class foo
{
    public function getBar(): string
    {
        return 'foo';
    }
}

I use the phake mock annotation to mock this class. (Also I could do this with the Phake::mock(...)

#[\Phake\Mock]
private Foo $foo;

I really would love to see a autocompletion for methods of mocked classes as in PHPUnit.

Here I would expect the getBar() Method as suggestion.
missing autocompletion for mock class foo

These are just minor issues as I already said Im really grateful for this plugin and with that I wanna say thank you again ;)

PS: Regarding to Phake Annotation I can`t say if this is a Plugin problem or a problem with the package itself.

@pierredup
Copy link
Member

@cuberinooo Thanks for the report.

Unfortunately the plugin does not recognize the Annotation (see screenshot):

I think this is because the \Phake\Mock class doesn't actually exist. It looks like Phake just uses a placeholder as the attribute, but the class in the attribute is not part of the source code. I don't think this is something the plugin can fix, but I'll look into it. Ideally, the Phake\Mock class should just be added to the Phake source code, then this will resolve the issue (as well as the "Import is not used" issue as well).

I really would love to see a autocompletion for methods of mocked classes as in PHPUnit.

Here I would expect the getBar() Method as suggestion.

This is definitely something that can be fixed in the plugin, but I will only be able to get to it in a week or two.

@pierredup
Copy link
Member

I created phake/phake#318 to address the first issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants