Passed
Push — test ( d838cf...cef4a5 )
by Tom
03:29
created

OptionMatcherTest::provideOptionArgMatches()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 35
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 33
nc 1
nop 0
dl 0
loc 35
rs 9.392
c 0
b 0
f 0
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\Cli\Args;
6
7
use Ktomk\Pipelines\TestCase;
8
9
/**
10
 * @covers \Ktomk\Pipelines\Cli\Args\OptionMatcher
11
 */
12
class OptionMatcherTest extends TestCase
13
{
14
    public function testCreate()
15
    {
16
        self::assertTrue(OptionMatcher::create('user')->match('--user=1000:1000'));
17
        self::assertFalse(OptionMatcher::create('user')->match('--foo-user=1000:1000'));
18
    }
19
20
    /**
21
     * @return array
22
     */
23
    public function provideOptionArgMatches()
24
    {
25
        return array(
26
            array(false, '', '', false),
27
            array(false, '', '', true),
28
            array(false, 'n', '', false),
29
            array(false, 'n', '', true),
30
            array(false, '', '--option', false),
31
            array(false, '', '--option', true),
32
            array(false, '', 'option', false),
33
            array(false, '', 'option', true),
34
            array(false, 'option', 'option', false),
35
            array(false, 'option', 'option', true),
36
            array(false, 'option', '--', false),
37
            array(false, 'option', '--', true),
38
            array(false, 'option', '--foo', false),
39
            array(false, 'option', '--foo', true),
40
            array(false, 'option', '-option', false),
41
            array(false, 'option', '-option', true),
42
            array(true, 'option', '--option', false),
43
            array(true, 'option', '--option', true),
44
            array(false, 'option', '--=', true),
45
            array(true, 'option', '--option=', true),
46
            array(true, 'option', '--option=bar', true),
47
            array(false, 'b', '-fo', false),
48
            array(false, 'b', '-fo=', false),
49
            array(false, 'b', '-fo=', true),
50
            array(false, 'b', '-fo=ar', false),
51
            array(false, 'b', '-fo=ba', true),
52
            array(true, 'b', '-fo=ba', false),
53
            array(true, 'b', '-bar', false),
54
            array(true, 'b', '-bar', false),
55
            array(true, 'b', '-arb=', true),
56
            array(true, 'b', '-arb=bar', false),
57
            array(true, 'b', '-arb=bar', true),
58
        );
59
    }
60
61
    /**
62
     * @dataProvider provideOptionArgMatches
63
     *
64
     * @param bool $expected
65
     * @param string $option
66
     * @param string $arg
67
     * @param null|bool $equals
68
     */
69
    public function testMatchOptionArg($expected, $option, $arg, $equals)
70
    {
71
        $actual = OptionMatcher::matchOptionArg($option, $arg, $equals);
72
        self::assertSame($expected, $actual);
73
    }
74
75
    /**
76
     * @dataProvider provideOptionArgMatches
77
     *
78
     * @param bool $expected
79
     * @param string|string[] $option
80
     * @param string $arg
81
     * @param null|bool $equals
82
     */
83
    public function testMatch($expected, $option, $arg, $equals)
84
    {
85
        $matcher = new OptionMatcher($option, $equals);
86
        self::assertSame($expected, $matcher->match($arg));
87
    }
88
}
89