Skip to content

[Finder] [Iterator] Make the tests less fragile #12028

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
25 changes: 25 additions & 0 deletions src/Symfony/Component/Finder/Tests/Iterator/IteratorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,31 @@ protected function assertOrderedIterator($expected, \Traversable $iterator)
$this->assertEquals($expected, array_values($values));
}

/**
* Same as assertOrderedIterator, but checks the order of groups of
* array elements.
*
* @param array $expected - an array of arrays. For any two subarrays
* $a and $b such that $a goes before $b in $expected, the method
* asserts that any element of $a goes before any element of $b
* in the sequence generated by $iterator
* @param \Traversable $iterator
*/
protected function assertOrderedIteratorForGroups($expected, \Traversable $iterator)
{
$values = array_values(array_map(function (\SplFileInfo $fileinfo) { return $fileinfo->getPathname(); }, iterator_to_array($iterator)));

foreach ($expected as $subarray) {
$temp = array();
while (count($values) && count($temp) < count($subarray)) {
array_push($temp, array_shift($values));
}
sort($temp);
sort($subarray);
$this->assertEquals($subarray, $temp);
}
}

/**
* Same as IteratorTestCase::assertIterator with foreach usage
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ protected static function toAbsolute($files = null)
if (is_array($files)) {
$f = array();
foreach ($files as $file) {
$f[] = self::$tmpDir.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, $file);
if (is_array($file)) {
$f[] = self::toAbsolute($file);
} else {
$f[] = self::$tmpDir.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, $file);
}
}

return $f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ public function testAccept($mode, $expected)

$iterator = new SortableIterator($inner, $mode);

$this->assertOrderedIterator($expected, $iterator);
if ($mode === SortableIterator::SORT_BY_ACCESSED_TIME
|| $mode === SortableIterator::SORT_BY_CHANGED_TIME
|| $mode === SortableIterator::SORT_BY_MODIFIED_TIME) {
$this->assertOrderedIteratorForGroups($expected, $iterator);
} else {
$this->assertOrderedIterator($expected, $iterator);
}
}

public function getAcceptData()
Expand Down Expand Up @@ -102,45 +108,53 @@ public function getAcceptData()
);

$sortByAccessedTime = array(
'foo/bar.tmp',
'test.php',
'toto',
'foo bar',
'foo',
'test.py',
'.foo',
'.foo/.bar',
'.foo/bar',
'.git',
'.bar',
// For these two files the access time was set to 2005-10-15
array('foo/bar.tmp', 'test.php'),
// These files were created more or less at the same time
array(
'.git',
'.foo',
'.foo/.bar',
'.foo/bar',
'test.py',
'foo',
'toto',
'foo bar',
),
// This file was accessed after sleeping for 1 sec
array('.bar'),
);

$sortByChangedTime = array(
'foo',
'foo/bar.tmp',
'toto',
'.git',
'.bar',
'.foo',
'foo bar',
'.foo/.bar',
'.foo/bar',
'test.php',
'test.py',
array(
'.git',
'.foo',
'.foo/.bar',
'.foo/bar',
'.bar',
'foo',
'foo/bar.tmp',
'toto',
'foo bar',
),
array('test.php'),
array('test.py'),
);

$sortByModifiedTime = array(
'foo/bar.tmp',
'foo',
'toto',
'.git',
'.bar',
'.foo',
'foo bar',
'.foo/.bar',
'.foo/bar',
'test.php',
'test.py',
array(
'.git',
'.foo',
'.foo/.bar',
'.foo/bar',
'.bar',
'foo',
'foo/bar.tmp',
'toto',
'foo bar',
),
array('test.php'),
array('test.py'),
);

return array(
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy