forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSupportReflectorTest.php
More file actions
112 lines (91 loc) · 2.97 KB
/
Copy pathSupportReflectorTest.php
File metadata and controls
112 lines (91 loc) · 2.97 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
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
namespace Illuminate\Tests\Support;
use Illuminate\Contracts\Mail\Mailable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Reflector;
use Illuminate\Support\Testing\Fakes\BusFake;
use Illuminate\Support\Testing\Fakes\MailFake;
use Illuminate\Support\Testing\Fakes\PendingMailFake;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
class SupportReflectorTest extends TestCase
{
public function testGetClassName()
{
$method = (new ReflectionClass(PendingMailFake::class))->getMethod('send');
$this->assertSame(Mailable::class, Reflector::getParameterClassName($method->getParameters()[0]));
}
public function testEmptyClassName()
{
$method = (new ReflectionClass(MailFake::class))->getMethod('assertSent');
$this->assertNull(Reflector::getParameterClassName($method->getParameters()[0]));
}
public function testStringTypeName()
{
$method = (new ReflectionClass(BusFake::class))->getMethod('dispatchedAfterResponse');
$this->assertNull(Reflector::getParameterClassName($method->getParameters()[0]));
}
public function testSelfClassName()
{
$method = (new ReflectionClass(Model::class))->getMethod('newPivot');
$this->assertSame(Model::class, Reflector::getParameterClassName($method->getParameters()[0]));
}
public function testParentClassName()
{
$method = (new ReflectionClass(B::class))->getMethod('f');
$this->assertSame(A::class, Reflector::getParameterClassName($method->getParameters()[0]));
}
/**
* @requires PHP 8
*/
public function testUnionTypeName()
{
$method = (new ReflectionClass(C::class))->getMethod('f');
$this->assertNull(Reflector::getParameterClassName($method->getParameters()[0]));
}
public function testIsCallable()
{
$this->assertTrue(Reflector::isCallable(function () {
}));
$this->assertTrue(Reflector::isCallable([B::class, 'f']));
$this->assertFalse(Reflector::isCallable([TestClassWithCall::class, 'f']));
$this->assertTrue(Reflector::isCallable([new TestClassWithCall, 'f']));
$this->assertTrue(Reflector::isCallable([TestClassWithCallStatic::class, 'f']));
$this->assertFalse(Reflector::isCallable([new TestClassWithCallStatic, 'f']));
$this->assertFalse(Reflector::isCallable([new TestClassWithCallStatic]));
$this->assertFalse(Reflector::isCallable(['TotallyMissingClass', 'foo']));
$this->assertTrue(Reflector::isCallable(['TotallyMissingClass', 'foo'], true));
}
}
class A
{
}
class B extends A
{
public function f(parent $x)
{
}
}
if (PHP_MAJOR_VERSION >= 8) {
eval('
namespace Illuminate\Tests\Support;
class C
{
public function f(A|Model $x)
{
}
}'
);
}
class TestClassWithCall
{
public function __call($method, $parameters)
{
}
}
class TestClassWithCallStatic
{
public static function __callStatic($method, $parameters)
{
}
}