scratch – Blame information for rev 122
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
120 | office | 1 | <?php |
2 | |||
3 | /* |
||
4 | * This file is part of the Symfony package. |
||
5 | * |
||
6 | * (c) Fabien Potencier <fabien@symfony.com> |
||
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 Symfony\Component\Finder\Tests\Comparator; |
||
13 | |||
14 | use PHPUnit\Framework\TestCase; |
||
15 | use Symfony\Component\Finder\Comparator\NumberComparator; |
||
16 | |||
17 | class NumberComparatorTest extends TestCase |
||
18 | { |
||
19 | /** |
||
20 | * @dataProvider getConstructorTestData |
||
21 | */ |
||
22 | public function testConstructor($successes, $failures) |
||
23 | { |
||
24 | foreach ($successes as $s) { |
||
25 | new NumberComparator($s); |
||
26 | } |
||
27 | |||
28 | foreach ($failures as $f) { |
||
29 | try { |
||
30 | new NumberComparator($f); |
||
31 | $this->fail('__construct() throws an \InvalidArgumentException if the test expression is not valid.'); |
||
32 | } catch (\Exception $e) { |
||
33 | $this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the test expression is not valid.'); |
||
34 | } |
||
35 | } |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @dataProvider getTestData |
||
40 | */ |
||
41 | public function testTest($test, $match, $noMatch) |
||
42 | { |
||
43 | $c = new NumberComparator($test); |
||
44 | |||
45 | foreach ($match as $m) { |
||
46 | $this->assertTrue($c->test($m), '->test() tests a string against the expression'); |
||
47 | } |
||
48 | |||
49 | foreach ($noMatch as $m) { |
||
50 | $this->assertFalse($c->test($m), '->test() tests a string against the expression'); |
||
51 | } |
||
52 | } |
||
53 | |||
54 | public function getTestData() |
||
55 | { |
||
56 | return array( |
||
57 | array('< 1000', array('500', '999'), array('1000', '1500')), |
||
58 | |||
59 | array('< 1K', array('500', '999'), array('1000', '1500')), |
||
60 | array('<1k', array('500', '999'), array('1000', '1500')), |
||
61 | array(' < 1 K ', array('500', '999'), array('1000', '1500')), |
||
62 | array('<= 1K', array('1000'), array('1001')), |
||
63 | array('> 1K', array('1001'), array('1000')), |
||
64 | array('>= 1K', array('1000'), array('999')), |
||
65 | |||
66 | array('< 1KI', array('500', '1023'), array('1024', '1500')), |
||
67 | array('<= 1KI', array('1024'), array('1025')), |
||
68 | array('> 1KI', array('1025'), array('1024')), |
||
69 | array('>= 1KI', array('1024'), array('1023')), |
||
70 | |||
71 | array('1KI', array('1024'), array('1023', '1025')), |
||
72 | array('==1KI', array('1024'), array('1023', '1025')), |
||
73 | |||
74 | array('==1m', array('1000000'), array('999999', '1000001')), |
||
75 | array('==1mi', array(1024 * 1024), array(1024 * 1024 - 1, 1024 * 1024 + 1)), |
||
76 | |||
77 | array('==1g', array('1000000000'), array('999999999', '1000000001')), |
||
78 | array('==1gi', array(1024 * 1024 * 1024), array(1024 * 1024 * 1024 - 1, 1024 * 1024 * 1024 + 1)), |
||
79 | |||
80 | array('!= 1000', array('500', '999'), array('1000')), |
||
81 | ); |
||
82 | } |
||
83 | |||
84 | public function getConstructorTestData() |
||
85 | { |
||
86 | return array( |
||
87 | array( |
||
88 | array( |
||
89 | '1', '0', |
||
90 | '3.5', '33.55', '123.456', '123456.78', |
||
91 | '.1', '.123', |
||
92 | '.0', '0.0', |
||
93 | '1.', '0.', '123.', |
||
94 | '==1', '!=1', '<1', '>1', '<=1', '>=1', |
||
95 | '==1k', '==1ki', '==1m', '==1mi', '==1g', '==1gi', |
||
96 | '1k', '1ki', '1m', '1mi', '1g', '1gi', |
||
97 | ), |
||
98 | array( |
||
99 | false, null, '', |
||
100 | ' ', 'foobar', |
||
101 | '=1', '===1', |
||
102 | '0 . 1', '123 .45', '234. 567', |
||
103 | '..', '.0.', '0.1.2', |
||
104 | ), |
||
105 | ), |
||
106 | ); |
||
107 | } |
||
108 | } |