TYPO3  7.6
NumberComparatorTest.php
Go to the documentation of this file.
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 
15 
16 class NumberComparatorTest extends \PHPUnit_Framework_TestCase
17 {
21  public function testConstructor($successes, $failures)
22  {
23  foreach ($successes as $s) {
24  new NumberComparator($s);
25  }
26 
27  foreach ($failures as $f) {
28  try {
29  new NumberComparator($f);
30  $this->fail('__construct() throws an \InvalidArgumentException if the test expression is not valid.');
31  } catch (\Exception $e) {
32  $this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the test expression is not valid.');
33  }
34  }
35  }
36 
40  public function testTest($test, $match, $noMatch)
41  {
42  $c = new NumberComparator($test);
43 
44  foreach ($match as $m) {
45  $this->assertTrue($c->test($m), '->test() tests a string against the expression');
46  }
47 
48  foreach ($noMatch as $m) {
49  $this->assertFalse($c->test($m), '->test() tests a string against the expression');
50  }
51  }
52 
53  public function getTestData()
54  {
55  return array(
56  array('< 1000', array('500', '999'), array('1000', '1500')),
57 
58  array('< 1K', array('500', '999'), array('1000', '1500')),
59  array('<1k', array('500', '999'), array('1000', '1500')),
60  array(' < 1 K ', array('500', '999'), array('1000', '1500')),
61  array('<= 1K', array('1000'), array('1001')),
62  array('> 1K', array('1001'), array('1000')),
63  array('>= 1K', array('1000'), array('999')),
64 
65  array('< 1KI', array('500', '1023'), array('1024', '1500')),
66  array('<= 1KI', array('1024'), array('1025')),
67  array('> 1KI', array('1025'), array('1024')),
68  array('>= 1KI', array('1024'), array('1023')),
69 
70  array('1KI', array('1024'), array('1023', '1025')),
71  array('==1KI', array('1024'), array('1023', '1025')),
72 
73  array('==1m', array('1000000'), array('999999', '1000001')),
74  array('==1mi', array(1024 * 1024), array(1024 * 1024 - 1, 1024 * 1024 + 1)),
75 
76  array('==1g', array('1000000000'), array('999999999', '1000000001')),
77  array('==1gi', array(1024 * 1024 * 1024), array(1024 * 1024 * 1024 - 1, 1024 * 1024 * 1024 + 1)),
78 
79  array('!= 1000', array('500', '999'), array('1000')),
80  );
81  }
82 
83  public function getConstructorTestData()
84  {
85  return array(
86  array(
87  array(
88  '1', '0',
89  '3.5', '33.55', '123.456', '123456.78',
90  '.1', '.123',
91  '.0', '0.0',
92  '1.', '0.', '123.',
93  '==1', '!=1', '<1', '>1', '<=1', '>=1',
94  '==1k', '==1ki', '==1m', '==1mi', '==1g', '==1gi',
95  '1k', '1ki', '1m', '1mi', '1g', '1gi',
96  ),
97  array(
98  false, null, '',
99  ' ', 'foobar',
100  '=1', '===1',
101  '0 . 1', '123 .45', '234. 567',
102  '..', '.0.', '0.1.2',
103  ),
104  ),
105  );
106  }
107 }