-
Hello, assume you have following code in your setup beforeEach method: beforeEach(function () {
$this->user = User::factory()->withPersonalTeam()->create();
}); Is there any workaround to call the $this->user property without using a closure for your test? it('cannot be accessed by unauthenticated')
->actingAs($this->user)
->get(route('company.show', $this->user->currentTeam))
->assertStatus(302); this gives me a "Using $this when not in object context error". Do you have any ideas? |
Beta Was this translation helpful? Give feedback.
Answered by
geisi
Oct 26, 2021
Replies: 1 comment
-
Thanks to nuno ->you can achieve that by using the tap() method like mentioned in the docs. https://pestphp.com/docs/higher-order-tests it('cannot be accessed by unauthenticated')
->tap(fn() => actingAs($this->user))
->tap(fn() => get(route('company.show', $this->user->currentTeam)))
->assertStatus(302); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
geisi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to nuno ->you can achieve that by using the tap() method like mentioned in the docs. https://pestphp.com/docs/higher-order-tests