Pest helper to get $this with IDE support

By @samuel · 2021-08-30 13:04

Pest helper to get $this with IDE support

I like to create a helper like this when using Pest:

function please(): TestCase
{
    return TestSuite::getInstance()->test;
}

And then inside tests, instead of using $this:

test('the about page is accessible', function () {
    $this->get('/about')->assertSuccessful();
});

I use the please() helper:

test('the about page is accessible', function () {
    please()->get('/about')->assertSuccessful();
});

This provides perfect IDE support in my editor (VSCode) and makes the tests more polite 😎