4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Finder\Tests\Comparator;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Finder\Comparator\NumberComparator;
17 class NumberComparatorTest extends TestCase
20 * @dataProvider getConstructorTestData
22 public function testConstructor($successes, $failures)
24 foreach ($successes as $s) {
25 new NumberComparator($s);
28 foreach ($failures as $f) {
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.');
39 * @dataProvider getTestData
41 public function testTest($test, $match, $noMatch)
43 $c = new NumberComparator($test);
45 foreach ($match as $m) {
46 $this->assertTrue($c->test($m), '->test() tests a string against the expression');
49 foreach ($noMatch as $m) {
50 $this->assertFalse($c->test($m), '->test() tests a string against the expression');
54 public function getTestData()
57 array('< 1000', array('500', '999'), array('1000', '1500')),
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')),
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')),
71 array('1KI', array('1024'), array('1023', '1025')),
72 array('==1KI', array('1024'), array('1023', '1025')),
74 array('==1m', array('1000000'), array('999999', '1000001')),
75 array('==1mi', array(1024 * 1024), array(1024 * 1024 - 1, 1024 * 1024 + 1)),
77 array('==1g', array('1000000000'), array('999999999', '1000000001')),
78 array('==1gi', array(1024 * 1024 * 1024), array(1024 * 1024 * 1024 - 1, 1024 * 1024 * 1024 + 1)),
80 array('!= 1000', array('500', '999'), array('1000')),
84 public function getConstructorTestData()
90 '3.5', '33.55', '123.456', '123456.78',
94 '==1', '!=1', '<1', '>1', '<=1', '>=1',
95 '==1k', '==1ki', '==1m', '==1mi', '==1g', '==1gi',
96 '1k', '1ki', '1m', '1mi', '1g', '1gi',
102 '0 . 1', '123 .45', '234. 567',
103 '..', '.0.', '0.1.2',