1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AbacaphiliacTest\Compliments; |
4
|
|
|
|
5
|
|
|
use Abacaphiliac\Compliments\RandomComplimentCommand; |
6
|
|
|
use org\bovigo\vfs\vfsStream; |
7
|
|
|
use Symfony\Component\Console\Input\ArgvInput; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
class RandomComplimentCommandTest extends \PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|OutputInterface */ |
13
|
|
|
private $output; |
|
|
|
|
14
|
|
|
|
15
|
|
|
/** @var RandomComplimentCommand */ |
16
|
|
|
private $sut; |
17
|
|
|
|
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
parent::setUp(); |
21
|
|
|
|
22
|
|
|
$this->output = $this->getMock('\Symfony\Component\Console\Output\OutputInterface'); |
23
|
|
|
|
24
|
|
|
$this->sut = new RandomComplimentCommand(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testRunWithDefaultValues() |
28
|
|
|
{ |
29
|
|
|
$this->output->expects(self::atLeastOnce())->method('writeln'); |
|
|
|
|
30
|
|
|
|
31
|
|
|
$input = new ArgvInput(array()); |
32
|
|
|
|
33
|
|
|
$actual = $this->sut->run($input, $this->output); |
34
|
|
|
|
35
|
|
|
self::assertEmpty($actual); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @expectedException \InvalidArgumentException |
40
|
|
|
* @throws \InvalidArgumentException |
41
|
|
|
* @throws \Exception |
42
|
|
|
*/ |
43
|
|
|
public function testRunWithDirectoryInsteadOfFile() |
44
|
|
|
{ |
45
|
|
|
$dir = vfsStream::setup('tmp'); |
46
|
|
|
|
47
|
|
|
$input = new ArgvInput(array( |
48
|
|
|
__FILE__, |
49
|
|
|
'--file=' . $dir->url(), |
50
|
|
|
)); |
51
|
|
|
|
52
|
|
|
$actual = $this->sut->run($input, $this->output); |
53
|
|
|
|
54
|
|
|
self::assertSame(0, $actual); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @expectedException \InvalidArgumentException |
59
|
|
|
* @throws \InvalidArgumentException |
60
|
|
|
* @throws \Exception |
61
|
|
|
*/ |
62
|
|
|
public function testRunWithNonReadableFile() |
63
|
|
|
{ |
64
|
|
|
$dir = vfsStream::setup('tmp'); |
65
|
|
|
$file = vfsStream::newFile('compliments.txt', 0000); |
66
|
|
|
$dir->addChild($file); |
67
|
|
|
|
68
|
|
|
$input = new ArgvInput(array( |
69
|
|
|
__FILE__, |
70
|
|
|
'--file=' . $file->url(), |
71
|
|
|
)); |
72
|
|
|
|
73
|
|
|
$actual = $this->sut->run($input, $this->output); |
74
|
|
|
|
75
|
|
|
self::assertSame(0, $actual); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|