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

[Finder] Improve ComparatorTest #42164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 47 additions & 18 deletions 65 src/Symfony/Component/Finder/Tests/Comparator/ComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@ class ComparatorTest extends TestCase
{
public function testGetSetOperator()
{
$comparator = new Comparator();
try {
$comparator->setOperator('foo');
$this->fail('->setOperator() throws an \InvalidArgumentException if the operator is not valid.');
} catch (\Exception $e) {
$this->assertInstanceOf(\InvalidArgumentException::class, $e, '->setOperator() throws an \InvalidArgumentException if the operator is not valid.');
}

$comparator = new Comparator();
$comparator->setOperator('>');
$this->assertEquals('>', $comparator->getOperator(), '->getOperator() returns the current operator');
}

public function testInvalidOperator()
{
$comparator = new Comparator();

$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid operator "foo".');
$comparator->setOperator('foo');
}

public function testGetSetTarget()
{
$comparator = new Comparator();
Expand All @@ -39,27 +40,55 @@ public function testGetSetTarget()
}

/**
* @dataProvider getTestData
* @dataProvider provideMatches
*/
public function testTest($operator, $target, $match, $noMatch)
public function testTestSucceeds(string $operator, string $target, string $testedValue)
{
$c = new Comparator();
$c->setOperator($operator);
$c->setTarget($target);

foreach ($match as $m) {
$this->assertTrue($c->test($m), '->test() tests a string against the expression');
}
$this->assertTrue($c->test($testedValue));
}

public function provideMatches(): array
{
return [
['<', '1000', '500'],
['<', '1000', '999'],
['<=', '1000', '999'],
['!=', '1000', '999'],
['<=', '1000', '1000'],
['==', '1000', '1000'],
['>=', '1000', '1000'],
['>=', '1000', '1001'],
['>', '1000', '1001'],
['>', '1000', '5000'],
];
}

/**
* @dataProvider provideNonMatches
*/
public function testTestFails(string $operator, string $target, string $testedValue)
{
$c = new Comparator();
$c->setOperator($operator);
$c->setTarget($target);

foreach ($noMatch as $m) {
$this->assertFalse($c->test($m), '->test() tests a string against the expression');
}
$this->assertFalse($c->test($testedValue));
}

public function getTestData()
public function provideNonMatches(): array
{
return [
['<', '1000', ['500', '999'], ['1000', '1500']],
['>', '1000', '500'],
['>=', '1000', '500'],
['>', '1000', '1000'],
['!=', '1000', '1000'],
['<', '1000', '1000'],
['<', '1000', '1500'],
['<=', '1000', '1500'],
];
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.