Passed
Push — 1.x ( 5a4286...a604cc )
by Kevin
01:41
created

can_re_enable_catching_exceptions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 10
nc 2
nop 0
dl 0
loc 17
rs 9.9332
c 1
b 0
f 1
1
<?php
2
3
namespace Zenstruck\Browser\Tests;
4
5
use Zenstruck\Browser\KernelBrowser;
6
use Zenstruck\Browser\Test\HasKernelBrowser;
7
8
/**
9
 * @author Kevin Bond <[email protected]>
10
 */
11
trait KernelBrowserTests
12
{
13
    use BrowserKitBrowserTests, HasKernelBrowser;
14
15
    /**
16
     * @test
17
     */
18
    public function can_enable_exception_throwing(): void
19
    {
20
        $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

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

21
        $this->/** @scrutinizer ignore-call */ 
22
               expectExceptionMessage('exception thrown');
Loading history...
22
23
        $this->browser()
24
            ->throwExceptions()
25
            ->visit('/exception')
26
        ;
27
    }
28
29
    /**
30
     * @test
31
     */
32
    public function can_re_enable_catching_exceptions(): void
33
    {
34
        $browser = $this->browser();
35
36
        try {
37
            $browser->throwExceptions()->visit('/exception');
38
        } catch (\Exception $e) {
39
            $browser
40
                ->catchExceptions()
41
                ->visit('/exception')
42
                ->assertStatus(500)
43
            ;
44
45
            return;
46
        }
47
48
        $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

48
        $this->/** @scrutinizer ignore-call */ 
49
               fail('Exception was not caught.');
Loading history...
49
    }
50
51
    /**
52
     * @test
53
     */
54
    public function can_enable_the_profiler(): void
55
    {
56
        $profile = $this->browser()
57
            ->withProfiling()
58
            ->visit('/page1')
59
            ->profile()
60
        ;
61
62
        $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

62
        $this->/** @scrutinizer ignore-call */ 
63
               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...
63
    }
64
65
    protected static function browserClass(): string
66
    {
67
        return KernelBrowser::class;
68
    }
69
}
70