Skip to content

Commit 73937c4

Browse files
committed
Rework unit tests in "tests"
1 parent 3fee55e commit 73937c4

3 files changed

Lines changed: 95 additions & 83 deletions

File tree

tests/AppTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,28 @@ class AppTest extends Testcase
1414
/**
1515
* @return void
1616
*/
17-
public function test_combustor_yml_file()
17+
public function test_passed_if_config_file()
1818
{
1919
$app = new Console(__DIR__ . '/Fixture');
2020

21-
$expected = 'Rougin\Blueprint\Wrapper';
21+
$expect = 'Rougin\Blueprint\Wrapper';
2222

2323
$actual = $app->make()->find('create');
2424

25-
$this->assertInstanceOf($expected, $actual);
25+
$this->assertInstanceOf($expect, $actual);
2626
}
2727

2828
/**
2929
* @return void
3030
*/
31-
public function test_without_combustor_yml()
31+
public function test_passed_if_no_config_file()
3232
{
3333
$app = new Console(__DIR__ . '/../');
3434

35-
$expected = 'Rougin\Blueprint\Wrapper';
35+
$expect = 'Rougin\Blueprint\Wrapper';
3636

3737
$actual = $app->make()->find('initialize');
3838

39-
$this->assertInstanceOf($expected, $actual);
39+
$this->assertInstanceOf($expect, $actual);
4040
}
4141
}

tests/FileTest.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,26 @@ class FileTest extends ScriptTest
1212
/**
1313
* @return void
1414
*/
15-
public function doSetUp()
15+
public function test_passed_if_config_path()
1616
{
17-
$this->app = new Console(__DIR__ . '/Fixture/Sample');
17+
$path = __DIR__ . '/Fixture/Sample/config';
18+
19+
$ds = DIRECTORY_SEPARATOR;
20+
21+
$expect = str_replace(array('/', '\\'), $ds, $path);
22+
23+
$actual = $this->app->getConfigPath();
24+
25+
$this->assertEquals($expect, $actual);
1826
}
1927

2028
/**
2129
* @return void
2230
*/
23-
public function test_config_path()
31+
protected function doSetUp()
2432
{
25-
$expected = __DIR__ . '/Fixture/Sample/config';
26-
27-
$ds = DIRECTORY_SEPARATOR;
28-
29-
$expected = str_replace(array('/', '\\'), $ds, $expected);
30-
31-
$actual = $this->app->getConfigPath();
33+
$path = __DIR__ . '/Fixture/Sample';
3234

33-
$this->assertEquals($expected, $actual);
35+
$this->app = new Console($path);
3436
}
3537
}

tests/ScriptTest.php

Lines changed: 76 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)