-
Notifications
You must be signed in to change notification settings - Fork 0
/
DetectCallerTest.php
59 lines (53 loc) · 1.64 KB
/
DetectCallerTest.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
<?php declare(strict_types=1);
namespace Horat1us\Tests;
use Horat1us\DetectCaller;
use PHPUnit\Framework\TestCase;
class DetectCallerTest extends TestCase
{
/**
* @covers \Horat1us\DetectCaller::backtrace
*/
public function testBacktrace(): void
{
$line = __LINE__ + 1;
$backtrace = (fn() => DetectCaller::backtrace(0))();
$expected = [
'file' => __FILE__,
'line' => $line,
'function' => 'Horat1us\Tests\{closure}',
'class' => __CLASS__,
'type' => '->',
];
$this->assertEquals($expected, $backtrace);
}
public function callStaticDataProvider(): array
{
return [
[__FUNCTION__, DetectCaller::function(),],
[__CLASS__, DetectCaller::class(),],
[DetectCaller::class(), (fn() => DetectCaller::class(1))(),],
[(string)__LINE__, (fn() => DetectCaller::line())(),],
['->', DetectCaller::type(),],
];
}
/**
* @dataProvider callStaticDataProvider
* @covers \Horat1us\DetectCaller::__callStatic
* @param int|string $expected
* @param int|string $actual
*/
public function testCallStatic($expected, $actual): void
{
$this->assertEquals($expected, $actual);
}
/**
* @covers \Horat1us\DetectCaller::__callStatic
*/
public function testInvalidCallStatic(): void
{
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Method caesar not exists!');
/** @noinspection PhpUndefinedMethodInspection */
DetectCaller::caesar(2);
}
}