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
|
|
|
use ReflectionFunction; |
14
|
|
|
|
15
|
|
|
class PluginTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Basic test that whoops plugin is running. |
19
|
|
|
* |
20
|
|
|
* The exception is not thrown but caught by Whoops and rendered plaintext |
21
|
|
|
* CLI response. |
22
|
|
|
*/ |
23
|
1 |
|
public function testWhoops() |
24
|
|
|
{ |
25
|
1 |
|
$config = new Config([ |
26
|
|
|
'plugins' => [ |
27
|
1 |
|
'phile\\errorHandler' => ['active' => true, 'handler' => 'development'] |
28
|
|
|
] |
29
|
|
|
]); |
30
|
1 |
|
$eventBus = new \Phile\Core\Event; |
31
|
1 |
|
$eventBus->register('after_init_core', function () { |
32
|
1 |
|
throw new \Exception('1845F098-9035-4D8E-9E31'); |
33
|
|
|
}); |
34
|
|
|
|
35
|
1 |
|
$request = $this->createServerRequestFromArray(); |
36
|
|
|
|
37
|
1 |
|
$body = null; |
38
|
|
|
try { |
39
|
1 |
|
$core = $this->createPhileCore($eventBus, $config); |
40
|
1 |
|
$core->addBootstrap(function ($eventBus, $config) { |
41
|
1 |
|
$config->set('phile_cli_mode', false); |
42
|
1 |
|
Bootstrap::setupErrorHandler($config); |
43
|
|
|
}); |
44
|
1 |
|
$core->bootstrap(); |
45
|
1 |
|
$this->createPhileResponse($core, $request); |
46
|
1 |
|
} catch (\Exception $e) { |
47
|
1 |
|
ob_start(); |
48
|
1 |
|
$errorHandler = \Phile\Core\ServiceLocator::getService( |
49
|
|
|
'Phile_ErrorHandler' |
50
|
|
|
); |
51
|
1 |
|
$errorHandler->handleException($e); |
52
|
1 |
|
$body = ob_get_clean(); |
53
|
|
|
} |
54
|
|
|
|
55
|
1 |
|
$this->assertStringStartsWith('Exception: 1845F098-9035-4D8E-9E31 in file', $body); |
|
|
|
|
56
|
|
|
|
57
|
1 |
|
$handler = new ReflectionFunction(set_exception_handler(null)); |
58
|
1 |
|
$this->assertInstanceOf( |
59
|
|
|
\Phile\Plugin\Phile\ErrorHandler\Development::class, |
60
|
1 |
|
$handler->getClosureThis() |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|