forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionsTest.php
More file actions
99 lines (83 loc) · 2.92 KB
/
Copy pathExceptionsTest.php
File metadata and controls
99 lines (83 loc) · 2.92 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Debug;
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\ReflectionHelper;
use Config\Exceptions as ExceptionsConfig;
use Config\Services;
use RuntimeException;
/**
* @internal
*/
final class ExceptionsTest extends CIUnitTestCase
{
use ReflectionHelper;
/**
* @var Exceptions
*/
private $exception;
protected function setUp(): void
{
$this->exception = new Exceptions(new ExceptionsConfig(), Services::request(), Services::response());
}
public function testDetermineViews(): void
{
$determineView = $this->getPrivateMethodInvoker($this->exception, 'determineView');
$this->assertSame('error_404.php', $determineView(PageNotFoundException::forControllerNotFound('Foo', 'bar'), ''));
$this->assertSame('error_exception.php', $determineView(new RuntimeException('Exception'), ''));
$this->assertSame('error_404.php', $determineView(new RuntimeException('foo', 404), 'app/Views/errors/cli'));
}
public function testCollectVars(): void
{
$vars = $this->getPrivateMethodInvoker($this->exception, 'collectVars')(new RuntimeException('This.'), 404);
$this->assertIsArray($vars);
$this->assertCount(7, $vars);
foreach (['title', 'type', 'code', 'message', 'file', 'line', 'trace'] as $key) {
$this->assertArrayHasKey($key, $vars);
}
}
public function testDetermineCodes(): void
{
$determineCodes = $this->getPrivateMethodInvoker($this->exception, 'determineCodes');
$this->assertSame([500, 9], $determineCodes(new RuntimeException('This.')));
$this->assertSame([500, 1], $determineCodes(new RuntimeException('That.', 600)));
$this->assertSame([404, 1], $determineCodes(new RuntimeException('There.', 404)));
}
/**
* @dataProvider dirtyPathsProvider
*/
public function testCleanPaths(string $file, string $expected): void
{
$this->assertSame($expected, Exceptions::cleanPath($file));
}
public function dirtyPathsProvider()
{
$ds = DIRECTORY_SEPARATOR;
yield from [
[
APPPATH . 'Config' . $ds . 'App.php',
'APPPATH' . $ds . 'Config' . $ds . 'App.php',
],
[
SYSTEMPATH . 'CodeIgniter.php',
'SYSTEMPATH' . $ds . 'CodeIgniter.php',
],
[
VENDORPATH . 'autoload.php',
'VENDORPATH' . $ds . 'autoload.php',
],
[
FCPATH . 'index.php',
'FCPATH' . $ds . 'index.php',
],
];
}
}