Skip to content

Commit 7423cc1

Browse files
Once more added a lot of unit tests
1 parent 88012ce commit 7423cc1

File tree

4 files changed

+322
-29
lines changed

4 files changed

+322
-29
lines changed

tests/phpbu/Backup/Cli/CmdTest.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
namespace phpbu\Backup\Cli;
33

44
/**
5-
* ExecTest
5+
* CmdTest
66
*
77
* @package phpbu
88
* @subpackage tests
@@ -12,34 +12,37 @@
1212
* @link http://www.phpbu.de/
1313
* @since Class available since Release 1.0.5
1414
*/
15-
class ExecTest extends \PHPUnit_Framework_TestCase
15+
class CmdTest extends \PHPUnit_Framework_TestCase
1616
{
1717
/**
18-
* Tests Exec::getExec
19-
*
20-
* @expectedException \phpbu\App\Exception
18+
* Tests Cmd::getName
2119
*/
22-
public function testGetExecFail()
20+
public function testGetName()
2321
{
24-
$exec = new Exec();
25-
$exec->getExec();
22+
$cmd = new Cmd('foo');
2623

27-
$this->assertFalse(true, 'exception should be thrown');
24+
$this->assertEquals('foo', $cmd->getName(), 'name getter should work properly');
2825
}
2926

3027
/**
3128
* Tests Cmd::addArgument
3229
*/
33-
public function testGetExecOk()
30+
public function testAddArgumentPlain()
3431
{
3532
$cmd = new Cmd('foo');
36-
$cmd->addArgument(array('bar', 'baz'));
33+
$cmd->addArgument('bar');
3734

38-
$exec = new Exec();
39-
$exec->addCommand($cmd);
35+
$this->assertEquals('foo \'bar\'', (string) $cmd, 'argument should be added');
36+
}
4037

41-
$res = $exec->getExec();
38+
/**
39+
* Tests Cmd::addArgument
40+
*/
41+
public function testAddArgumentArray()
42+
{
43+
$cmd = new Cmd('foo');
44+
$cmd->addArgument(array('bar', 'baz'));
4245

43-
$this->assertEquals('foo \'bar\' \'baz\'', $res, 'command should be as planned');
46+
$this->assertEquals('foo \'bar\' \'baz\'', (string) $cmd, 'arguments should be added');
4447
}
4548
}

tests/phpbu/Backup/Cli/ExecTest.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
namespace phpbu\Backup\Cli;
33

44
/**
5-
* CmdTest
5+
* ExecTest
66
*
77
* @package phpbu
88
* @subpackage tests
@@ -12,37 +12,48 @@
1212
* @link http://www.phpbu.de/
1313
* @since Class available since Release 1.0.5
1414
*/
15-
class CmdTest extends \PHPUnit_Framework_TestCase
15+
class ExecTest extends \PHPUnit_Framework_TestCase
1616
{
1717
/**
18-
* Tests Cmd::getName
18+
* Tests Exec::getExec
19+
*
20+
* @expectedException \phpbu\App\Exception
1921
*/
20-
public function testGetName()
22+
public function testGetExecFail()
2123
{
22-
$cmd = new Cmd('foo');
24+
$exec = new Exec();
25+
$exec->getExec();
2326

24-
$this->assertEquals('foo', $cmd->getName(), 'name getter should work properly');
27+
$this->assertFalse(true, 'exception should be thrown');
2528
}
2629

2730
/**
2831
* Tests Cmd::addArgument
2932
*/
30-
public function testAddArgumentPlain()
33+
public function testGetExecOk()
3134
{
3235
$cmd = new Cmd('foo');
33-
$cmd->addArgument('bar');
36+
$cmd->addArgument(array('bar', 'baz'));
37+
38+
$exec = new Exec();
39+
$exec->addCommand($cmd);
40+
41+
$res = $exec->getExec();
3442

35-
$this->assertEquals('foo \'bar\'', (string) $cmd, 'argument should be added');
43+
$this->assertEquals('foo \'bar\' \'baz\'', $res, 'command should be as planned');
3644
}
3745

3846
/**
39-
* Tests Cmd::addArgument
47+
* Tests Exec::execute
4048
*/
41-
public function testAddArgumentArray()
49+
public function testExecute()
4250
{
43-
$cmd = new Cmd('foo');
44-
$cmd->addArgument(array('bar', 'baz'));
51+
$cmd = new Cmd('echo 1');
52+
$exec = new Exec();
53+
$exec->addCommand($cmd);
54+
55+
$res = $exec->execute();
4556

46-
$this->assertEquals('foo \'bar\' \'baz\'', (string) $cmd, 'arguments should be added');
57+
$this->assertEquals(0, $res->getCode(), 'scho should work everywhere');
4758
}
4859
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
namespace phpbu\Backup\Cli;
3+
4+
/**
5+
* CmdTest
6+
*
7+
* @package phpbu
8+
* @subpackage tests
9+
* @author Sebastian Feldmann <sebastian@phpbu.de>
10+
* @copyright Sebastian Feldmann <sebastian@phpbu.de>
11+
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
12+
* @link http://www.phpbu.de/
13+
* @since Class available since Release 1.0.5
14+
*/
15+
class ResultTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* Tests Cmd::getCode
19+
*/
20+
public function testGetCode()
21+
{
22+
$result = new Result('echo 1', 0, array());
23+
$this->assertEquals(0, $result->getCode(), 'code getter should work properly');
24+
}
25+
26+
/**
27+
* Tests Cmd::wasSuccessful
28+
*/
29+
public function testWasSuccessfulTrue()
30+
{
31+
$result = new Result('echo 1', 0, array());
32+
$this->assertEquals(true, $result->wasSuccessful(), 'should be successful on code 0');
33+
}
34+
35+
/**
36+
* Tests Cmd::wasSuccessful
37+
*/
38+
public function testWasSuccessfulFalse()
39+
{
40+
$result = new Result('echo 1', 1, array());
41+
$this->assertEquals(false, $result->wasSuccessful(), 'should not be successful on code 1');
42+
}
43+
44+
/**
45+
* Tests Cmd::getCmd
46+
*/
47+
public function testGetCmd()
48+
{
49+
$result = new Result('echo 1', 0, array());
50+
$this->assertEquals('echo 1', $result->getCmd(), 'cmd getter should work properly');
51+
}
52+
53+
/**
54+
* Tests Cmd::getOutput
55+
*/
56+
public function testGetOutput()
57+
{
58+
$result = new Result('echo 1', 0, array('foo', 'bar'));
59+
$this->assertEquals(2, count($result->getOutput()), 'output getter should work properly');
60+
}
61+
62+
/**
63+
* Tests Cmd::getOutput
64+
*/
65+
public function testGetOutputAsString()
66+
{
67+
$result = new Result('echo 1', 0, array('foo', 'bar'));
68+
$this->assertEquals('foo' . PHP_EOL . 'bar', $result->getOutput(true), 'outputAsString getter should work properly');
69+
}
70+
71+
/**
72+
* Tests Cmd::__toString
73+
*/
74+
public function testToString()
75+
{
76+
$result = new Result('echo 1', 0, array('foo'));
77+
$this->assertEquals('foo', (string) $result, 'toString should work properly');
78+
}
79+
}

0 commit comments

Comments
 (0)