Issues (120)

tests/Pest.php (2 issues)

1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of Flight Routing.
5
 *
6
 * PHP version 8.0 and above required
7
 *
8
 * @author    Divine Niiquaye Ibok <[email protected]>
9
 * @copyright 2019 Divine Niiquaye Ibok (https://divinenii.com/)
10
 * @license   https://opensource.org/licenses/BSD-3-Clause License
11
 *
12
 * For the full copyright and license information, please view the LICENSE
13
 * file that was distributed with this source code.
14
 */
15
16
use Flight\Routing\Handlers\ResourceHandler;
17
18
\spl_autoload_register(function (string $class): void {
19
    match ($class) {
20
        'Flight\Routing\Tests\Fixtures\Annotation\Route\Valid\MultipleMethodRouteController' => require __DIR__.'/Fixtures/Annotation/Route/Valid/MultipleMethodRouteController.php',
21
        'Flight\Routing\Tests\Fixtures\BlankRequestHandler' => require __DIR__.'/Fixtures/BlankRequestHandler.php',
22
        'Flight\Routing\Tests\Fixtures\BlankRestful' => require __DIR__.'/Fixtures/BlankRestful.php',
23
        'Flight\Routing\Tests\Fixtures\Annotation\Route\Invalid\PathEmpty' => require __DIR__.'/Fixtures/Annotation/Route/Invalid/PathEmpty.php',
24
        'Flight\Routing\Tests\Fixtures\Annotation\Route\Invalid\MethodWithResource' => require __DIR__.'/Fixtures/Annotation/Route/Invalid/MethodWithResource.php',
25
        'Flight\Routing\Tests\Fixtures\Annotation\Route\Invalid\ClassGroupWithResource' => require __DIR__.'/Fixtures/Annotation/Route/Invalid/ClassGroupWithResource.php',
26
        default => null,
27
    };
28
});
29
30
// uses(Tests\TestCase::class)->in('Feature');
31
32
/*
33
|--------------------------------------------------------------------------
34
| Expectations
35
|--------------------------------------------------------------------------
36
|
37
| When you're writing tests, you often need to check that values meet certain conditions. The
38
| "expect()" function gives you access to a set of "expectations" methods that you can use
39
| to assert different things. Of course, you may extend the Expectation API at any time.
40
|
41
*/
42
expect()->extend('toBeOne', fn () => $this->toBe(1));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
43
44
/*
45
|--------------------------------------------------------------------------
46
| Functions
47
|--------------------------------------------------------------------------
48
|
49
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
50
| project that you don't want to repeat in every file. Here you can also expose helpers as
51
| global functions to help you to reduce the number of lines of code in your test files.
52
|
53
*/
54
function debugFormat(mixed $value, $indent = ''): string
55
{
56
    switch (true) {
57
        case \is_int($value) || \is_float($value):
58
            return \var_export($value, true);
59
        case [] === $value:
60
            return '[]';
61
        case false === $value:
62
            return 'false';
63
        case true === $value:
64
            return 'true';
65
        case null === $value:
66
            return 'null';
67
        case '' === $value:
68
            return "''";
69
        case $value instanceof \UnitEnum:
0 ignored issues
show
The type UnitEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
70
            return \ltrim(\var_export($value, true), '\\');
71
    }
72
    $subIndent = $indent.'    ';
73
74
    if (\is_string($value)) {
75
        return \sprintf("'%s'", \addcslashes($value, "'\\"));
76
    }
77
78
    if (\is_array($value)) {
79
        $j = -1;
80
        $code = '';
81
82
        foreach ($value as $k => $v) {
83
            $code .= $subIndent;
84
85
            if (\in_array($k, ['path', 'prefix'], true) && \is_string($v)) {
86
                $v = '/'.\ltrim($v, '/');
87
            }
88
89
            if (!\is_int($k) || 1 !== $k - $j) {
90
                $code .= debugFormat($k, $subIndent).' => ';
91
            }
92
93
            if (\is_int($k) && $k > $j) {
94
                $j = $k;
95
            }
96
            $code .= debugFormat($v, $subIndent).",\n";
97
        }
98
99
        return "[\n".$code.$indent.']';
100
    }
101
102
    if (\is_object($value)) {
103
        if ($value instanceof ResourceHandler) {
104
            return 'new ResourceHandler('.debugFormat($value(''), $indent).')';
105
        }
106
107
        if ($value instanceof \stdClass) {
108
            return '(object) '.debugFormat((array) $value, $indent);
109
        }
110
111
        if (!$value instanceof \Closure) {
112
            return $value::class;
113
        }
114
        $ref = new \ReflectionFunction($value);
115
116
        if (0 === $ref->getNumberOfParameters()) {
117
            return 'fn() => '.debugFormat($ref->invoke(), $indent);
118
        }
119
    }
120
121
    throw new \UnexpectedValueException(\sprintf('Cannot format value of type "%s".', \get_debug_type($value)));
122
}
123