|
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
|
|
|
try { |
|
37
|
1 |
|
$core = $this->createPhileCore($eventBus, $config); |
|
38
|
1 |
|
$core->addBootstrap(function ($eventBus, $config) { |
|
39
|
1 |
|
$config->set('phile_cli_mode', false); |
|
40
|
1 |
|
Bootstrap::setupErrorHandler($config); |
|
41
|
1 |
|
}); |
|
42
|
1 |
|
$response = $this->createPhileResponse($core, $request); |
|
|
|
|
|
|
43
|
1 |
|
} catch (\Exception $e) { |
|
44
|
1 |
|
ob_start(); |
|
45
|
1 |
|
$errorHandler = \Phile\Core\ServiceLocator::getService( |
|
46
|
1 |
|
'Phile_ErrorHandler' |
|
47
|
|
|
); |
|
48
|
1 |
|
$errorHandler->handleException($e); |
|
49
|
1 |
|
$body = ob_get_clean(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
1 |
|
$this->assertStringStartsWith('Exception: 1845F098-9035-4D8E-9E31 in file', $body); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
1 |
|
$handlers = set_exception_handler(null); |
|
55
|
1 |
|
$this->assertInstanceOf(\Phile\Plugin\Phile\ErrorHandler\Development::class, $handlers[0]); |
|
56
|
1 |
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.