zenstruck /
browser
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Zenstruck\Browser\Tests; |
||||||
| 4 | |||||||
| 5 | use Symfony\Component\Security\Core\User\InMemoryUser; |
||||||
| 6 | use Zenstruck\Browser\KernelBrowser; |
||||||
| 7 | use Zenstruck\Browser\Tests\Fixture\Kernel; |
||||||
| 8 | |||||||
| 9 | /** |
||||||
| 10 | * @author Kevin Bond <[email protected]> |
||||||
| 11 | */ |
||||||
| 12 | trait KernelBrowserTests |
||||||
| 13 | { |
||||||
| 14 | use BrowserKitBrowserTests; |
||||||
| 15 | |||||||
| 16 | /** |
||||||
| 17 | * @test |
||||||
| 18 | */ |
||||||
| 19 | public function can_use_kernel_browser_as_typehint(): void |
||||||
| 20 | { |
||||||
| 21 | $this->browser() |
||||||
| 22 | ->use(function(KernelBrowser $browser) { |
||||||
| 23 | $browser->visit('/redirect1'); |
||||||
| 24 | }) |
||||||
| 25 | ->assertOn('/page1') |
||||||
| 26 | ; |
||||||
| 27 | } |
||||||
| 28 | |||||||
| 29 | /** |
||||||
| 30 | * @test |
||||||
| 31 | */ |
||||||
| 32 | public function can_act_as_user(): void |
||||||
| 33 | { |
||||||
| 34 | if (!Kernel::securityEnabled()) { |
||||||
| 35 | $this->markTestSkipped('Only enable security-related tests in 5.3+'); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 36 | } |
||||||
| 37 | |||||||
| 38 | $this->browser() |
||||||
| 39 | ->throwExceptions() |
||||||
| 40 | ->actingAs(new InMemoryUser('kevin', 'pass')) |
||||||
| 41 | ->visit('/user') |
||||||
| 42 | ->assertSee('user: kevin/pass') |
||||||
| 43 | ; |
||||||
| 44 | } |
||||||
| 45 | |||||||
| 46 | /** |
||||||
| 47 | * @test |
||||||
| 48 | */ |
||||||
| 49 | public function can_enable_exception_throwing(): void |
||||||
| 50 | { |
||||||
| 51 | $this->expectException(\Exception::class); |
||||||
|
0 ignored issues
–
show
It seems like
expectException() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 52 | $this->expectExceptionMessage('exception thrown'); |
||||||
|
0 ignored issues
–
show
It seems like
expectExceptionMessage() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 53 | |||||||
| 54 | $this->browser() |
||||||
| 55 | ->throwExceptions() |
||||||
| 56 | ->visit('/exception') |
||||||
| 57 | ; |
||||||
| 58 | } |
||||||
| 59 | |||||||
| 60 | /** |
||||||
| 61 | * @test |
||||||
| 62 | */ |
||||||
| 63 | public function can_re_enable_catching_exceptions(): void |
||||||
| 64 | { |
||||||
| 65 | $browser = $this->browser(); |
||||||
| 66 | |||||||
| 67 | try { |
||||||
| 68 | $browser->throwExceptions()->visit('/exception'); |
||||||
| 69 | } catch (\Exception $e) { |
||||||
| 70 | $browser |
||||||
| 71 | ->catchExceptions() |
||||||
| 72 | ->visit('/exception') |
||||||
| 73 | ->assertStatus(500) |
||||||
| 74 | ; |
||||||
| 75 | |||||||
| 76 | return; |
||||||
| 77 | } |
||||||
| 78 | |||||||
| 79 | $this->fail('Exception was not caught.'); |
||||||
|
0 ignored issues
–
show
It seems like
fail() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 80 | } |
||||||
| 81 | |||||||
| 82 | /** |
||||||
| 83 | * @test |
||||||
| 84 | */ |
||||||
| 85 | public function can_enable_the_profiler(): void |
||||||
| 86 | { |
||||||
| 87 | $profile = $this->browser() |
||||||
| 88 | ->withProfiling() |
||||||
| 89 | ->visit('/page1') |
||||||
| 90 | ->profile() |
||||||
| 91 | ; |
||||||
| 92 | |||||||
| 93 | $this->assertTrue($profile->hasCollector('request')); |
||||||
|
0 ignored issues
–
show
The method
assertTrue() does not exist on Zenstruck\Browser\Tests\KernelBrowserTests. Did you maybe mean assert_on()?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 94 | } |
||||||
| 95 | |||||||
| 96 | protected function browser(): KernelBrowser |
||||||
| 97 | { |
||||||
| 98 | return $this->kernelBrowser(); |
||||||
| 99 | } |
||||||
| 100 | } |
||||||
| 101 |