Closed girardotcl closed 2 days ago
I'm not Pest expert, but looking at Pest internals, more convinent way to get a current test case instance would be:
$test = TestSuite::getInstance()->test;
If you need this to be typed for PHPStan, you can go with assertion that will make PHPStan narrow $test
type if you use phpstan-phpunit
extension:
assert($test instanceof TestCase); // class of test case you expect to have
Thanks for your advice @rutek , I'll make some improvements.
May I still hope an "official" answer ?
pest-plugin-laravel :
/**
* Set the currently logged in user for the application.
*
* @return TestCase
*/
function actingAs(Authenticatable $user, string $driver = null)
{
return test()->actingAs(...func_get_args());
}
I have my anwser
🧑🏭 Context
I have security and code quality needs, i can't simply avoid errors with an ignore line in
phpstan.neon
like this :I find the way by replacing all
$this
withtest()
:Before, with Larastan error
test('users can access categories edit route', function (User $user) { actingAs($user) ->get(route('admin.category.edit', ['category' => $this->category->id])) ->assertOk(); }) ->with('my user dataset');
// ... other tests
I made some
dd()
and check the content, it seems ok.❓Question
But before review all my test suite, I need a confirmation :
⚠️ Is this a solid and sustainable solution from this package point of view ? ⚠️
Pest Version
2.8.1
PHP Version
8.2.13
Operation System
Windows & MacOS