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\Procedure; |
10
|
|
|
|
11
|
|
|
use Twig_Environment; |
12
|
|
|
use Twig_Loader_String; |
13
|
|
|
use JonnyW\PhantomJs\Engine; |
14
|
|
|
use JonnyW\PhantomJs\Cache\FileCache; |
15
|
|
|
use JonnyW\PhantomJs\Cache\CacheInterface; |
16
|
|
|
use JonnyW\PhantomJs\Parser\JsonParser; |
17
|
|
|
use JonnyW\PhantomJs\Parser\ParserInterface; |
18
|
|
|
use JonnyW\PhantomJs\Template\TemplateRenderer; |
19
|
|
|
use JonnyW\PhantomJs\Template\TemplateRendererInterface; |
20
|
|
|
use JonnyW\PhantomJs\Procedure\ProcedureFactory; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* PHP PhantomJs |
24
|
|
|
* |
25
|
|
|
* @author Jon Wenmoth <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class ProcedureFactoryTest extends \PHPUnit_Framework_TestCase |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/ |
31
|
|
|
/** ++++++++++++++ TESTS ++++++++++++++ **/ |
32
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/ |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Test factory can create instance of |
36
|
|
|
* procedure. |
37
|
|
|
* |
38
|
|
|
* @access public |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
public function testFactoryCanCreateInstanceOfProcedure() |
42
|
|
|
{ |
43
|
|
|
$engine = $this->getEngine(); |
44
|
|
|
$parser = $this->getParser(); |
45
|
|
|
$cache = $this->getCache(); |
46
|
|
|
$renderer = $this->getRenderer(); |
47
|
|
|
|
48
|
|
|
$procedureFactory = $this->getProcedureFactory($engine, $parser, $cache, $renderer); |
49
|
|
|
|
50
|
|
|
$this->assertInstanceOf('\JonnyW\PhantomJs\Procedure\Procedure', $procedureFactory->createProcedure()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/ |
54
|
|
|
/** ++++++++++ TEST ENTITIES ++++++++++ **/ |
55
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/ |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get procedure factory instance. |
59
|
|
|
* |
60
|
|
|
* @access protected |
61
|
|
|
* @param \JonnyW\PhantomJs\Engine $engine |
62
|
|
|
* @param \JonnyW\PhantomJs\Parser\ParserInterface $parser |
63
|
|
|
* @param \JonnyW\PhantomJs\Cache\CacheInterface $cacheHandler |
64
|
|
|
* @param \JonnyW\PhantomJs\Template\TemplateRendererInterface $renderer |
65
|
|
|
* @return \JonnyW\PhantomJs\Procedure\ProcedureFactory |
66
|
|
|
*/ |
67
|
|
|
protected function getProcedureFactory(Engine $engine, ParserInterface $parser, CacheInterface $cacheHandler, TemplateRendererInterface $renderer) |
68
|
|
|
{ |
69
|
|
|
$procedureFactory = new ProcedureFactory($engine, $parser, $cacheHandler, $renderer); |
70
|
|
|
|
71
|
|
|
return $procedureFactory; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get engine. |
76
|
|
|
* |
77
|
|
|
* @access protected |
78
|
|
|
* @return \JonnyW\PhantomJs\Engine |
79
|
|
|
*/ |
80
|
|
|
protected function getEngine() |
81
|
|
|
{ |
82
|
|
|
$engine = new Engine(); |
83
|
|
|
|
84
|
|
|
return $engine; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Get parser. |
89
|
|
|
* |
90
|
|
|
* @access protected |
91
|
|
|
* @return \JonnyW\PhantomJs\Parser\JsonParser |
92
|
|
|
*/ |
93
|
|
|
protected function getParser() |
94
|
|
|
{ |
95
|
|
|
$parser = new JsonParser(); |
96
|
|
|
|
97
|
|
|
return $parser; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get cache. |
102
|
|
|
* |
103
|
|
|
* @access protected |
104
|
|
|
* @param string $cacheDir (default: '') |
105
|
|
|
* @param string $extension (default: 'proc') |
106
|
|
|
* @return \JonnyW\PhantomJs\Cache\FileCache |
107
|
|
|
*/ |
108
|
|
|
protected function getCache($cacheDir = '', $extension = 'proc') |
|
|
|
|
109
|
|
|
{ |
110
|
|
|
$cache = new FileCache(($cacheDir ? $cacheDir : sys_get_temp_dir()), 'proc'); |
111
|
|
|
|
112
|
|
|
return $cache; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Get template renderer. |
117
|
|
|
* |
118
|
|
|
* @access protected |
119
|
|
|
* @return \JonnyW\PhantomJs\Template\TemplateRenderer |
120
|
|
|
*/ |
121
|
|
|
protected function getRenderer() |
122
|
|
|
{ |
123
|
|
|
$twig = new Twig_Environment( |
124
|
|
|
new Twig_Loader_String() |
|
|
|
|
125
|
|
|
); |
126
|
|
|
|
127
|
|
|
$renderer = new TemplateRenderer($twig); |
128
|
|
|
|
129
|
|
|
return $renderer; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.