-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFormatFunctionTest.php
More file actions
executable file
·69 lines (62 loc) · 1.92 KB
/
FormatFunctionTest.php
File metadata and controls
executable file
·69 lines (62 loc) · 1.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
<?php
declare(strict_types=1);
namespace Typhoon\Formatter;
use PHPUnit\Framework\Attributes\CoversFunction;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
#[CoversFunction('Typhoon\Formatter\formatFunction')]
final class FormatFunctionTest extends TestCase
{
/**
* @return \Generator<string, array{callable, non-empty-string}>
*/
public static function cases(): \Generator
{
yield 'brackets to string with ::' => [
\sprintf('%s::cases', self::class),
\sprintf('%s::cases()', self::class),
];
yield 'brackets to string' => [
'strlen',
'strlen()',
];
yield 'from array' => [
[
new class {
public function foo(): void {}
},
'foo',
],
\sprintf('class@%s:%d::foo()', __FILE__, __LINE__ - 5),
];
yield 'from closure' => [
static function (): void {},
\sprintf('function@%s:%d()', __FILE__, __LINE__ - 1),
];
yield 'from invokable object' => [
new class {
public function __invoke(): void {}
},
\sprintf('class@%s:%d()', __FILE__, __LINE__ - 3),
];
yield 'from eval closure' => [
(static function (): callable {
/**
* @var callable $closure
*/
$closure = eval('return function() {};');
return $closure;
})(),
\sprintf('function@%s:%d()', __FILE__, __LINE__ - 4),
];
}
/**
* @param callable $closure
*/
#[DataProvider('cases')]
public function testFormatFunction(mixed $closure, string $expectedFormattedFunction): void
{
$formatted = formatFunction($closure);
self::assertSame($expectedFormattedFunction, $formatted);
}
}