Passed
Pull Request — 1.x (#23)
by Wouter
02:36
created

KernelBrowserTests::browser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Zenstruck\Browser\Tests;
4
5
use Symfony\Bundle\FrameworkBundle\KernelBrowser as SymfonyKernelBrowser;
6
use Symfony\Component\Security\Core\User\User;
7
use Zenstruck\Browser\KernelBrowser;
8
use Zenstruck\Browser\Test\HasBrowser;
9
10
/**
11
 * @author Kevin Bond <[email protected]>
12
 */
13
trait KernelBrowserTests
14
{
15
    use BrowserKitBrowserTests, HasBrowser;
16
17
    /**
18
     * @test
19
     */
20
    public function can_use_kernel_browser_as_typehint(): void
21
    {
22
        $this->browser()
23
            ->use(function(KernelBrowser $browser) {
24
                $browser->visit('/redirect1');
25
            })
26
            ->assertOn('/page1')
27
        ;
28
    }
29
30
    /**
31
     * @test
32
     */
33
    public function can_act_as_user(): void
34
    {
35
        if (!\method_exists(SymfonyKernelBrowser::class, 'loginUser')) {
36
            $this->markTestSkipped(SymfonyKernelBrowser::class.'::loginUser() is only available in Symfony 5.1+.');
0 ignored issues
show
Bug introduced by
It seems like markTestSkipped() 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 ignore-call  annotation

36
            $this->/** @scrutinizer ignore-call */ 
37
                   markTestSkipped(SymfonyKernelBrowser::class.'::loginUser() is only available in Symfony 5.1+.');
Loading history...
37
        }
38
39
        $this->browser()
40
            ->throwExceptions()
0 ignored issues
show
Bug introduced by
The method throwExceptions() does not exist on Zenstruck\Browser. It seems like you code against a sub-type of Zenstruck\Browser such as Zenstruck\Browser\KernelBrowser. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
            ->/** @scrutinizer ignore-call */ throwExceptions()
Loading history...
41
            ->actingAs(new User('kevin', 'pass'))
42
            ->visit('/user')
43
            ->assertSee('user: kevin/pass')
44
        ;
45
    }
46
47
    /**
48
     * @test
49
     */
50
    public function can_enable_exception_throwing(): void
51
    {
52
        $this->expectException(\Exception::class);
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

52
        $this->/** @scrutinizer ignore-call */ 
53
               expectException(\Exception::class);
Loading history...
53
        $this->expectExceptionMessage('exception thrown');
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

53
        $this->/** @scrutinizer ignore-call */ 
54
               expectExceptionMessage('exception thrown');
Loading history...
54
55
        $this->browser()
56
            ->throwExceptions()
57
            ->visit('/exception')
58
        ;
59
    }
60
61
    /**
62
     * @test
63
     */
64
    public function can_re_enable_catching_exceptions(): void
65
    {
66
        $browser = $this->browser();
67
68
        try {
69
            $browser->throwExceptions()->visit('/exception');
70
        } catch (\Exception $e) {
71
            $browser
72
                ->catchExceptions()
0 ignored issues
show
Bug introduced by
The method catchExceptions() does not exist on Zenstruck\Browser. It seems like you code against a sub-type of Zenstruck\Browser such as Zenstruck\Browser\KernelBrowser. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

72
                ->/** @scrutinizer ignore-call */ 
73
                  catchExceptions()
Loading history...
73
                ->visit('/exception')
74
                ->assertStatus(500)
75
            ;
76
77
            return;
78
        }
79
80
        $this->fail('Exception was not caught.');
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

80
        $this->/** @scrutinizer ignore-call */ 
81
               fail('Exception was not caught.');
Loading history...
81
    }
82
83
    /**
84
     * @test
85
     */
86
    public function can_enable_the_profiler(): void
87
    {
88
        $profile = $this->browser()
89
            ->withProfiling()
0 ignored issues
show
Bug introduced by
The method withProfiling() does not exist on Zenstruck\Browser. It seems like you code against a sub-type of Zenstruck\Browser such as Zenstruck\Browser\KernelBrowser. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

89
            ->/** @scrutinizer ignore-call */ withProfiling()
Loading history...
90
            ->visit('/page1')
91
            ->profile()
92
        ;
93
94
        $this->assertTrue($profile->hasCollector('request'));
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

94
        $this->/** @scrutinizer ignore-call */ 
95
               assertTrue($profile->hasCollector('request'));

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...
95
    }
96
}
97