1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Unit; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Modulate\Artisan\Interceptor\OptionBuilder; |
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
8
|
|
|
|
9
|
|
|
use Symfony\Component\Console\Exception\InvalidArgumentException; |
10
|
|
|
|
11
|
|
|
class OptionBuilderTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
protected OptionBuilder $builder; |
14
|
|
|
public function setUp(): void |
15
|
|
|
{ |
16
|
|
|
parent::setUp(); |
17
|
|
|
$this->builder = new OptionBuilder(); |
18
|
|
|
} |
19
|
|
|
/** |
20
|
|
|
* A basic unit test example. |
21
|
|
|
*/ |
22
|
|
|
public function test_create(): void |
23
|
|
|
{ |
24
|
|
|
$inputOption = $this->builder |
25
|
|
|
->name('foo') |
26
|
|
|
->get(); |
27
|
|
|
$this->assertInstanceOf(InputOption::class, $inputOption); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function test_flag(): void |
31
|
|
|
{ |
32
|
|
|
$inputOption = $this->builder |
33
|
|
|
->name('foo') |
34
|
|
|
->flag() |
35
|
|
|
->get(); |
36
|
|
|
$this->assertFalse($inputOption->acceptValue()); |
37
|
|
|
|
38
|
|
|
} |
39
|
|
|
public function test_optional(): void |
40
|
|
|
{ |
41
|
|
|
$inputOption = $this->builder |
42
|
|
|
->name('foo') |
43
|
|
|
->optional() |
44
|
|
|
->get(); |
45
|
|
|
$this->assertFalse($inputOption->isValueRequired()); |
46
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function test_required(): void |
50
|
|
|
{ |
51
|
|
|
$inputOption = $this->builder |
52
|
|
|
->name('foo') |
53
|
|
|
->required() |
54
|
|
|
->get(); |
55
|
|
|
$this->assertTrue($inputOption->isValueRequired()); |
56
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function test_negatable(): void |
60
|
|
|
{ |
61
|
|
|
$inputOption = $this->builder |
62
|
|
|
->name('foo') |
63
|
|
|
->negatable() |
64
|
|
|
->get(); |
65
|
|
|
$this->assertTrue($inputOption->isNegatable()); |
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function test_accepts_array(): void |
70
|
|
|
{ |
71
|
|
|
$inputOption = $this->builder |
72
|
|
|
->name('foo') |
73
|
|
|
->required() |
74
|
|
|
->array() |
75
|
|
|
->get(); |
76
|
|
|
$this->assertTrue($inputOption->isArray()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function test_throws_exception(): void |
80
|
|
|
{ |
81
|
|
|
$this->expectException(InvalidArgumentException::class); |
82
|
|
|
$inputOption = $this->builder |
|
|
|
|
83
|
|
|
->name('foo') |
84
|
|
|
->array() |
85
|
|
|
->get(); |
86
|
|
|
|
87
|
|
|
$this->expectException(InvalidArgumentException::class); |
88
|
|
|
$inputOption = $this->builder |
89
|
|
|
->name('foo') |
90
|
|
|
->flag() |
91
|
|
|
->required() |
92
|
|
|
->get(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
} |