Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / psy / psysh / test / Input / FilterOptionsTest.php
1 <?php
2
3 /*
4  * This file is part of Psy Shell.
5  *
6  * (c) 2012-2018 Justin Hileman
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Psy\Test\Input;
13
14 use Psy\Input\FilterOptions;
15 use Symfony\Component\Console\Input\InputDefinition;
16 use Symfony\Component\Console\Input\StringInput;
17
18 class FilterOptionsTest extends \PHPUnit\Framework\TestCase
19 {
20     public function testGetOptions()
21     {
22         $opts = FilterOptions::getOptions();
23         $this->assertCount(3, $opts);
24     }
25
26     /**
27      * @dataProvider validInputs
28      */
29     public function testBindValidInput($input, $hasFilter = true)
30     {
31         $input = $this->getInput($input);
32         $filterOptions = new FilterOptions();
33         $filterOptions->bind($input);
34
35         $this->assertEquals($hasFilter, $filterOptions->hasFilter());
36     }
37
38     public function validInputs()
39     {
40         return [
41             ['--grep="bar"'],
42             ['--grep="bar" --invert'],
43             ['--grep="bar" --insensitive'],
44             ['--grep="bar" --invert --insensitive'],
45             ['', false],
46         ];
47     }
48
49     /**
50      * @dataProvider invalidInputs
51      * @expectedException \Psy\Exception\RuntimeException
52      */
53     public function testBindInvalidInput($input)
54     {
55         $input = $this->getInput($input);
56         $filterOptions = new FilterOptions();
57         $filterOptions->bind($input);
58     }
59
60     public function invalidInputs()
61     {
62         return [
63             ['--invert'],
64             ['--insensitive'],
65             ['--invert --insensitive'],
66
67             // invalid because regex
68             ['--grep /*/'],
69         ];
70     }
71
72     /**
73      * @dataProvider matchData
74      */
75     public function testMatch($input, $str, $matches)
76     {
77         $input = $this->getInput($input);
78         $filterOptions = new FilterOptions();
79         $filterOptions->bind($input);
80
81         $this->assertEquals($matches, $filterOptions->match($str));
82     }
83
84     public function matchData()
85     {
86         return [
87             ['', 'whatever', true],
88             ['--grep FOO', 'foo', false],
89             ['--grep foo', 'foo', true],
90             ['--grep foo', 'food', true],
91             ['--grep oo', 'Food', true],
92             ['--grep oo -i', 'FOOD', true],
93             ['--grep foo -v', 'food', false],
94             ['--grep foo -v', 'whatever', true],
95         ];
96     }
97
98     private function getInput($input)
99     {
100         $input = new StringInput($input);
101         $input->bind(new InputDefinition(FilterOptions::getOptions()));
102
103         return $input;
104     }
105 }