Passed
Pull Request — 1.x (#3)
by Kevin
02:01
created

can_enable_exception_throwing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
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
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 */
12
trait KernelBrowserTests
13
{
14
    use BrowserKitBrowserTests;
15
16
    /**
17
     * @test
18
     */
19
    public function can_act_as_user(): void
20
    {
21
        if (!\method_exists(SymfonyKernelBrowser::class, 'loginUser')) {
22
            $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

22
            $this->/** @scrutinizer ignore-call */ 
23
                   markTestSkipped(SymfonyKernelBrowser::class.'::loginUser() is only available in Symfony 5.1+.');
Loading history...
23
        }
24
25
        $this->browser()
26
            ->throwExceptions()
27
            ->actingAs(new User('kevin', 'pass'))
28
            ->visit('/user')
29
            ->assertSee('user: kevin/pass')
30
        ;
31
    }
32
33
    /**
34
     * @test
35
     */
36
    public function can_enable_exception_throwing(): void
37
    {
38
        $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

38
        $this->/** @scrutinizer ignore-call */ 
39
               expectException(\Exception::class);
Loading history...
39
        $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

39
        $this->/** @scrutinizer ignore-call */ 
40
               expectExceptionMessage('exception thrown');
Loading history...
40
41
        $this->browser()
42
            ->throwExceptions()
43
            ->visit('/exception')
44
        ;
45
    }
46
47
    /**
48
     * @test
49
     */
50
    public function can_re_enable_catching_exceptions(): void
51
    {
52
        $browser = $this->browser();
53
54
        try {
55
            $browser->throwExceptions()->visit('/exception');
56
        } catch (\Exception $e) {
57
            $browser
58
                ->catchExceptions()
59
                ->visit('/exception')
60
                ->assertStatus(500)
61
            ;
62
63
            return;
64
        }
65
66
        $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

66
        $this->/** @scrutinizer ignore-call */ 
67
               fail('Exception was not caught.');
Loading history...
67
    }
68
69
    /**
70
     * @test
71
     */
72
    public function can_enable_the_profiler(): void
73
    {
74
        $profile = $this->browser()
75
            ->withProfiling()
76
            ->visit('/page1')
77
            ->profile()
78
        ;
79
80
        $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

80
        $this->/** @scrutinizer ignore-call */ 
81
               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...
81
    }
82
83
    protected function browser(): KernelBrowser
84
    {
85
        return $this->kernelBrowser();
86
    }
87
}
88