1 | <?php |
||
40 | abstract class PHPUnit_Stakx_TestCase extends \PHPUnit_Framework_TestCase |
||
|
|||
41 | { |
||
42 | const FM_OBJ_TEMPLATE = "---\n%s\n---\n\n%s"; |
||
43 | |||
44 | /** @var string */ |
||
45 | protected $assetFolder; |
||
46 | /** @var vfsStreamFile */ |
||
47 | protected $dummyFile; |
||
48 | /** @var vfsStreamDirectory */ |
||
49 | protected $rootDir; |
||
50 | |||
51 | public function setUp() |
||
64 | |||
65 | public function tearDown() |
||
72 | |||
73 | /// |
||
74 | // Assertion Functions |
||
75 | /// |
||
76 | |||
77 | /** |
||
78 | * @param string $needle |
||
79 | * @param string $haystack |
||
80 | * @param string $message |
||
81 | */ |
||
82 | protected function assertStringContains($needle, $haystack, $message = '') |
||
86 | |||
87 | /** |
||
88 | * @param string $fileContent |
||
89 | * @param string $filePath |
||
90 | * @param string $message |
||
91 | */ |
||
92 | protected function assertFileContains($fileContent, $filePath, $message = '') |
||
100 | |||
101 | /// |
||
102 | // Filesystem Functions |
||
103 | /// |
||
104 | |||
105 | /** |
||
106 | * Create a temporary folder where temporary file writes will be made to. |
||
107 | * |
||
108 | * @param string $folderName |
||
109 | */ |
||
110 | protected function createAssetFolder($folderName) |
||
116 | |||
117 | /** |
||
118 | * Write a file to the asset folder. |
||
119 | * |
||
120 | * This file will be written to the actual filesystem and not the virtual filesystem. This file will be deleted at |
||
121 | * each tearDown(). |
||
122 | * |
||
123 | * @param string $fileName |
||
124 | * @param string $content |
||
125 | * |
||
126 | * @return string Path to the temporary file; relative to the project's root |
||
127 | */ |
||
128 | protected function createPhysicalFile($fileName, $content) |
||
135 | |||
136 | /** |
||
137 | * Write a file to the virtual filesystem. |
||
138 | * |
||
139 | * This file will be deleted at each tearDown(). |
||
140 | * |
||
141 | * @param string $filename |
||
142 | * @param string $content |
||
143 | * |
||
144 | * @return string the URL of the file on the virtual filesystem |
||
145 | */ |
||
146 | protected function createVirtualFile($filename, $content) |
||
156 | |||
157 | /** |
||
158 | * Create an object of a given type. |
||
159 | * |
||
160 | * This will create a virtual file and then create an object of the specified type for the created file. |
||
161 | * |
||
162 | * @param string $classType |
||
163 | * @param string $filename |
||
164 | * @param string $content |
||
165 | * |
||
166 | * @return object An instance of $classType |
||
167 | */ |
||
168 | protected function createDocumentOfType($classType, $filename, $content) |
||
174 | |||
175 | /** |
||
176 | * Create an object of a given type following the Front Matter format. |
||
177 | * |
||
178 | * @param string $classType |
||
179 | * @param string $filename |
||
180 | * @param array $frontMatter |
||
181 | * @param string $content |
||
182 | * |
||
183 | * @return object An instance of $classType |
||
184 | */ |
||
185 | protected function createFrontMatterDocumentOfType($classType, $filename = null, $frontMatter = [], $content = 'Body Text') |
||
196 | |||
197 | /** |
||
198 | * Create multiple virtual files from a given array of information. |
||
199 | * |
||
200 | * ```php |
||
201 | * $elements = [ |
||
202 | * [ |
||
203 | * 'filename' => '<string>', |
||
204 | * 'frontmatter' => [], |
||
205 | * 'body' => '<string>', |
||
206 | * ], |
||
207 | * ]; |
||
208 | * ``` |
||
209 | * |
||
210 | * @param string $classType |
||
211 | * @param array $elements |
||
212 | * |
||
213 | * @return array |
||
214 | */ |
||
215 | protected function createMultipleFrontMatterDocumentsOfType($classType, $elements) |
||
234 | |||
235 | /** |
||
236 | * Create a File object from a given path. |
||
237 | * |
||
238 | * @deprecated |
||
239 | * |
||
240 | * @param string $filePath |
||
241 | * |
||
242 | * @return File |
||
243 | */ |
||
244 | protected function createFileObjectFromPath($filePath) |
||
248 | |||
249 | /// |
||
250 | // Mock Objects |
||
251 | /// |
||
252 | |||
253 | /** |
||
254 | * @return AssetEngineManager|\PHPUnit_Framework_MockObject_MockBuilder |
||
255 | */ |
||
256 | protected function getMockAssetEngineManager() |
||
260 | |||
261 | /** |
||
262 | * @return Configuration|\PHPUnit_Framework_MockObject_MockObject |
||
263 | */ |
||
264 | protected function getMockConfiguration() |
||
276 | |||
277 | /** |
||
278 | * @return PageManager|\PHPUnit_Framework_MockObject_MockObject |
||
279 | */ |
||
280 | protected function getMockPageManager() |
||
291 | |||
292 | /** |
||
293 | * @return MenuManager|\PHPUnit_Framework_MockObject_MockObject |
||
294 | */ |
||
295 | protected function getMockMenuManager() |
||
306 | |||
307 | /** |
||
308 | * @return CollectionManager|\PHPUnit_Framework_MockObject_MockObject |
||
309 | */ |
||
310 | protected function getMockCollectionManager() |
||
321 | |||
322 | /** |
||
323 | * @return DataManager|\PHPUnit_Framework_MockObject_MockObject |
||
324 | */ |
||
325 | protected function getMockDataManager() |
||
336 | |||
337 | /** |
||
338 | * @return TwigExtension |
||
339 | */ |
||
340 | protected function getMockTwigExtension() |
||
346 | |||
347 | /** |
||
348 | * @return TwigStakxBridge |
||
349 | */ |
||
350 | protected function getMockTemplateBridge() |
||
358 | |||
359 | /** |
||
360 | * @return MarkupEngineManager |
||
361 | */ |
||
362 | protected function getMockMarkupEngineManager() |
||
376 | |||
377 | /** |
||
378 | * Get a mock EventDispatcher. |
||
379 | * |
||
380 | * @return EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject |
||
381 | */ |
||
382 | protected function getMockEventDistpatcher() |
||
386 | |||
387 | /** |
||
388 | * Get a mock logger. |
||
389 | * |
||
390 | * @return LoggerInterface|\PHPUnit_Framework_MockObject_MockObject |
||
391 | */ |
||
392 | protected function getMockLogger() |
||
396 | |||
397 | /** |
||
398 | * Get a real logger instance that will save output to the console. |
||
399 | * |
||
400 | * @return Logger |
||
401 | */ |
||
402 | protected function getReadableLogger() |
||
410 | |||
411 | /// |
||
412 | // Utility Functions |
||
413 | /// |
||
414 | |||
415 | /** |
||
416 | * Get the directory of the unit tests. |
||
417 | * |
||
418 | * @return string |
||
419 | */ |
||
420 | protected static function getTestRoot() |
||
424 | |||
425 | /** |
||
426 | * Generate a FrontMatter-ready syntax to be used as a file's content. |
||
427 | * |
||
428 | * @param array $frontMatter |
||
429 | * @param string $body |
||
430 | * |
||
431 | * @return string |
||
432 | */ |
||
433 | protected function buildFrontMatterTemplate(array $frontMatter = [], $body = 'Body text') |
||
439 | |||
440 | /// |
||
441 | // Misc Functions |
||
442 | /// |
||
443 | |||
444 | protected function bookCollectionProvider($jailed = false) |
||
462 | } |
||
463 |
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
.