Pest: Some notes from my first day with Pest

Created on 5 May 2020  路  6Comments  路  Source: pestphp/pest

Gonna keep this updated with things I find today as I rewrite my tests to Pest

  • The test contents are inverted in this page of the docs. On the let's head over to both ..Test.php files and modify the content to: the unit has feature test contents and otherwise.
  • It's somewhat annoying I can't use routes in higher-order tests [1]
  • Being able to incrementally-adopt Pest is really really nice
  • I think Reinink already said it, but a Pest shift would be really useful for migration
  • IDE autocompletion is way better than I thought it'd be, but it's annoying that the return values of the $this-> methods are not detected, and especially annoying when working with TestResponses (using VSCode)
  • Really missed using the Better PHPUnit extension by Caleb, which allows you to run a test while you're inside the code by pressing cmd+t, so I made a fork that works with Pest.
  • When porting tests I expected assertGuest() to work the same as assertCount() but it seems the magic methods are limited to PHPUnit's default assertions. I understand this is supposed to be Laravel agnostic, but it would be cool to have all TestClass methods available without $this.
  • I don't know if this is possible, but setting groups per file (and then merging in custom defined ones on individual tests) would be useful to avoid repetition.
  • I assume this is in the roadmap, but it would be nice if Collision's php artisan test command ran Pest if it's installed, or at least provided some way of customizing the binary-


[1]:

Screenshot 2020-05-05 at 11 21 57

All 6 comments

Really missed using the Better PHPUnit extension by Caleb, which allows you to run a test while you're inside the code by pressing cmd+t, so I made a fork that works with Pest.

cc @calebporzio

Thinking about the Better PHPUnit extension, could you just create an executable that checks if vendor/bin/pest is available and if not, fall back to vendor/bin/phpunit? And then set the better-phpunit.phpunitBinary to use that?


Example

#!/usr/bin/env bash
if [[ -f 'vendor/bin/pest' ]]; then
   vendor/bin/pest $@
elif [[ -f 'vendor/bin/phpunit' ]]; then
   vendor/bin/phpunit $@
else
   echo No Pest or PHPUnit binaries were found.
   exit 1
fi

(I haven't used the extension as I use PhpStorm, but it looks like the fork just is a search and replace?)

@owenvoke Yeah, I basically changed the regex (and had to change the filter a little also to avoid wrapping the whole thing in regex), but the rest of it is just search+replace to avoid conflicts with his extension.

That's also why the script above wouldn't work btw, Caleb's extension wraps the method name in a regex which is required to filter in phpunit but I couldn't get Pest to work until I removed it.

Ah, I hadn't seen the RegEx changes. Nice. :+1:

I also reached out to him on Twitter (since I didn't know he was in here) asking if he'd prefer me to PR the changes under some config option or to just keep the fork 馃槃

  • [x] The test contents are inverted in this page of the docs. On the let's head over to both ..Test.php files and modify the content to: the unit has feature test contents and otherwise.

Fixed.

  • [x] It's somewhat annoying I can't use routes in higher-order tests [1]

lol, yeah. High order tests needs arguments that can be computed a static time - before even the framework gets booted.

  • [x] Being able to incrementally-adopt Pest is really really nice

Thanks.

  • [x] I think Reinink already said it, but a Pest shift would be really useful for migration

Let's wait for the community to fix this.

  • [x] IDE autocompletion is way better than I thought it'd be, but it's annoying that the return values of the $this-> methods are not detected, and especially annoying when working with TestResponses (using VSCode)

Let's wait for the community to fix this.

Can you pull request to @calebporzio that?

  • [x] When porting tests I expected assertGuest() to work the same as assertCount() but it seems the magic methods are limited to PHPUnit's default assertions. I understand this is supposed to be Laravel agnostic, but it would be cool to have all TestClass methods available without $this.

no plans.

  • [x] I don't know if this is possible, but setting groups per file (and then merging in custom defined ones on individual tests) would be useful to avoid repetition.
uses(..)->group('name')->in('folder-or-subfolder');
  • [x] I assume this is in the roadmap, but it would be nice if Collision's php artisan test command ran Pest if it's installed, or at least provided some way of customizing the binary-

Fixed: https://github.com/nunomaduro/collision/commit/3a08241eb1ff4d1daf1cf6baaf07c832f9b2eed6.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zingimmick picture zingimmick  路  3Comments

olivernybroe picture olivernybroe  路  7Comments

rihardssceredins picture rihardssceredins  路  5Comments

albertpratomo picture albertpratomo  路  7Comments

Synchro picture Synchro  路  5Comments