1 | <?php |
||
31 | abstract class PHPUnit_Stakx_TestCase extends \PHPUnit_Framework_TestCase |
||
|
|||
32 | { |
||
33 | const FM_OBJ_TEMPLATE = "---\n%s\n---\n\n%s"; |
||
34 | |||
35 | /** @var string */ |
||
36 | protected $assetFolder; |
||
37 | /** @var vfsStreamFile */ |
||
38 | protected $dummyFile; |
||
39 | /** @var vfsStreamDirectory */ |
||
40 | protected $rootDir; |
||
41 | /** @var Filesystem */ |
||
42 | protected $fs; |
||
43 | |||
44 | public function setUp() |
||
61 | |||
62 | public function tearDown() |
||
69 | |||
70 | /// |
||
71 | // Assertion Functions |
||
72 | /// |
||
73 | |||
74 | /** |
||
75 | * @param string $needle |
||
76 | * @param string $haystack |
||
77 | * @param string $message |
||
78 | */ |
||
79 | protected function assertStringContains($needle, $haystack, $message = '') |
||
83 | |||
84 | /** |
||
85 | * @param string $fileContent |
||
86 | * @param string $filePath |
||
87 | * @param string $message |
||
88 | */ |
||
89 | protected function assertFileContains($fileContent, $filePath, $message = '') |
||
97 | |||
98 | /// |
||
99 | // Filesystem Functions |
||
100 | /// |
||
101 | |||
102 | /** |
||
103 | * Create a temporary folder where temporary file writes will be made to. |
||
104 | * |
||
105 | * @param string $folderName |
||
106 | */ |
||
107 | protected function createAssetFolder($folderName) |
||
113 | |||
114 | /** |
||
115 | * Write a file to the asset folder. |
||
116 | * |
||
117 | * This file will be written to the actual filesystem and not the virtual filesystem. This file will be deleted at |
||
118 | * each tearDown(). |
||
119 | * |
||
120 | * @param string $fileName |
||
121 | * @param string $content |
||
122 | * |
||
123 | * @return string Path to the temporary file; relative to the project's root |
||
124 | */ |
||
125 | protected function createPhysicalFile($fileName, $content) |
||
132 | |||
133 | /** |
||
134 | * Write a file to the virtual filesystem. |
||
135 | * |
||
136 | * This file will be deleted at each tearDown(). |
||
137 | * |
||
138 | * @param string $filename |
||
139 | * @param string $content |
||
140 | * |
||
141 | * @return string The URL of the file on the virtual filesystem. |
||
142 | */ |
||
143 | protected function createVirtualFile($filename, $content) |
||
153 | |||
154 | /** |
||
155 | * Create an object of a given type. |
||
156 | * |
||
157 | * This will create a virtual file and then create an object of the specified type for the created file. |
||
158 | * |
||
159 | * @param string $classType |
||
160 | * @param string $filename |
||
161 | * @param string $content |
||
162 | * |
||
163 | * @return object An instance of $classType |
||
164 | */ |
||
165 | protected function createDocumentOfType($classType, $filename, $content) |
||
171 | |||
172 | /** |
||
173 | * Create an object of a given type following the Front Matter format. |
||
174 | * |
||
175 | * @param string $classType |
||
176 | * @param string $filename |
||
177 | * @param array $frontMatter |
||
178 | * @param string $content |
||
179 | * |
||
180 | * @return object An instance of $classType |
||
181 | */ |
||
182 | protected function createFrontMatterDocumentOfType($classType, $filename = null, $frontMatter = [], $content = 'Body Text') |
||
193 | |||
194 | /** |
||
195 | * Create multiple virtual files from a given array of information. |
||
196 | * |
||
197 | * ```php |
||
198 | * $elements = [ |
||
199 | * [ |
||
200 | * 'filename' => '<string>', |
||
201 | * 'frontmatter' => [], |
||
202 | * 'body' => '<string>', |
||
203 | * ], |
||
204 | * ]; |
||
205 | * ``` |
||
206 | * |
||
207 | * @param string $classType |
||
208 | * @param array $elements |
||
209 | * |
||
210 | * @return array |
||
211 | */ |
||
212 | protected function createMultipleFrontMatterDocumentsOfType($classType, $elements) |
||
231 | |||
232 | /** |
||
233 | * Create a File object from a given path. |
||
234 | * |
||
235 | * @deprecated |
||
236 | * |
||
237 | * @param string $filePath |
||
238 | * |
||
239 | * @return File |
||
240 | */ |
||
241 | protected function createFileObjectFromPath($filePath) |
||
245 | |||
246 | /// |
||
247 | // Mock Objects |
||
248 | /// |
||
249 | |||
250 | /** |
||
251 | * @return Configuration|\PHPUnit_Framework_MockObject_MockObject |
||
252 | */ |
||
253 | protected function getMockConfiguration() |
||
265 | |||
266 | /** |
||
267 | * @return PageManager|\PHPUnit_Framework_MockObject_MockObject |
||
268 | */ |
||
269 | protected function getMockPageManager() |
||
280 | |||
281 | /** |
||
282 | * @return MenuManager|\PHPUnit_Framework_MockObject_MockObject |
||
283 | */ |
||
284 | protected function getMockMenuManager() |
||
295 | |||
296 | /** |
||
297 | * @return CollectionManager|\PHPUnit_Framework_MockObject_MockObject |
||
298 | */ |
||
299 | protected function getMockCollectionManager() |
||
310 | |||
311 | /** |
||
312 | * @return DataManager|\PHPUnit_Framework_MockObject_MockObject |
||
313 | */ |
||
314 | protected function getMockDataManager() |
||
325 | |||
326 | /** |
||
327 | * Get a mock EventDispatcher. |
||
328 | * |
||
329 | * @return EventDispatcherInterface |
||
330 | */ |
||
331 | protected function getMockEventDistpatcher() |
||
335 | |||
336 | /** |
||
337 | * Get a mock logger. |
||
338 | * |
||
339 | * @return LoggerInterface |
||
340 | */ |
||
341 | protected function getMockLogger() |
||
345 | |||
346 | /** |
||
347 | * Get a real logger instance that will save output to the console. |
||
348 | * |
||
349 | * @return StakxLogger |
||
350 | */ |
||
351 | protected function getReadableLogger() |
||
359 | |||
360 | /// |
||
361 | // Utility Functions |
||
362 | /// |
||
363 | |||
364 | /** |
||
365 | * Get the directory of the unit tests. |
||
366 | * |
||
367 | * @return string |
||
368 | */ |
||
369 | protected function getTestRoot() |
||
373 | |||
374 | /** |
||
375 | * Generate a FrontMatter-ready syntax to be used as a file's content. |
||
376 | * |
||
377 | * @param array $frontMatter |
||
378 | * @param string $body |
||
379 | * |
||
380 | * @return string |
||
381 | */ |
||
382 | protected function buildFrontMatterTemplate(array $frontMatter = array(), $body = 'Body text') |
||
388 | |||
389 | /// |
||
390 | // Misc Functions |
||
391 | /// |
||
392 | |||
393 | protected function bookCollectionProvider($jailed = false) |
||
409 | } |
||
410 |
Classes in PHP are usually named in CamelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes
DatabaseProvider
.