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

Missing PHPStorm plugin #5

Closed
nunomaduro opened this issue May 12, 2020 · 14 comments
Closed

Missing PHPStorm plugin #5

nunomaduro opened this issue May 12, 2020 · 14 comments

Comments

@nunomaduro
Copy link
Member

nunomaduro commented May 12, 2020

The IDE completion in PHPStorm can be better on closure based tests.

Problem: The $this variable inside closures don't get autocompletion on PHPStorm by default.

it('foo', function () {
    $this->ass // <-- here.
});

Workaround: Add a type hint just before the $this variable.

it('foo', function () {
    /* @var TestCase $this */
    $this->assertFoo // <-- here.
});

Solution: Develop a phpstorm-plugin that can hint phpstorm about this.

@BertvanHoekelen
Copy link
Collaborator

BertvanHoekelen commented May 13, 2020

This has also implications on the beforeEach methods. Dynamically defined properties are not "seen" by PHPStorm.

For example:

<?php 

beforeEach(function () {
    /* @var \Tests\TestCase $this */

    $this->fooMock = Mockery::mock(Foo::class);
    $this->fooMock->shouldReceive('execute')->andReturnTrue();
});

it('recognises dynamic properties', function () {
    /* @var \Tests\TestCase $this */
    
    $this->fooMock->expects('foo'); // No autocomplete on fooMock
});

Currently I can't seem to find a workaround for this.

@nunomaduro
Copy link
Member Author

I got in touch with PHPStorm team. They told me this is something that can be accomplished doing a plugin. We just need to find someone with the expertises to do it. I guess is just a question of having Pest open sourced. 👍

@olivernybroe
Copy link
Member

olivernybroe commented May 13, 2020

A workaround which could make this work without an IDE, would be to supply the class as the first argument in the function.

it('foo', function (TestCase $test) {
    $test->assertFoo;
});

$this can still be there, but if users want autocompletion they can do it like that.
Ofc. a PHPStorm plugin can do so it won't be needed in PHPStorm, but this solution could do so it can be used in vscode and so on.

@tbtmuse
Copy link

tbtmuse commented May 14, 2020

I can look into creating a Pest plugin for PHPStorm. Need a bit of a refresher first, I last worked on an intelliJ plugin a while ago.

This will most probably be a "Custom Language Support" plugin, but a "Framework Integration" plugin might allow for more functionality in future.

@nunomaduro
Copy link
Member Author

@tbtmuse That would be awesome. The PHPStorm core team told me that we should take a look into this: https://github.com/Haehnchen/idea-php-symfony2-plugin for grabbing some ideas.

@tbtmuse
Copy link

tbtmuse commented May 14, 2020

Perfect thanks.

@JoshMoreno
Copy link

@nunomaduro Any reason to not do what @olivernybroe suggested?
As he said, this would benefit developers that don't use phpstorm and $this can still be bound making this completely optional for the developer. And we wouldn't require a separate phpstorm plugin that someone has to end up maintaining.

@petemcfarlane
Copy link

I don't know if it's relevant to this issue exactly, but the biggest thing preventing me adopting pest is the PHPStorm integration with the test runner.

I've no idea how it works, sorry, but I know they support PHPUnit, PhpSpec and Behat and I think Codeception.

Screenshot 2020-05-28 at 15 18 21

This would be super useful for PHPStorm users! ❤️

@nunomaduro
Copy link
Member Author

Concerning autocompletions, the problem will be addressed in Pest 0.2.

@jonnywilliamson
Copy link

I don't know if it's relevant to this issue exactly, but the biggest thing preventing me adopting pest is the PHPStorm integration with the test runner.

I got a little bit further using PEST a few days ago to run tests in phpstorm. It's a bit ugly.

But unfortunately I had to give up as PHPStorm just doesn't seem ready yet for Pest.

https://github.com/pestphp/website/issues/39

@JoshMoreno
Copy link

@petemcfarlane @jonnywilliamson
I know this isn't ideal, but since pest passes all args to PHPUnit I've been using --filter for now. I'd much rather have it mapped to a keystroke but this will do for now.

With a test that looks like this...
```php
// RegisterTest.php

it('requires a password to be at least 8 characters', function () {
    // ...
});

Then run your tests...

# run a single file
./vendor/bin/pest --filter RegisterTest

# run a specific test (pretty cool this works!)
./vendor/bin/pest --filter 'requires a password to be at least 8 characters'

And if you want to make it shorter, create the following aliases. I have these in my ~/.zshrc.

alias pest="./vendor/bin/pest"
alias pestf="./vendor/bin/pest --filter"

If anyone wants to help out, I opened an issue so we can get the cli documented with examples; just been so busy lately!
See #17

@christophrumpel
Copy link

Hey people, just tried out the package and I really enjoy writing tests like that. (I didn't thought I would hehe)

For me missing right now is also more support for PhpStorm before I would integrate it in my daily workflow. Like @petemcfarlane said, being able to use PhpStorm's Test Runner would be awesome. I'm really used to go into a test and use a shortcut to run the current test, where my cursor is, or all tests of the current file. Not sure if this would be possible with a plugin?

That's just my first feedback regarding PEST and PhpStorm. Again thanks for the package 👍

@olivernybroe
Copy link
Member

olivernybroe commented Jun 10, 2020

Has anybody looked into this yet?

I think it makes sense to register pest as a new framework type, to have full control instead of trying to build on top of phpunit. At least my limited experience with plugin creation, says that building on top of the build in types often gives problems because there will be a lot of deprecations in future versions of phpstorm.

So I am thinking something in the likes of this?
image

image

@olivernybroe
Copy link
Member

olivernybroe commented Jul 15, 2020

So I can see we never updated this issue, there is a repository for the plugin and with a lot of working features.
A stable release has not been made yet, however it is pretty usable already.

https://github.com/pestphp/pest-intellij

@christophrumpel what you are asking for is possible in the plugin now btw.

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

No branches or pull requests

8 participants