HandleExceptionsTest.php
2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
use Illuminate\Config\Repository as Config;
use Illuminate\Log\LogManager;
use Roots\Acorn\Application;
use Roots\Acorn\Bootstrap\HandleExceptions;
use Roots\Acorn\Tests\Test\TestCase;
use function Roots\Acorn\Tests\mock;
uses(TestCase::class);
beforeEach(function () {
$this->container = Application::setInstance(new Application());
$this->config = new Config();
$this->config->set('app.debug', true);
$this->container->singleton('config', fn () => $this->config);
$this->container->bootstrapWith([]);
$this->handleExceptions = new HandleExceptions();
with(new ReflectionClass($this->handleExceptions), function ($reflection) {
$property = tap($reflection->getProperty('app'))->setAccessible(true);
$property->setValue($this->handleExceptions, $this->container);
});
});
it('does not throw an exception for deprecation notices', function () {
$logger = mock(LogManager::class);
$this->container->instance(LogManager::class, $logger);
$logger->shouldReceive('channel')->with('deprecations')->andReturnSelf();
$logger->shouldReceive('warning')->with(sprintf('%s in %s on line %s',
'kjo(): Passing null to parameter #2 ($kjo) of type Kjo is deprecated',
'/acorn/path/to/file.php',
17
));
$this->handleExceptions->handleError(
E_USER_DEPRECATED,
'kjo(): Passing null to parameter #2 ($kjo) of type Kjo is deprecated',
'/acorn/path/to/file.php',
17
);
});
it('handles a warning', function () {
$logger = mock(LogManager::class);
$logger->shouldReceive();
$this->container->instance(LogManager::class, $logger);
$this->handleExceptions->handleError(
E_USER_WARNING,
'warning message',
'/acorn/path/to/file.php',
5
);
})->throws(ErrorException::class);
it('escapes an error exception for non-deprecation error', function () {
$logger = mock(LogManager::class);
$logger->shouldReceive();
$this->container->instance(LogManager::class, $logger);
add_filter('acorn/throw_error_exception', '__return_false');
$this->handleExceptions->handleError(
E_USER_WARNING,
'warning message',
'/acorn/path/to/file.php',
5
);
$this->expectNotToPerformAssertions();
});