Completed
Push — master ( 748c89...d24f56 )
by Schlaefer
06:53 queued 03:34
created

PluginTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 43
c 0
b 0
f 0
ccs 24
cts 24
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B testWhoops() 0 35 2
1
<?php
2
/**
3
 * @link http://philecms.github.io/
4
 * @license http://opensource.org/licenses/MIT
5
 * @package Phile\Plugin\Phile\ErrorHandler\Test
6
 */
7
8
namespace Phile\Plugin\Phile\ErrorHandler\Tests;
9
10
use Phile\Core\Bootstrap;
11
use Phile\Core\Config;
12
use Phile\Test\TestCase;
13
14
class PluginTest extends TestCase
15
{
16
    /**
17
     * Basic test that whoops plugin is running.
18
     *
19
     * The exception is not thrown but caught by Whoops and rendered plaintext
20
     * CLI response.
21
     */
22 1
    public function testWhoops()
23
    {
24 1
        $config = new Config([
25 1
            'plugins' => [
26
                'phile\\errorHandler' => ['active' => true, 'handler' => 'development']
27
            ]
28
        ]);
29 1
        $eventBus = new \Phile\Core\Event;
30 1
        $eventBus->register('after_init_core', function () {
31 1
            throw new \Exception('1845F098-9035-4D8E-9E31');
32 1
        });
33
34 1
        $request = $this->createServerRequestFromArray();
35
36 1
        $body = null;
37
        try {
38 1
            $core = $this->createPhileCore($eventBus, $config);
39 1
            $core->addBootstrap(function ($eventBus, $config) {
40 1
                $config->set('phile_cli_mode', false);
41 1
                Bootstrap::setupErrorHandler($config);
42 1
            });
43 1
            $response = $this->createPhileResponse($core, $request);
0 ignored issues
show
Unused Code introduced by
The assignment to $response is dead and can be removed.
Loading history...
44 1
        } catch (\Exception $e) {
45 1
            ob_start();
46 1
            $errorHandler = \Phile\Core\ServiceLocator::getService(
47 1
                'Phile_ErrorHandler'
48
            );
49 1
            $errorHandler->handleException($e);
50 1
            $body = ob_get_clean();
51
        }
52
53 1
        $this->assertStringStartsWith('Exception: 1845F098-9035-4D8E-9E31 in file', $body);
54
55 1
        $handlers = set_exception_handler(null);
56 1
        $this->assertInstanceOf(\Phile\Plugin\Phile\ErrorHandler\Development::class, $handlers[0]);
57 1
    }
58
}
59