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\Validator; |
10
|
|
|
|
11
|
|
|
use Symfony\Component\Config\FileLocator; |
12
|
|
|
use JonnyW\PhantomJs\Validator\Esprima; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* PHP PhantomJs |
16
|
|
|
* |
17
|
|
|
* @author Jon Wenmoth <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class EsprimaTest extends \PHPUnit_Framework_TestCase |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/ |
23
|
|
|
/** ++++++++++++++ TESTS ++++++++++++++ **/ |
24
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Test invalid argument exception is thrown |
28
|
|
|
* if file path is not local file. |
29
|
|
|
* |
30
|
|
|
* @access public |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
|
|
public function testInvalidArgumentExceptionIsThrownIfFilePathIsNotLocalFile() |
34
|
|
|
{ |
35
|
|
|
$this->setExpectedException('\InvalidArgumentException'); |
36
|
|
|
|
37
|
|
|
$fileLocator = $this->getFileLocator(); |
38
|
|
|
$esprima = $this->getEsprima($fileLocator, 'http://example.com'); |
39
|
|
|
|
40
|
|
|
$esprima->load(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Test invalid argument exception is thrown if |
45
|
|
|
* file does not exist. |
46
|
|
|
* |
47
|
|
|
* @access public |
48
|
|
|
* @return void |
49
|
|
|
*/ |
50
|
|
|
public function testInvalidArgumentIsThrownIfFileDoesNotExist() |
51
|
|
|
{ |
52
|
|
|
$this->setExpectedException('\InvalidArgumentException'); |
53
|
|
|
|
54
|
|
|
$fileLocator = $this->getFileLocator(); |
55
|
|
|
$esprima = $this->getEsprima($fileLocator, 'invalidFile.js'); |
56
|
|
|
|
57
|
|
|
$esprima->load(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Test engine can be loaded. |
62
|
|
|
* |
63
|
|
|
* @access public |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
|
|
public function testEngineCanBeLoaded() |
67
|
|
|
{ |
68
|
|
|
$fileLocator = $this->getFileLocator(); |
69
|
|
|
$esprima = $this->getEsprima($fileLocator, 'esprima-2.0.0.js'); |
70
|
|
|
|
71
|
|
|
$this->assertContains('esprima', $esprima->load()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Test engine can be converted to string. |
76
|
|
|
* |
77
|
|
|
* @access public |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
|
|
public function testEngineCanBeCovertedToString() |
81
|
|
|
{ |
82
|
|
|
$fileLocator = $this->getFileLocator(); |
83
|
|
|
$esprima = $this->getEsprima($fileLocator, 'esprima-2.0.0.js'); |
84
|
|
|
|
85
|
|
|
$this->assertContains('esprima', (string) $esprima); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/ |
89
|
|
|
/** ++++++++++ TEST ENTITIES ++++++++++ **/ |
90
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/ |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Get esprima. |
94
|
|
|
* |
95
|
|
|
* @access protected |
96
|
|
|
* @return \JonnyW\PhantomJs\Validator\Esprima |
97
|
|
|
*/ |
98
|
|
|
protected function getEsprima(FileLocator $fileLocator, $file) |
99
|
|
|
{ |
100
|
|
|
$esprima = new Esprima($fileLocator, $file); |
101
|
|
|
|
102
|
|
|
return $esprima; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get file locator. |
107
|
|
|
* |
108
|
|
|
* @access protected |
109
|
|
|
* @return \Symfony\Component\Config\FileLocator |
110
|
|
|
*/ |
111
|
|
|
protected function getFileLocator() |
112
|
|
|
{ |
113
|
|
|
$fileLocator = new FileLocator( |
114
|
|
|
sprintf('%s/../../../Resources/validators/', __DIR__) |
115
|
|
|
); |
116
|
|
|
|
117
|
|
|
return $fileLocator; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|