1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the php-phantomjs. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace JonnyW\PhantomJs\Tests\Unit; |
10
|
|
|
|
11
|
|
|
use JonnyW\PhantomJs\Client; |
12
|
|
|
use JonnyW\PhantomJs\Engine; |
13
|
|
|
use JonnyW\PhantomJs\Http\MessageFactoryInterface; |
14
|
|
|
use JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface; |
15
|
|
|
use JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* PHP PhantomJs |
19
|
|
|
* |
20
|
|
|
* @author Jon Wenmoth <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class ClientTest extends \PHPUnit_Framework_TestCase |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/ |
26
|
|
|
/** ++++++++++++++ TESTS ++++++++++++++ **/ |
27
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Test can get client through |
31
|
|
|
* factory method. |
32
|
|
|
* |
33
|
|
|
* @access public |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
|
|
public function testCanGetClientThroughFactoryMethod() |
37
|
|
|
{ |
38
|
|
|
$this->assertInstanceOf('\JonnyW\PhantomJs\Client', Client::getInstance()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Test can get engine. |
43
|
|
|
* |
44
|
|
|
* @return void |
45
|
|
|
*/ |
46
|
|
|
public function testCanGetEngne() |
47
|
|
|
{ |
48
|
|
|
$engine = $this->getEngine(); |
49
|
|
|
$procedureLoader = $this->getProcedureLoader(); |
50
|
|
|
$procedureCompiler = $this->getProcedureCompiler(); |
51
|
|
|
$messageFactory = $this->getMessageFactory(); |
52
|
|
|
|
53
|
|
|
$client = $this->getClient($engine, $procedureLoader, $procedureCompiler, $messageFactory); |
54
|
|
|
|
55
|
|
|
$this->assertInstanceOf('\JonnyW\PhantomJs\Engine', $client->getEngine()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Test can get message factory |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
|
public function testCanGetMessageFactory() |
64
|
|
|
{ |
65
|
|
|
$engine = $this->getEngine(); |
66
|
|
|
$procedureLoader = $this->getProcedureLoader(); |
67
|
|
|
$procedureCompiler = $this->getProcedureCompiler(); |
68
|
|
|
$messageFactory = $this->getMessageFactory(); |
69
|
|
|
|
70
|
|
|
$client = $this->getClient($engine, $procedureLoader, $procedureCompiler, $messageFactory); |
71
|
|
|
|
72
|
|
|
$this->assertInstanceOf('\JonnyW\PhantomJs\Http\MessageFactoryInterface', $client->getMessageFactory()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Test can get procedure loader. |
77
|
|
|
* |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
|
|
public function testCanGetProcedureLoader() |
81
|
|
|
{ |
82
|
|
|
$engine = $this->getEngine(); |
83
|
|
|
$procedureLoader = $this->getProcedureLoader(); |
84
|
|
|
$procedureCompiler = $this->getProcedureCompiler(); |
85
|
|
|
$messageFactory = $this->getMessageFactory(); |
86
|
|
|
|
87
|
|
|
$client = $this->getClient($engine, $procedureLoader, $procedureCompiler, $messageFactory); |
88
|
|
|
|
89
|
|
|
$this->assertInstanceOf('\JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface', $client->getProcedureLoader()); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/ |
93
|
|
|
/** ++++++++++ TEST ENTITIES ++++++++++ **/ |
94
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/ |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get client instance |
98
|
|
|
* |
99
|
|
|
* @param \JonnyW\PhantomJs\Engine $engine |
100
|
|
|
* @param \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface $procedureLoader |
101
|
|
|
* @param \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface $procedureCompiler |
102
|
|
|
* @param \JonnyW\PhantomJs\Http\MessageFactoryInterface $messageFactory |
103
|
|
|
* @return \JonnyW\PhantomJs\Client |
104
|
|
|
*/ |
105
|
|
|
protected function getClient(Engine $engine, ProcedureLoaderInterface $procedureLoader, ProcedureCompilerInterface $procedureCompiler, MessageFactoryInterface $messageFactory) |
106
|
|
|
{ |
107
|
|
|
$client = new Client($engine, $procedureLoader, $procedureCompiler, $messageFactory); |
108
|
|
|
|
109
|
|
|
return $client; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/ |
113
|
|
|
/** ++++++++++ MOCKS / STUBS ++++++++++ **/ |
114
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/ |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Get engine |
118
|
|
|
* |
119
|
|
|
* @access protected |
120
|
|
|
* @return \JonnyW\PhantomJs\Engine |
121
|
|
|
*/ |
122
|
|
|
protected function getEngine() |
123
|
|
|
{ |
124
|
|
|
$engine = $this->getMock('\JonnyW\PhantomJs\Engine'); |
125
|
|
|
|
126
|
|
|
return $engine; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Get message factory |
131
|
|
|
* |
132
|
|
|
* @access protected |
133
|
|
|
* @return \JonnyW\PhantomJs\Http\MessageFactoryInterface |
134
|
|
|
*/ |
135
|
|
|
protected function getMessageFactory() |
136
|
|
|
{ |
137
|
|
|
$messageFactory = $this->getMock('\JonnyW\PhantomJs\Http\MessageFactoryInterface'); |
138
|
|
|
|
139
|
|
|
return $messageFactory; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Get procedure loader. |
144
|
|
|
* |
145
|
|
|
* @access protected |
146
|
|
|
* @return \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface |
147
|
|
|
*/ |
148
|
|
|
protected function getProcedureLoader() |
149
|
|
|
{ |
150
|
|
|
$procedureLoader = $this->getMock('\JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface'); |
151
|
|
|
|
152
|
|
|
return $procedureLoader; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Get procedure validator. |
157
|
|
|
* |
158
|
|
|
* @access protected |
159
|
|
|
* @return \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface |
160
|
|
|
*/ |
161
|
|
|
protected function getProcedureCompiler() |
162
|
|
|
{ |
163
|
|
|
$procedureCompiler = $this->getMock('\JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface'); |
164
|
|
|
|
165
|
|
|
return $procedureCompiler; |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|