Repository navigation
Expand file tree
/
Copy pathClassInvokerTest.php
More file actions
103 lines (85 loc) · 2.41 KB
/
Copy pathClassInvokerTest.php
File metadata and controls
103 lines (85 loc) · 2.41 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
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Support\Reflection;
use Hyperf\Support\Reflection\ClassInvoker;
use Mockery;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;
use ReflectionException;
/**
* @internal
* @coversNothing
*/
#[CoversNothing]
class ClassInvokerTest extends TestCase
{
protected function tearDown(): void
{
Mockery::close();
}
public function testClassInvokerCall()
{
$invoker = new ClassInvoker(new Caller());
$this->assertSame(1, $invoker->one());
$this->assertSame(1, $invoker->one());
$this->assertSame(123, $invoker->two(123));
$this->assertSame(3, $invoker->three(1, 2));
}
public function testClassInvokerGet()
{
$invoker = new ClassInvoker(new Caller());
$this->assertSame(null, $invoker->id);
$this->assertSame(md5(''), $invoker->md5);
$this->assertSame(sha1(''), $invoker->sha);
$invoker = new ClassInvoker(new Caller($id = uniqid()));
$this->assertSame($id, $invoker->id);
$this->assertSame(md5($id), $invoker->md5);
$this->assertSame(sha1($id), $invoker->sha);
}
public function testClassInvokerCallNotExistMethod()
{
$invoker = new ClassInvoker(new Caller());
$this->expectException(ReflectionException::class);
$this->expectExceptionMessage('Method HyperfTest\Support\Reflection\Caller::zero() does not exist');
$invoker->zero();
}
public function testClassInvokerGetNotExistProperty()
{
$invoker = new ClassInvoker(new Caller());
$this->expectException(ReflectionException::class);
$this->expectExceptionMessage('Property HyperfTest\Support\Reflection\Caller::$zero does not exist');
$invoker->zero;
}
}
class Caller
{
public $id;
protected $sha;
private $md5;
public function __construct($id = null)
{
$this->id = $id;
$this->md5 = md5($id ?? '');
$this->sha = sha1($id ?? '');
}
public function three($a, $b)
{
return $a + $b;
}
protected function two($data)
{
return $data;
}
private function one()
{
return 1;
}
}