Passed
Push — master ( 7c6fc7...70457d )
by Maksim
02:54
created

DebugBarExceptionRouteTest::getEnvironmentSetUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Orchestra\Testbench\BrowserKit\Tests;
4
5
use Barryvdh\Debugbar\ServiceProvider;
6
use MaksimM\ConditionalDebugBar\ConditionalDebugBarServiceProvider;
7
use MaksimM\ConditionalDebugBar\DebugModeBootValidators\TestingDebugBarBootValidator;
8
use MaksimM\ConditionalDebugBar\Http\Middleware\OptionalDebugBar;
9
use Mockery\Exception;
10
use Orchestra\Testbench\BrowserKit\TestCase;
11
12
class DebugBarExceptionRouteTest extends TestCase
13
{
14
    private $blank_page = '<html xmlns="http://www.w3.org/1999/html"><head></head><body</body</html>';
15
16
    /** @test */
17
    public function validatePage()
18
    {
19
        $crawler = $this->call('GET', 'page-with-middleware');
20
        $this->assertNotEquals($this->blank_page, $crawler->getContent());
21
        $this->assertContains('Test Exception', $crawler->getContent());
22
        $this->assertContains('PhpDebugBar.DebugBar', $crawler->getContent());
23
    }
24
25
    protected function getPackageProviders($app)
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

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

25
    protected function getPackageProviders(/** @scrutinizer ignore-unused */ $app)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
    {
27
        return [ServiceProvider::class, ConditionalDebugBarServiceProvider::class];
28
    }
29
30
    /**
31
     * Define environment setup.
32
     *
33
     * @param Illuminate\Foundation\Application $app
0 ignored issues
show
Bug introduced by
The type Orchestra\Testbench\Brow...\Foundation\Application was not found. Did you mean Illuminate\Foundation\Application? If so, make sure to prefix the type with \.
Loading history...
34
     *
35
     * @return void
36
     */
37
    protected function getEnvironmentSetUp($app)
38
    {
39
        $app['config']->set('conditional-debugbar.debugbar-boot-validator', TestingDebugBarBootValidator::class);
40
        $app['router']->get('page-with-middleware', ['uses' => function () {
41
            throw new Exception('Test Exception');
42
            return $this->blank_page;
0 ignored issues
show
Unused Code introduced by
return $this->blank_page is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
43
        }])->middleware(OptionalDebugBar::class);
44
    }
45
}
46