@@ -17,31 +17,75 @@ class ScriptTest extends Testcase
1717 protected $ app ;
1818
1919 /**
20- * @return void
20+ * @param string $name
21+ *
22+ * @return string
23+ */
24+ protected function getActualPage ($ name )
25+ {
26+ $ path = $ this ->app ->getPagesPath ();
27+
28+ $ files = glob ($ path . '/*.md ' );
29+
30+ $ files = is_array ($ files ) ? $ files : array ();
31+
32+ $ selected = '' ;
33+
34+ foreach ($ files as $ file )
35+ {
36+ $ base = basename ($ file );
37+
38+ $ parsed = substr ($ base , 15 , strlen ($ base ));
39+
40+ if ($ parsed === $ name . '.md ' )
41+ {
42+ $ selected = $ file ;
43+
44+ break ;
45+ }
46+ }
47+
48+ /** @var string */
49+ $ actual = file_get_contents ($ selected );
50+
51+ return str_replace ("\r\n" , "\n" , $ actual );
52+ }
53+
54+ /**
55+ * @param string $name
56+ *
57+ * @return string
2158 */
22- public function doSetUp ( )
59+ protected function getTemplate ( $ name )
2360 {
24- $ this ->app = new Console (__DIR__ . '/Fixture ' );
61+ $ path = __DIR__ . '/Fixture/Output/ ' . $ name ;
62+
63+ /** @var string */
64+ $ file = file_get_contents ($ path );
65+
66+ return str_replace ("\r\n" , "\n" , $ file );
2567 }
2668
2769 /**
2870 * @return void
2971 */
30- public function test_compiling_pages ()
72+ public function test_passed_if_page_compiled ()
3173 {
3274 $ create = $ this ->findCommand ('create ' );
3375
34- $ create ->execute (array ('name ' => 'Hello world! ' ));
76+ $ data = array ('name ' => 'Hello world! ' );
77+
78+ $ create ->execute ($ data );
3579
3680 $ test = $ this ->findCommand ('build ' );
3781
3882 $ test ->execute (array ());
3983
40- $ expected = $ this ->getTemplate ('HelloWorld.html ' );
84+ $ expect = $ this ->getTemplate ('HelloWorld.html ' );
4185
4286 $ actual = $ this ->getActualHtml ('hello-world ' );
4387
44- $ this ->assertEquals ($ expected , $ actual );
88+ $ this ->assertEquals ($ expect , $ actual );
4589
4690 $ this ->deletePath ('build ' );
4791
@@ -51,17 +95,19 @@ public function test_compiling_pages()
5195 /**
5296 * @return void
5397 */
54- public function test_creating_new_page ()
98+ public function test_passed_if_page_created ()
5599 {
56100 $ test = $ this ->findCommand ('create ' );
57101
58- $ test ->execute (array ('name ' => 'Hello world! ' ));
102+ $ data = array ('name ' => 'Hello world! ' );
103+
104+ $ test ->execute ($ data );
59105
60- $ expected = $ this ->getTemplate ('HelloWorld.md ' );
106+ $ expect = $ this ->getTemplate ('HelloWorld.md ' );
61107
62108 $ actual = $ this ->getActualPage ('hello-world ' );
63109
64- $ this ->assertEquals ($ expected , $ actual );
110+ $ this ->assertEquals ($ expect , $ actual );
65111 }
66112
67113 /**
@@ -84,10 +130,12 @@ protected function deletePath($name, $path = null)
84130
85131 if (! is_dir ($ path ))
86132 {
87- throw new \InvalidArgumentException ('" ' . $ path . '" must be a directory ' );
133+ $ text = '" ' . $ path . '" must be a directory ' ;
134+
135+ throw new \InvalidArgumentException ($ text );
88136 }
89137
90- if (substr ($ path , strlen ( $ path ) - 1 , 1 ) != '/ ' )
138+ if (substr ($ path , - 1 ) != '/ ' )
91139 {
92140 $ path .= '/ ' ;
93141 }
@@ -111,14 +159,26 @@ protected function deletePath($name, $path = null)
111159 rmdir ($ path );
112160 }
113161
162+ /**
163+ * @return void
164+ */
165+ protected function doSetUp ()
166+ {
167+ $ path = __DIR__ . '/Fixture ' ;
168+
169+ $ this ->app = new Console ($ path );
170+ }
171+
114172 /**
115173 * @param string $name
116174 *
117175 * @return \Symfony\Component\Console\Tester\CommandTester
118176 */
119177 protected function findCommand ($ name )
120178 {
121- return new CommandTester ($ this ->app ->make ()->find ($ name ));
179+ $ command = $ this ->app ->make ()->find ($ name );
180+
181+ return new CommandTester ($ command );
122182 }
123183
124184 /**
@@ -157,58 +217,8 @@ protected function getActualHtml($name)
157217 }
158218
159219 /** @var string */
160- $ result = file_get_contents ($ selected );
161-
162- return str_replace ("\r\n" , "\n" , $ result );
163- }
164-
165- /**
166- * @param string $name
167- *
168- * @return string
169- */
170- protected function getActualPage ($ name )
171- {
172- $ path = $ this ->app ->getPagesPath ();
173-
174- $ files = glob ($ path . '/*.md ' );
175-
176- $ files = is_array ($ files ) ? $ files : array ();
177-
178- $ selected = '' ;
179-
180- foreach ($ files as $ file )
181- {
182- $ base = basename ($ file );
183-
184- $ parsed = substr ($ base , 15 , strlen ($ base ));
220+ $ actual = file_get_contents ($ selected );
185221
186- if ($ parsed === $ name . '.md ' )
187- {
188- $ selected = $ file ;
189-
190- break ;
191- }
192- }
193-
194- /** @var string */
195- $ result = file_get_contents ($ selected );
196-
197- return str_replace ("\r\n" , "\n" , $ result );
198- }
199-
200- /**
201- * @param string $name
202- *
203- * @return string
204- */
205- protected function getTemplate ($ name )
206- {
207- $ path = __DIR__ . '/Fixture/Output/ ' . $ name ;
208-
209- /** @var string */
210- $ file = file_get_contents ($ path );
211-
212- return str_replace ("\r\n" , "\n" , $ file );
222+ return str_replace ("\r\n" , "\n" , $ actual );
213223 }
214224}
0 commit comments