1
|
|
|
<?php |
2
|
|
|
namespace Mezon\Service\Tests; |
3
|
|
|
|
4
|
|
|
use Mezon\Service\ServiceConsoleTransport\ServiceConsoleTransport; |
5
|
|
|
use Mezon\Security\MockProvider; |
6
|
|
|
|
7
|
|
|
class ServiceConsoleTransportUnitTest extends \PHPUnit\Framework\TestCase |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Getting mock object. |
12
|
|
|
* |
13
|
|
|
* @return object ServiceConsoleTransport mocked object. |
14
|
|
|
*/ |
15
|
|
|
protected function getTransportMock(): object |
16
|
|
|
{ |
17
|
|
|
return $this->getMockBuilder(ServiceConsoleTransport::class) |
|
|
|
|
18
|
|
|
->setMethods([ |
19
|
|
|
'createSession' |
20
|
|
|
]) |
21
|
|
|
->getMock(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Getting mock object. |
26
|
|
|
* |
27
|
|
|
* @return object ServiceLogic mocked object. |
28
|
|
|
*/ |
29
|
|
|
protected function getServiceLogicMock(): object |
30
|
|
|
{ |
31
|
|
|
return $this->getMockBuilder(TestingServiceLogicForConsoleTransport::class) |
|
|
|
|
32
|
|
|
->disableOriginalConstructor() |
33
|
|
|
->setMethods([ |
34
|
|
|
'connect' |
35
|
|
|
]) |
36
|
|
|
->getMock(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Testing connect method. |
41
|
|
|
*/ |
42
|
|
|
public function testConstructor(): void |
43
|
|
|
{ |
44
|
|
|
$transport = new ServiceConsoleTransport(); |
45
|
|
|
|
46
|
|
|
$this->assertNotEquals(null, $transport->getSecurityProvider()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Testing that security provider was set. |
51
|
|
|
*/ |
52
|
|
|
public function testSecurityProviderInitDefault(): void |
53
|
|
|
{ |
54
|
|
|
$transport = new ServiceConsoleTransport(); |
55
|
|
|
$this->assertInstanceOf(MockProvider::class, $transport->getSecurityProvider()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Testing that security provider was set. |
60
|
|
|
*/ |
61
|
|
|
public function testSecurityProviderInitString(): void |
62
|
|
|
{ |
63
|
|
|
$transport = new ServiceConsoleTransport(MockProvider::class); |
64
|
|
|
$this->assertInstanceOf(MockProvider::class, $transport->getSecurityProvider()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Testing that security provider was set. |
69
|
|
|
*/ |
70
|
|
|
public function testSecurityProviderInitObject(): void |
71
|
|
|
{ |
72
|
|
|
$transport = new ServiceConsoleTransport(new MockProvider()); |
73
|
|
|
$this->assertInstanceOf(MockProvider::class, $transport->getSecurityProvider()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Testing that header function is called once for each header. |
78
|
|
|
*/ |
79
|
|
|
public function testSingleHeaderCall(): void |
80
|
|
|
{ |
81
|
|
|
$mock = $this->getTransportMock(); |
82
|
|
|
|
83
|
|
|
$serviceLogic = $this->getServiceLogicMock(); |
84
|
|
|
|
85
|
|
|
$serviceLogic->expects($this->once()) |
86
|
|
|
->method('connect'); |
87
|
|
|
|
88
|
|
|
$mock->callLogic($serviceLogic, 'connect'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Testing that header function is called once for each header. |
93
|
|
|
*/ |
94
|
|
|
public function testSingleHeaderCallPublic(): void |
95
|
|
|
{ |
96
|
|
|
$mock = $this->getTransportMock(); |
97
|
|
|
|
98
|
|
|
$serviceLogic = $this->getServiceLogicMock(); |
99
|
|
|
|
100
|
|
|
$serviceLogic->expects($this->once()) |
101
|
|
|
->method('connect'); |
102
|
|
|
|
103
|
|
|
$mock->callPublicLogic($serviceLogic, 'connect'); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Testing public call without createSession method. |
108
|
|
|
*/ |
109
|
|
|
public function testPublicCall(): void |
110
|
|
|
{ |
111
|
|
|
// setup |
112
|
|
|
$_GET['r'] = '/public-method/'; |
113
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET'; |
114
|
|
|
$mock = $this->getTransportMock(); |
115
|
|
|
|
116
|
|
|
$mock->setServiceLogic($this->getServiceLogicMock()); |
117
|
|
|
|
118
|
|
|
$mock->expects($this->never()) |
119
|
|
|
->method('createSession'); |
120
|
|
|
|
121
|
|
|
$mock->addRoute('public-method', 'publicMethod', 'GET', 'public_call'); |
122
|
|
|
|
123
|
|
|
// test body and assertions |
124
|
|
|
$mock->run(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Testing private call with createSession method. |
129
|
|
|
*/ |
130
|
|
|
public function testPrivateCall(): void |
131
|
|
|
{ |
132
|
|
|
// setup |
133
|
|
|
$_GET['r'] = '/private-method/'; |
134
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET'; |
135
|
|
|
$mock = $this->getTransportMock(); |
136
|
|
|
|
137
|
|
|
$mock->setServiceLogic($this->getServiceLogicMock()); |
138
|
|
|
|
139
|
|
|
$mock->expects($this->once()) |
140
|
|
|
->method('createSession'); |
141
|
|
|
|
142
|
|
|
$mock->addRoute('private-method', 'privateMethod', 'GET', 'private_call'); |
143
|
|
|
|
144
|
|
|
// test body and assertions |
145
|
|
|
$mock->run(); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Testing 'run' method |
150
|
|
|
*/ |
151
|
|
|
public function testRun(): void |
152
|
|
|
{ |
153
|
|
|
// setup |
154
|
|
|
$_GET['r'] = 'public-method'; |
155
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET'; |
156
|
|
|
$mock = $this->getTransportMock(); |
157
|
|
|
|
158
|
|
|
$mock->setServiceLogic($this->getServiceLogicMock()); |
159
|
|
|
|
160
|
|
|
$mock->expects($this->never()) |
161
|
|
|
->method('createSession'); |
162
|
|
|
|
163
|
|
|
$mock->addRoute('public-method', 'publicMethod', 'GET', 'public_call'); |
164
|
|
|
|
165
|
|
|
// test body |
166
|
|
|
$mock->run(); |
167
|
|
|
|
168
|
|
|
// assertions |
169
|
|
|
$this->assertEquals('public', $mock->result); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.