1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Gandung\JWT\Tests\Proxy; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Gandung\JWT\Proxy\AbstractProxy; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @author Paulus Gandung Prakosa <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
class AbstractProxyTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function testCanGetInstance() |
14
|
|
|
{ |
15
|
|
|
$mock = $this->getMockBuilder(AbstractProxy::class) |
16
|
|
|
->setConstructorArgs([new \ProxyManager\Factory\LazyLoadingValueHolderFactory]) |
17
|
|
|
->getMockForAbstractClass(); |
18
|
|
|
$this->assertInstanceOf(AbstractProxy::class, $mock); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testCanInstantiateGivenConcreteClassName() |
22
|
|
|
{ |
23
|
|
|
$mock = $this->getMockBuilder(AbstractProxy::class) |
24
|
|
|
->setConstructorArgs([new \ProxyManager\Factory\LazyLoadingValueHolderFactory]) |
25
|
|
|
->getMockForAbstractClass(); |
26
|
|
|
$this->assertInstanceOf(AbstractProxy::class, $mock); |
27
|
|
|
$caller = function () { |
28
|
|
|
return $this->instantiate( |
|
|
|
|
29
|
|
|
\Gandung\JWT\Algorithm\ECDSA\ES256::class, |
30
|
|
|
[\Gandung\JWT\Adapter\ECDSAAdapter::create()] |
31
|
|
|
); |
32
|
|
|
}; |
33
|
|
|
$inv = $caller->bindTo($mock, $mock); |
34
|
|
|
$this->assertInstanceOf(\Gandung\JWT\Algorithm\ECDSA\ES256::class, $inv()); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @expectedException \InvalidArgumentException |
39
|
|
|
*/ |
40
|
|
|
public function testCanRaiseExceptionWhileInstantiateNonexistClassName() |
41
|
|
|
{ |
42
|
|
|
$mock = $this->getMockBuilder(AbstractProxy::class) |
43
|
|
|
->setConstructorArgs([new \ProxyManager\Factory\LazyLoadingValueHolderFactory]) |
44
|
|
|
->getMockForAbstractClass(); |
45
|
|
|
$this->assertInstanceOf(AbstractProxy::class, $mock); |
46
|
|
|
$caller = function () { |
47
|
|
|
return $this->instantiate( |
|
|
|
|
48
|
|
|
'Nonexistent\Class\Name\Will\Be\Fucked\For\Good', |
49
|
|
|
[] |
50
|
|
|
); |
51
|
|
|
}; |
52
|
|
|
$inv = $caller->bindTo($mock, $mock); |
53
|
|
|
$inv(); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.