Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5aef120

Browse filesBrowse files
committed
minor #42164 [Finder] Improve ComparatorTest (derrabus)
This PR was merged into the 4.4 branch. Discussion ---------- [Finder] Improve ComparatorTest | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | #42137 (comment), #42137 (comment) | License | MIT | Doc PR | not necessary Commits ------- 4c44dce [Finder] Improve ComparatorTest
2 parents 2fe4b00 + 4c44dce commit 5aef120
Copy full SHA for 5aef120

File tree

1 file changed

+47
-18
lines changed
Filter options

1 file changed

+47
-18
lines changed

‎src/Symfony/Component/Finder/Tests/Comparator/ComparatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Finder/Tests/Comparator/ComparatorTest.php
+47-18Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@ class ComparatorTest extends TestCase
1818
{
1919
public function testGetSetOperator()
2020
{
21-
$comparator = new Comparator();
22-
try {
23-
$comparator->setOperator('foo');
24-
$this->fail('->setOperator() throws an \InvalidArgumentException if the operator is not valid.');
25-
} catch (\Exception $e) {
26-
$this->assertInstanceOf(\InvalidArgumentException::class, $e, '->setOperator() throws an \InvalidArgumentException if the operator is not valid.');
27-
}
28-
2921
$comparator = new Comparator();
3022
$comparator->setOperator('>');
3123
$this->assertEquals('>', $comparator->getOperator(), '->getOperator() returns the current operator');
3224
}
3325

26+
public function testInvalidOperator()
27+
{
28+
$comparator = new Comparator();
29+
30+
$this->expectException(\InvalidArgumentException::class);
31+
$this->expectExceptionMessage('Invalid operator "foo".');
32+
$comparator->setOperator('foo');
33+
}
34+
3435
public function testGetSetTarget()
3536
{
3637
$comparator = new Comparator();
@@ -39,27 +40,55 @@ public function testGetSetTarget()
3940
}
4041

4142
/**
42-
* @dataProvider getTestData
43+
* @dataProvider provideMatches
4344
*/
44-
public function testTest($operator, $target, $match, $noMatch)
45+
public function testTestSucceeds(string $operator, string $target, string $testedValue)
4546
{
4647
$c = new Comparator();
4748
$c->setOperator($operator);
4849
$c->setTarget($target);
4950

50-
foreach ($match as $m) {
51-
$this->assertTrue($c->test($m), '->test() tests a string against the expression');
52-
}
51+
$this->assertTrue($c->test($testedValue));
52+
}
53+
54+
public function provideMatches(): array
55+
{
56+
return [
57+
['<', '1000', '500'],
58+
['<', '1000', '999'],
59+
['<=', '1000', '999'],
60+
['!=', '1000', '999'],
61+
['<=', '1000', '1000'],
62+
['==', '1000', '1000'],
63+
['>=', '1000', '1000'],
64+
['>=', '1000', '1001'],
65+
['>', '1000', '1001'],
66+
['>', '1000', '5000'],
67+
];
68+
}
69+
70+
/**
71+
* @dataProvider provideNonMatches
72+
*/
73+
public function testTestFails(string $operator, string $target, string $testedValue)
74+
{
75+
$c = new Comparator();
76+
$c->setOperator($operator);
77+
$c->setTarget($target);
5378

54-
foreach ($noMatch as $m) {
55-
$this->assertFalse($c->test($m), '->test() tests a string against the expression');
56-
}
79+
$this->assertFalse($c->test($testedValue));
5780
}
5881

59-
public function getTestData()
82+
public function provideNonMatches(): array
6083
{
6184
return [
62-
['<', '1000', ['500', '999'], ['1000', '1500']],
85+
['>', '1000', '500'],
86+
['>=', '1000', '500'],
87+
['>', '1000', '1000'],
88+
['!=', '1000', '1000'],
89+
['<', '1000', '1000'],
90+
['<', '1000', '1500'],
91+
['<=', '1000', '1500'],
6392
];
6493
}
6594
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.