1 | <?php |
||
20 | abstract class PHPUnit_Stakx_TestCase extends \PHPUnit_Framework_TestCase |
||
|
|||
21 | { |
||
22 | const FM_OBJ_TEMPLATE = "---\n%s\n---\n\n%s"; |
||
23 | |||
24 | /** |
||
25 | * @var vfsStreamFile |
||
26 | */ |
||
27 | protected $dummyFile; |
||
28 | |||
29 | /** |
||
30 | * @var vfsStreamDirectory |
||
31 | */ |
||
32 | protected $rootDir; |
||
33 | |||
34 | /** |
||
35 | * @var Filesystem |
||
36 | */ |
||
37 | protected $fs; |
||
38 | |||
39 | public function setUp() |
||
45 | |||
46 | // |
||
47 | // Utility Functions |
||
48 | // |
||
49 | |||
50 | protected function bookCollectionProvider ($jailed = false) |
||
51 | { |
||
52 | $cm = new CollectionManager(); |
||
53 | $cm->setLogger($this->getMockLogger()); |
||
54 | $cm->parseCollections(array( |
||
55 | array( |
||
56 | 'name' => 'books', |
||
57 | 'folder' => 'tests/allejo/stakx/Test/assets/MyBookCollection/' |
||
58 | ) |
||
59 | )); |
||
60 | |||
61 | return ($jailed) ? $cm->getCollections() : $cm->getJailedCollections(); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @param string $classType |
||
66 | * @param array $frontMatter |
||
67 | * @param string $body |
||
68 | * |
||
69 | * @return mixed |
||
70 | */ |
||
71 | protected function createVirtualFile ($classType, $frontMatter = array(), $body = "Body Text") |
||
79 | |||
80 | protected function createMultipleVirtualFiles ($classType, $elements) |
||
81 | { |
||
82 | $results = array(); |
||
83 | |||
84 | foreach ($elements as $element) |
||
85 | { |
||
86 | $filename = (isset($element['filename'])) ? $element['filename'] : hash('sha256', uniqid(mt_rand(), true), false); |
||
87 | $frontMatter = (empty($element['frontmatter'])) ? '' : Yaml::dump($element['frontmatter'], 2); |
||
88 | $body = (isset($element['body'])) ? $element['body'] : 'Body Text'; |
||
89 | |||
90 | $file = vfsStream::newFile($filename); |
||
91 | $file |
||
92 | ->setContent(sprintf("---\n%s\n---\n\n%s", $frontMatter, $body)) |
||
93 | ->at($this->rootDir); |
||
94 | |||
95 | $results[] = new $classType($file->url()); |
||
96 | } |
||
97 | |||
98 | return $results; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Get a mock logger |
||
103 | * |
||
104 | * @return LoggerInterface |
||
105 | */ |
||
106 | protected function getMockLogger () |
||
110 | |||
111 | /** |
||
112 | * Get a real logger instance that will save output to the console |
||
113 | * |
||
114 | * @return StakxLogger |
||
115 | */ |
||
116 | protected function getReadableLogger () |
||
124 | |||
125 | /** |
||
126 | * Generate a FrontMatter-ready syntax to be used as a file's content |
||
127 | * |
||
128 | * @param array $frontMatter |
||
129 | * @param string $body |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | protected function generateFM (array $frontMatter = array(), $body = 'Body text') |
||
139 | } |
||
140 |
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
.