|
1
|
|
|
<?php namespace Venta\Console; |
|
2
|
|
|
|
|
3
|
|
|
use PHPUnit\Framework\TestCase; |
|
4
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
5
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
8
|
|
|
|
|
9
|
|
|
class CommandTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @test |
|
13
|
|
|
*/ |
|
14
|
|
|
public function canAcceptOptionsAndAgruments() |
|
15
|
|
|
{ |
|
16
|
|
|
$command = new class() extends \Venta\Console\Command |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
public function handle(InputInterface $input, OutputInterface $output) |
|
20
|
|
|
{ |
|
21
|
|
|
$this->write($this->arg('argument')); |
|
22
|
|
|
$this->write($this->opt('option')); |
|
23
|
|
|
$this->writeln('abc'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function signature(): string |
|
27
|
|
|
{ |
|
28
|
|
|
return 'test'; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function returnArguments(): array |
|
32
|
|
|
{ |
|
33
|
|
|
return [new InputArgument('argument')]; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function returnOptions(): array |
|
37
|
|
|
{ |
|
38
|
|
|
return [new InputOption('option')]; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
}; |
|
42
|
|
|
|
|
43
|
|
|
$output = new \Symfony\Component\Console\Output\BufferedOutput(); |
|
44
|
|
|
$input = new \Symfony\Component\Console\Input\ArrayInput(['argument' => 'value1', '--option' => 'value2']); |
|
45
|
|
|
$command->run($input, $output); |
|
46
|
|
|
$this->assertSame("value1value2abc\n", $output->fetch()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @test |
|
51
|
|
|
*/ |
|
52
|
|
|
public function canArgumentAndOptionBeDefinedInSignature() |
|
53
|
|
|
{ |
|
54
|
|
|
$command = new class() extends \Venta\Console\Command |
|
55
|
|
|
{ |
|
56
|
|
|
|
|
57
|
|
|
public function handle(InputInterface $input, OutputInterface $output) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->write($this->arg('a')); |
|
60
|
|
|
$this->write($this->opt('o')); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function signature(): string |
|
64
|
|
|
{ |
|
65
|
|
|
return 'test {--o} {a}'; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
}; |
|
69
|
|
|
|
|
70
|
|
|
$output = new \Symfony\Component\Console\Output\BufferedOutput(); |
|
71
|
|
|
$input = new \Symfony\Component\Console\Input\ArrayInput(['a' => 'argument', '--o' => 'option']); |
|
72
|
|
|
$command->run($input, $output); |
|
73
|
|
|
$this->assertSame("argumentoption", $output->fetch()); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @test |
|
78
|
|
|
*/ |
|
79
|
|
|
public function canHandle() |
|
80
|
|
|
{ |
|
81
|
|
|
$command = new class() extends \Venta\Console\Command |
|
82
|
|
|
{ |
|
83
|
|
|
|
|
84
|
|
|
public function handle(InputInterface $input, OutputInterface $output) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->write('abc'); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function signature(): string |
|
90
|
|
|
{ |
|
91
|
|
|
return 'test'; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
}; |
|
95
|
|
|
|
|
96
|
|
|
$output = new \Symfony\Component\Console\Output\BufferedOutput(); |
|
97
|
|
|
$command->run(new \Symfony\Component\Console\Input\ArrayInput([]), $output); |
|
98
|
|
|
$this->assertSame('abc', $output->fetch()); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|