|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Stefano Torresi (http://stefanotorresi.it) |
|
4
|
|
|
* @license See the file LICENSE.txt for copying permission. |
|
5
|
|
|
* ************************************************ |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Thorr\OAuth2\Test\Server; |
|
9
|
|
|
|
|
10
|
|
|
use OAuth2\Server as OAuth2Server; |
|
11
|
|
|
use PHPUnit_Framework_TestCase as TestCase; |
|
12
|
|
|
use Thorr\OAuth2\Options\ModuleOptions; |
|
13
|
|
|
use Thorr\OAuth2\Server\ServerInitializer; |
|
14
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
15
|
|
|
|
|
16
|
|
|
class ServerInitializerTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
public function testReturnsCallableIfCallbackReturnedCallable() |
|
19
|
|
|
{ |
|
20
|
|
|
$serviceManager = $this->getMock(ServiceLocatorInterface::class); |
|
21
|
|
|
$serviceManager |
|
22
|
|
|
->expects($this->any()) |
|
23
|
|
|
->method('get') |
|
24
|
|
|
->willReturnCallback(function ($name) { |
|
25
|
|
|
switch ($name) { |
|
26
|
|
|
case ModuleOptions::class : |
|
27
|
|
|
return new ModuleOptions(); |
|
28
|
|
|
} |
|
29
|
|
|
}) |
|
30
|
|
|
; |
|
31
|
|
|
$oauth2Server = $this->getMockBuilder(OAuth2Server::class)->disableOriginalConstructor()->getMock(); |
|
32
|
|
|
$callback = function () use ($oauth2Server) { |
|
33
|
|
|
return function () use ($oauth2Server) { |
|
34
|
|
|
return $oauth2Server; |
|
35
|
|
|
}; |
|
36
|
|
|
}; |
|
37
|
|
|
$initializer = new ServerInitializer(); |
|
38
|
|
|
|
|
39
|
|
|
$result = $initializer->createDelegatorWithName($serviceManager, '', '', $callback); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertInternalType('callable', $result); |
|
42
|
|
|
$this->assertSame($result(), $oauth2Server); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testReturnsInstanceIfCallbackReturnedInstance() |
|
46
|
|
|
{ |
|
47
|
|
|
$serviceManager = $this->getMock(ServiceLocatorInterface::class); |
|
48
|
|
|
$serviceManager |
|
49
|
|
|
->expects($this->any()) |
|
50
|
|
|
->method('get') |
|
51
|
|
|
->willReturnCallback(function ($name) { |
|
52
|
|
|
switch ($name) { |
|
53
|
|
|
case ModuleOptions::class : |
|
54
|
|
|
return new ModuleOptions(); |
|
55
|
|
|
} |
|
56
|
|
|
}) |
|
57
|
|
|
; |
|
58
|
|
|
$oauth2Server = $this->getMockBuilder(OAuth2Server::class)->disableOriginalConstructor()->getMock(); |
|
59
|
|
|
$callback = function () use ($oauth2Server) { |
|
60
|
|
|
return $oauth2Server; |
|
61
|
|
|
}; |
|
62
|
|
|
$initializer = new ServerInitializer(); |
|
63
|
|
|
|
|
64
|
|
|
$result = $initializer->createDelegatorWithName($serviceManager, '', '', $callback); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertEquals($result, $oauth2Server); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|