Passed
Push — main ( 650632...004bf9 )
by Justin
03:06
created

OptionBuilderTest::test_create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 6
rs 10
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
0 ignored issues
show
Unused Code introduced by
The assignment to $inputOption is dead and can be removed.
Loading history...
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
}