1 | <?php |
||
29 | abstract class PHPUnit_Stakx_TestCase extends \PHPUnit_Framework_TestCase |
||
|
|||
30 | { |
||
31 | const FM_OBJ_TEMPLATE = "---\n%s\n---\n\n%s"; |
||
32 | |||
33 | /** @var string */ |
||
34 | protected $assetFolder; |
||
35 | /** @var vfsStreamFile */ |
||
36 | protected $dummyFile; |
||
37 | /** @var vfsStreamDirectory */ |
||
38 | protected $rootDir; |
||
39 | /** @var Filesystem */ |
||
40 | protected $fs; |
||
41 | |||
42 | public function setUp() |
||
58 | |||
59 | public function tearDown() |
||
66 | |||
67 | /// |
||
68 | // Assertion Functions |
||
69 | /// |
||
70 | |||
71 | /** |
||
72 | * @param string $needle |
||
73 | * @param string $haystack |
||
74 | * @param string $message |
||
75 | */ |
||
76 | protected function assertStringContains($needle, $haystack, $message = '') |
||
80 | |||
81 | /** |
||
82 | * @param string $fileContent |
||
83 | * @param string $filePath |
||
84 | * @param string $message |
||
85 | */ |
||
86 | protected function assertFileContains($fileContent, $filePath, $message = '') |
||
94 | |||
95 | /// |
||
96 | // Filesystem Functions |
||
97 | /// |
||
98 | |||
99 | /** |
||
100 | * Create a temporary folder where temporary file writes will be made to. |
||
101 | * |
||
102 | * @param string $folderName |
||
103 | */ |
||
104 | protected function createAssetFolder($folderName) |
||
110 | |||
111 | /** |
||
112 | * Write a file to the asset folder. |
||
113 | * |
||
114 | * This file will be written to the actual filesystem and not the virtual filesystem. This file will be deleted at |
||
115 | * each tearDown(). |
||
116 | * |
||
117 | * @param string $fileName |
||
118 | * @param string $content |
||
119 | * |
||
120 | * @return string Path to the temporary file; relative to the project's root |
||
121 | */ |
||
122 | protected function createPhysicalFile($fileName, $content) |
||
129 | |||
130 | /** |
||
131 | * Write a file to the virtual filesystem. |
||
132 | * |
||
133 | * This file will be deleted at each tearDown(). |
||
134 | * |
||
135 | * @param string $filename |
||
136 | * @param string $content |
||
137 | * |
||
138 | * @return string The URL of the file on the virtual filesystem. |
||
139 | */ |
||
140 | protected function createVirtualFile($filename, $content) |
||
150 | |||
151 | /** |
||
152 | * Create an object of a given type. |
||
153 | * |
||
154 | * This will create a virtual file and then create an object of the specified type for the created file. |
||
155 | * |
||
156 | * @param string $classType |
||
157 | * @param string $filename |
||
158 | * @param string $content |
||
159 | * |
||
160 | * @return object An instance of $classType |
||
161 | */ |
||
162 | protected function createDocumentOfType($classType, $filename, $content) |
||
168 | |||
169 | /** |
||
170 | * Create an object of a given type following the Front Matter format. |
||
171 | * |
||
172 | * @param string $classType |
||
173 | * @param string $filename |
||
174 | * @param array $frontMatter |
||
175 | * @param string $content |
||
176 | * |
||
177 | * @return object An instance of $classType |
||
178 | */ |
||
179 | protected function createFrontMatterDocumentOfType($classType, $filename = null, $frontMatter = [], $content = 'Body Text') |
||
190 | |||
191 | /** |
||
192 | * Create multiple virtual files from a given array of information. |
||
193 | * |
||
194 | * ```php |
||
195 | * $elements = [ |
||
196 | * [ |
||
197 | * 'filename' => '<string>', |
||
198 | * 'frontmatter' => [], |
||
199 | * 'body' => '<string>', |
||
200 | * ], |
||
201 | * ]; |
||
202 | * ``` |
||
203 | * |
||
204 | * @param string $classType |
||
205 | * @param array $elements |
||
206 | * |
||
207 | * @return array |
||
208 | */ |
||
209 | protected function createMultipleFrontMatterDocumentsOfType($classType, $elements) |
||
228 | |||
229 | /** |
||
230 | * Create a File object from a given path. |
||
231 | * |
||
232 | * @deprecated |
||
233 | * |
||
234 | * @param string $filePath |
||
235 | * |
||
236 | * @return File |
||
237 | */ |
||
238 | protected function createFileObjectFromPath($filePath) |
||
242 | |||
243 | /// |
||
244 | // Mock Objects |
||
245 | /// |
||
246 | |||
247 | /** |
||
248 | * @return CollectionManager|\PHPUnit_Framework_MockObject_MockObject |
||
249 | */ |
||
250 | protected function getMockCollectionManager() |
||
257 | |||
258 | /** |
||
259 | * @return DataManager|\PHPUnit_Framework_MockObject_MockObject |
||
260 | */ |
||
261 | protected function getMockDataManager() |
||
268 | |||
269 | /** |
||
270 | * Get a mock EventDispatcher. |
||
271 | * |
||
272 | * @return EventDispatcherInterface |
||
273 | */ |
||
274 | protected function getMockEventDistpatcher() |
||
278 | |||
279 | /** |
||
280 | * Get a mock logger. |
||
281 | * |
||
282 | * @return LoggerInterface |
||
283 | */ |
||
284 | protected function getMockLogger() |
||
288 | |||
289 | /** |
||
290 | * Get a real logger instance that will save output to the console. |
||
291 | * |
||
292 | * @return StakxLogger |
||
293 | */ |
||
294 | protected function getReadableLogger() |
||
302 | |||
303 | /// |
||
304 | // Utility Functions |
||
305 | /// |
||
306 | |||
307 | /** |
||
308 | * Get the directory of the unit tests. |
||
309 | * |
||
310 | * @return string |
||
311 | */ |
||
312 | protected function getTestRoot() |
||
316 | |||
317 | /** |
||
318 | * Generate a FrontMatter-ready syntax to be used as a file's content. |
||
319 | * |
||
320 | * @param array $frontMatter |
||
321 | * @param string $body |
||
322 | * |
||
323 | * @return string |
||
324 | */ |
||
325 | private function buildFrontMatterTemplate(array $frontMatter = array(), $body = 'Body text') |
||
331 | |||
332 | /// |
||
333 | // Misc Functions |
||
334 | /// |
||
335 | |||
336 | protected function bookCollectionProvider($jailed = false) |
||
352 | } |
||
353 |
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
.