1 | <?php |
||
36 | abstract class PHPUnit_Stakx_TestCase extends \PHPUnit_Framework_TestCase |
||
|
|||
37 | { |
||
38 | const FM_OBJ_TEMPLATE = "---\n%s\n---\n\n%s"; |
||
39 | |||
40 | /** @var string */ |
||
41 | protected $assetFolder; |
||
42 | /** @var vfsStreamFile */ |
||
43 | protected $dummyFile; |
||
44 | /** @var vfsStreamDirectory */ |
||
45 | protected $rootDir; |
||
46 | /** @var Filesystem */ |
||
47 | protected $fs; |
||
48 | |||
49 | public function setUp() |
||
66 | |||
67 | public function tearDown() |
||
74 | |||
75 | /// |
||
76 | // Assertion Functions |
||
77 | /// |
||
78 | |||
79 | /** |
||
80 | * @param string $needle |
||
81 | * @param string $haystack |
||
82 | * @param string $message |
||
83 | */ |
||
84 | protected function assertStringContains($needle, $haystack, $message = '') |
||
88 | |||
89 | /** |
||
90 | * @param string $fileContent |
||
91 | * @param string $filePath |
||
92 | * @param string $message |
||
93 | */ |
||
94 | protected function assertFileContains($fileContent, $filePath, $message = '') |
||
102 | |||
103 | /// |
||
104 | // Filesystem Functions |
||
105 | /// |
||
106 | |||
107 | /** |
||
108 | * Create a temporary folder where temporary file writes will be made to. |
||
109 | * |
||
110 | * @param string $folderName |
||
111 | */ |
||
112 | protected function createAssetFolder($folderName) |
||
118 | |||
119 | /** |
||
120 | * Write a file to the asset folder. |
||
121 | * |
||
122 | * This file will be written to the actual filesystem and not the virtual filesystem. This file will be deleted at |
||
123 | * each tearDown(). |
||
124 | * |
||
125 | * @param string $fileName |
||
126 | * @param string $content |
||
127 | * |
||
128 | * @return string Path to the temporary file; relative to the project's root |
||
129 | */ |
||
130 | protected function createPhysicalFile($fileName, $content) |
||
137 | |||
138 | /** |
||
139 | * Write a file to the virtual filesystem. |
||
140 | * |
||
141 | * This file will be deleted at each tearDown(). |
||
142 | * |
||
143 | * @param string $filename |
||
144 | * @param string $content |
||
145 | * |
||
146 | * @return string The URL of the file on the virtual filesystem. |
||
147 | */ |
||
148 | protected function createVirtualFile($filename, $content) |
||
158 | |||
159 | /** |
||
160 | * Create an object of a given type. |
||
161 | * |
||
162 | * This will create a virtual file and then create an object of the specified type for the created file. |
||
163 | * |
||
164 | * @param string $classType |
||
165 | * @param string $filename |
||
166 | * @param string $content |
||
167 | * |
||
168 | * @return object An instance of $classType |
||
169 | */ |
||
170 | protected function createDocumentOfType($classType, $filename, $content) |
||
176 | |||
177 | /** |
||
178 | * Create an object of a given type following the Front Matter format. |
||
179 | * |
||
180 | * @param string $classType |
||
181 | * @param string $filename |
||
182 | * @param array $frontMatter |
||
183 | * @param string $content |
||
184 | * |
||
185 | * @return object An instance of $classType |
||
186 | */ |
||
187 | protected function createFrontMatterDocumentOfType($classType, $filename = null, $frontMatter = [], $content = 'Body Text') |
||
198 | |||
199 | /** |
||
200 | * Create multiple virtual files from a given array of information. |
||
201 | * |
||
202 | * ```php |
||
203 | * $elements = [ |
||
204 | * [ |
||
205 | * 'filename' => '<string>', |
||
206 | * 'frontmatter' => [], |
||
207 | * 'body' => '<string>', |
||
208 | * ], |
||
209 | * ]; |
||
210 | * ``` |
||
211 | * |
||
212 | * @param string $classType |
||
213 | * @param array $elements |
||
214 | * |
||
215 | * @return array |
||
216 | */ |
||
217 | protected function createMultipleFrontMatterDocumentsOfType($classType, $elements) |
||
236 | |||
237 | /** |
||
238 | * Create a File object from a given path. |
||
239 | * |
||
240 | * @deprecated |
||
241 | * |
||
242 | * @param string $filePath |
||
243 | * |
||
244 | * @return File |
||
245 | */ |
||
246 | protected function createFileObjectFromPath($filePath) |
||
250 | |||
251 | /// |
||
252 | // Mock Objects |
||
253 | /// |
||
254 | |||
255 | /** |
||
256 | * @return Configuration|\PHPUnit_Framework_MockObject_MockObject |
||
257 | */ |
||
258 | protected function getMockConfiguration() |
||
270 | |||
271 | /** |
||
272 | * @return PageManager|\PHPUnit_Framework_MockObject_MockObject |
||
273 | */ |
||
274 | protected function getMockPageManager() |
||
285 | |||
286 | /** |
||
287 | * @return MenuManager|\PHPUnit_Framework_MockObject_MockObject |
||
288 | */ |
||
289 | protected function getMockMenuManager() |
||
300 | |||
301 | /** |
||
302 | * @return CollectionManager|\PHPUnit_Framework_MockObject_MockObject |
||
303 | */ |
||
304 | protected function getMockCollectionManager() |
||
315 | |||
316 | /** |
||
317 | * @return DataManager|\PHPUnit_Framework_MockObject_MockObject |
||
318 | */ |
||
319 | protected function getMockDataManager() |
||
330 | |||
331 | /** |
||
332 | * @return TwigExtension |
||
333 | */ |
||
334 | protected function getMockTwigExtension() |
||
340 | |||
341 | /** |
||
342 | * @return MarkupEngineManager |
||
343 | */ |
||
344 | protected function getMockMarkupEngineManager() |
||
358 | |||
359 | /** |
||
360 | * Get a mock EventDispatcher. |
||
361 | * |
||
362 | * @return EventDispatcherInterface |
||
363 | */ |
||
364 | protected function getMockEventDistpatcher() |
||
368 | |||
369 | /** |
||
370 | * Get a mock logger. |
||
371 | * |
||
372 | * @return LoggerInterface |
||
373 | */ |
||
374 | protected function getMockLogger() |
||
378 | |||
379 | /** |
||
380 | * Get a real logger instance that will save output to the console. |
||
381 | * |
||
382 | * @return StakxLogger |
||
383 | */ |
||
384 | protected function getReadableLogger() |
||
392 | |||
393 | /// |
||
394 | // Utility Functions |
||
395 | /// |
||
396 | |||
397 | /** |
||
398 | * Get the directory of the unit tests. |
||
399 | * |
||
400 | * @return string |
||
401 | */ |
||
402 | protected static function getTestRoot() |
||
406 | |||
407 | /** |
||
408 | * Generate a FrontMatter-ready syntax to be used as a file's content. |
||
409 | * |
||
410 | * @param array $frontMatter |
||
411 | * @param string $body |
||
412 | * |
||
413 | * @return string |
||
414 | */ |
||
415 | protected function buildFrontMatterTemplate(array $frontMatter = array(), $body = 'Body text') |
||
421 | |||
422 | /// |
||
423 | // Misc Functions |
||
424 | /// |
||
425 | |||
426 | protected function bookCollectionProvider($jailed = false) |
||
443 | } |
||
444 |
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
.