1
|
|
|
<?php namespace Tarsana\Tester; |
2
|
|
|
|
3
|
|
|
use PHPUnit\Framework\TestCase; |
4
|
|
|
use Tarsana\Command\Command; |
5
|
|
|
use Tarsana\Command\Console\Console; |
6
|
|
|
use Tarsana\IO\Filesystem; |
7
|
|
|
use Tarsana\IO\Filesystem\Adapters\Memory; |
8
|
|
|
use Tarsana\IO\Resource\Buffer; |
9
|
|
|
use Tarsana\Tester\Mocks\Transformer; |
10
|
|
|
|
11
|
|
|
class CommandTestCase extends TestCase { |
12
|
|
|
|
13
|
|
|
protected $fs; |
14
|
|
|
protected $cmd; |
15
|
|
|
protected $stdout; |
16
|
|
|
protected $stderr; |
17
|
|
|
|
18
|
|
|
public function setUp() { |
19
|
|
|
$adapter = new Memory; |
20
|
|
|
$adapter->mkdir('.', 0777, true); |
21
|
|
|
$this->fs = new Filesystem('.', $adapter); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function command( |
25
|
|
|
Command $command, array $args = [], |
26
|
|
|
array $options = [], bool $rawArgs = true |
27
|
|
|
) { |
28
|
|
|
$console = (new Console) |
|
|
|
|
29
|
|
|
->stdin(new Buffer) |
30
|
|
|
->stdout(new Buffer) |
31
|
|
|
->stderr(new Buffer) |
32
|
|
|
->outTransformer(new Transformer); |
33
|
|
|
|
34
|
|
|
$this->fs->dir($command->fs()->path(), true); |
35
|
|
|
|
36
|
|
|
$command->console($console) |
37
|
|
|
->fs($this->fs) |
38
|
|
|
->run($args, $options, $rawArgs); |
39
|
|
|
|
40
|
|
|
$this->cmd = $command; |
41
|
|
|
$this->stdout = $console->stdout()->read(); |
42
|
|
|
$this->stderr = $console->stderr()->read(); |
43
|
|
|
|
44
|
|
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function prints(string $text) { |
48
|
|
|
$this->assertTrue( |
49
|
|
|
false !== strpos($this->stdout, $text), |
50
|
|
|
"Failed asserting that '{$this->stdout}' Contains '{$text}'" |
51
|
|
|
); |
52
|
|
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function printsExactly(string $text) { |
56
|
|
|
$this->assertEquals($text, $this->stdout); |
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function printsError(string $text) { |
61
|
|
|
$this->assertTrue( |
62
|
|
|
false !== strpos($this->stderr, $text), |
63
|
|
|
"Failed asserting that '{$this->stderr}' Contains '{$text}'" |
64
|
|
|
); |
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function argsEqual($args) { |
69
|
|
|
$this->assertEquals($args, $this->cmd->args()); |
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function optionsEqual($options) { |
74
|
|
|
$this->assertEquals($options, $this->cmd->options()); |
75
|
|
|
return $this; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: