1 | <?php |
||
18 | class FileCacheTest extends \PHPUnit_Framework_TestCase |
||
19 | { |
||
20 | /** |
||
21 | * Test filename |
||
22 | * |
||
23 | * @var string |
||
24 | * @access protected |
||
25 | */ |
||
26 | protected $filename; |
||
27 | |||
28 | /** |
||
29 | * Test directory |
||
30 | * |
||
31 | * @var string |
||
32 | * @access protected |
||
33 | */ |
||
34 | protected $directory; |
||
35 | |||
36 | /** +++++++++++++++++++++++++++++++++++ **/ |
||
37 | /** ++++++++++++++ TESTS ++++++++++++++ **/ |
||
38 | /** +++++++++++++++++++++++++++++++++++ **/ |
||
39 | |||
40 | /** |
||
41 | * Test false is returned if file |
||
42 | * does not exist. |
||
43 | * |
||
44 | * @access public |
||
45 | * @return void |
||
46 | */ |
||
47 | public function testFalseIsReturnedIfFileDoesNotExist() |
||
53 | |||
54 | /** |
||
55 | * Test true is returned if file does exist. |
||
56 | * |
||
57 | * @access public |
||
58 | * @return void |
||
59 | */ |
||
60 | public function testTrueIsReturnedIfFileDoesExist() |
||
68 | |||
69 | /** |
||
70 | * Test not writable exception is thrown if file |
||
71 | * cannot be saved due to write permissions. |
||
72 | * |
||
73 | * @return void |
||
74 | */ |
||
75 | public function testNotWritableExceptionIsThrownIfFileCannotBeSavedDueToWritePermissions() |
||
82 | |||
83 | /** |
||
84 | * Test test file location is returned |
||
85 | * if file is successfully saved. |
||
86 | * |
||
87 | * @access public |
||
88 | * @return void |
||
89 | */ |
||
90 | public function testFileLocationIsReturnedIfFileIsSuccessfullySaved() |
||
91 | { |
||
92 | $fileCache = $this->getFileCache($this->directory, 'txt'); |
||
93 | $file = $fileCache->save($this->filename, 'Test'); |
||
94 | |||
95 | $this->assertInternalType('string', $file); |
||
96 | $this->assertFileExists($file); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Test file can be saved |
||
101 | * with directory path |
||
102 | * |
||
103 | * @access public |
||
104 | * @return void |
||
105 | */ |
||
106 | public function testFileCanBeSavedWithDirectoryPath() |
||
107 | { |
||
108 | $fileCache = $this->getFileCache('', 'txt'); |
||
109 | $file = $fileCache->save($this->directory, 'Test'); |
||
110 | |||
111 | $this->assertSame(dirname($file), $this->directory); |
||
112 | |||
113 | unlink($file); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Test not writable exception is thrown |
||
118 | * if directory path is not writable. |
||
119 | * |
||
120 | * @access public |
||
121 | * @return void |
||
122 | */ |
||
123 | public function testNotWritableExceptionIsThrownIfDirectoryPathIsNotWritable() |
||
130 | |||
131 | /** |
||
132 | * Test file can be saved with absolute |
||
133 | * path. |
||
134 | * |
||
135 | * @access public |
||
136 | * @return void |
||
137 | */ |
||
138 | public function testFileCanBeSavedWithAbsolutePath() |
||
139 | { |
||
140 | $test = sprintf('%1$s/%2$s', $this->directory, 'new-file.txt'); |
||
141 | |||
142 | $fileCache = $this->getFileCache('', 'txt'); |
||
143 | $file = $fileCache->save($test, 'Test'); |
||
144 | |||
145 | $this->assertSame($test, $file); |
||
146 | |||
147 | unlink($file); |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * Test not exists exception is thrown when |
||
152 | * fetching data that doesn't exsit |
||
153 | * |
||
154 | * @access public |
||
155 | * @return void |
||
156 | */ |
||
157 | public function testNotExistsExceptionIsThrownIfWhenFetchingDataThatDoesntExist() |
||
165 | |||
166 | /** |
||
167 | * Test data can be fetched from cache. |
||
168 | * |
||
169 | * @access public |
||
170 | * @return void |
||
171 | */ |
||
172 | public function testDataCanBeFetchedFromCache() |
||
173 | { |
||
174 | $test = 'Test'; |
||
175 | |||
176 | $fileCache = $this->getFileCache($this->directory, 'txt'); |
||
177 | $fileCache->save($this->filename, $test); |
||
178 | |||
179 | $content = $fileCache->fetch($this->filename); |
||
180 | |||
181 | $this->assertSame($test, $content); |
||
182 | } |
||
183 | |||
184 | /** |
||
185 | * Test data can be deleted from cache. |
||
186 | * |
||
187 | * @access public |
||
188 | * @return void |
||
189 | */ |
||
190 | public function testDataCanBeDeletedFromCache() |
||
200 | |||
201 | /** |
||
202 | * Test data can be deleted from |
||
203 | * cache using wildcard. |
||
204 | *. |
||
205 | * |
||
206 | * @access public |
||
207 | * @return void |
||
208 | */ |
||
209 | public function testDataCanBeDeletedFromCacheUsingWildcard() |
||
221 | |||
222 | /** +++++++++++++++++++++++++++++++++++ **/ |
||
223 | /** ++++++++++ TEST ENTITIES ++++++++++ **/ |
||
224 | /** +++++++++++++++++++++++++++++++++++ **/ |
||
225 | |||
226 | /** |
||
227 | * Get file write instance |
||
228 | * |
||
229 | * @param string $directory |
||
230 | * @param string $extension |
||
231 | * @return \JonnyW\PhantomJs\Cache\FileCache |
||
232 | */ |
||
233 | protected function getFileCache($directory, $extension) |
||
239 | |||
240 | /** +++++++++++++++++++++++++++++++++++ **/ |
||
241 | /** ++++++++++++ UTILITIES ++++++++++++ **/ |
||
242 | /** +++++++++++++++++++++++++++++++++++ **/ |
||
243 | |||
244 | /** |
||
245 | * Set up test environment. |
||
246 | * |
||
247 | * @access public |
||
248 | * @return void |
||
249 | */ |
||
250 | public function setUp() |
||
259 | |||
260 | /** |
||
261 | * Tear down test environment. |
||
262 | * |
||
263 | * @access public |
||
264 | * @return void |
||
265 | */ |
||
266 | public function tearDown() |
||
274 | |||
275 | /** |
||
276 | * Get test filename. |
||
277 | * |
||
278 | * @access public |
||
279 | * @return string |
||
280 | */ |
||
281 | public function getFilename() |
||
285 | } |
||
286 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.