Skip to content

Commit

Permalink
Merge branch '4.4' into 5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobion committed Jul 17, 2021
2 parents 1b2363d + f638807 commit f1b7140
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ public function append(iterable $iterator)
$this->iterators[] = $iterator->getIterator();
} elseif ($iterator instanceof \Iterator) {
$this->iterators[] = $iterator;
} elseif ($iterator instanceof \Traversable || \is_array($iterator)) {
} elseif (is_iterable($iterator)) {
$it = new \ArrayIterator();
foreach ($iterator as $file) {
$file = $file instanceof \SplFileInfo ? $file : new \SplFileInfo($file);
Expand Down
65 changes: 47 additions & 18 deletions 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'],
];
}
}

0 comments on commit f1b7140

Please sign in to comment.