-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPest.php
122 lines (104 loc) · 4.35 KB
/
Pest.php
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php declare(strict_types=1);
/*
* This file is part of Flight Routing.
*
* PHP version 8.0 and above required
*
* @author Divine Niiquaye Ibok <[email protected]>
* @copyright 2019 Divine Niiquaye Ibok (https://divinenii.com/)
* @license https://opensource.org/licenses/BSD-3-Clause License
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Flight\Routing\Handlers\ResourceHandler;
\spl_autoload_register(function (string $class): void {
match ($class) {
'Flight\Routing\Tests\Fixtures\Annotation\Route\Valid\MultipleMethodRouteController' => require __DIR__.'/Fixtures/Annotation/Route/Valid/MultipleMethodRouteController.php',
'Flight\Routing\Tests\Fixtures\BlankRequestHandler' => require __DIR__.'/Fixtures/BlankRequestHandler.php',
'Flight\Routing\Tests\Fixtures\BlankRestful' => require __DIR__.'/Fixtures/BlankRestful.php',
'Flight\Routing\Tests\Fixtures\Annotation\Route\Invalid\PathEmpty' => require __DIR__.'/Fixtures/Annotation/Route/Invalid/PathEmpty.php',
'Flight\Routing\Tests\Fixtures\Annotation\Route\Invalid\MethodWithResource' => require __DIR__.'/Fixtures/Annotation/Route/Invalid/MethodWithResource.php',
'Flight\Routing\Tests\Fixtures\Annotation\Route\Invalid\ClassGroupWithResource' => require __DIR__.'/Fixtures/Annotation/Route/Invalid/ClassGroupWithResource.php',
default => null,
};
});
// uses(Tests\TestCase::class)->in('Feature');
/*
|--------------------------------------------------------------------------
| Expectations
|--------------------------------------------------------------------------
|
| When you're writing tests, you often need to check that values meet certain conditions. The
| "expect()" function gives you access to a set of "expectations" methods that you can use
| to assert different things. Of course, you may extend the Expectation API at any time.
|
*/
expect()->extend('toBeOne', fn () => $this->toBe(1));
/*
|--------------------------------------------------------------------------
| Functions
|--------------------------------------------------------------------------
|
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
| project that you don't want to repeat in every file. Here you can also expose helpers as
| global functions to help you to reduce the number of lines of code in your test files.
|
*/
function debugFormat(mixed $value, $indent = ''): string
{
switch (true) {
case \is_int($value) || \is_float($value):
return \var_export($value, true);
case [] === $value:
return '[]';
case false === $value:
return 'false';
case true === $value:
return 'true';
case null === $value:
return 'null';
case '' === $value:
return "''";
case $value instanceof \UnitEnum:
return \ltrim(\var_export($value, true), '\\');
}
$subIndent = $indent.' ';
if (\is_string($value)) {
return \sprintf("'%s'", \addcslashes($value, "'\\"));
}
if (\is_array($value)) {
$j = -1;
$code = '';
foreach ($value as $k => $v) {
$code .= $subIndent;
if (\in_array($k, ['path', 'prefix'], true) && \is_string($v)) {
$v = '/'.\ltrim($v, '/');
}
if (!\is_int($k) || 1 !== $k - $j) {
$code .= debugFormat($k, $subIndent).' => ';
}
if (\is_int($k) && $k > $j) {
$j = $k;
}
$code .= debugFormat($v, $subIndent).",\n";
}
return "[\n".$code.$indent.']';
}
if (\is_object($value)) {
if ($value instanceof ResourceHandler) {
return 'new ResourceHandler('.debugFormat($value(''), $indent).')';
}
if ($value instanceof \stdClass) {
return '(object) '.debugFormat((array) $value, $indent);
}
if (!$value instanceof \Closure) {
return $value::class;
}
$ref = new \ReflectionFunction($value);
if (0 === $ref->getNumberOfParameters()) {
return 'fn() => '.debugFormat($ref->invoke(), $indent);
}
}
throw new \UnexpectedValueException(\sprintf('Cannot format value of type "%s".', \get_debug_type($value)));
}