From 236623fd8ad23e04f86d363f5e9e481761812a30 Mon Sep 17 00:00:00 2001 From: Alex Bakhturin Date: Wed, 24 Sep 2014 16:34:46 -0700 Subject: [PATCH 1/4] Make Finder's Iterator tests less fragile [Finder] Modified the Iterator tests so that they assert only on what's actually being tested. In particular, the tests were checking the order of the files that were created at the same time after sorting them by date. This change is a part of the effort to make Symfony successfully pass tests on HHVM --- .../Tests/Iterator/IteratorTestCase.php | 25 ++++++ .../Tests/Iterator/RealIteratorTestCase.php | 6 +- .../Tests/Iterator/SortableIteratorTest.php | 84 +++++++++++-------- 3 files changed, 80 insertions(+), 35 deletions(-) diff --git a/src/Symfony/Component/Finder/Tests/Iterator/IteratorTestCase.php b/src/Symfony/Component/Finder/Tests/Iterator/IteratorTestCase.php index 504cfb01b1cee..5f74f380957c7 100644 --- a/src/Symfony/Component/Finder/Tests/Iterator/IteratorTestCase.php +++ b/src/Symfony/Component/Finder/Tests/Iterator/IteratorTestCase.php @@ -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 * diff --git a/src/Symfony/Component/Finder/Tests/Iterator/RealIteratorTestCase.php b/src/Symfony/Component/Finder/Tests/Iterator/RealIteratorTestCase.php index 8aa5c89d82fc2..2a7383dc0a908 100644 --- a/src/Symfony/Component/Finder/Tests/Iterator/RealIteratorTestCase.php +++ b/src/Symfony/Component/Finder/Tests/Iterator/RealIteratorTestCase.php @@ -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; diff --git a/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php b/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php index f4def17a18376..4a7ad0b076b71 100644 --- a/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php +++ b/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php @@ -54,11 +54,19 @@ public function testAccept($mode, $expected) $iterator = new SortableIterator($inner, $mode); - $this->assertOrderedIterator($expected, $iterator); + if (!is_callable($mode) && + ($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() { + $sortByName = array( '.bar', '.foo', @@ -102,45 +110,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( From 9392e05851e55e42ed49126350d0817fce11e4a7 Mon Sep 17 00:00:00 2001 From: Alex Bakhturin Date: Thu, 25 Sep 2014 09:06:15 -0700 Subject: [PATCH 2/4] Make the proposed changes. --- .../Finder/Tests/Iterator/SortableIteratorTest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php b/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php index 4a7ad0b076b71..65c8a37a22d89 100644 --- a/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php +++ b/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php @@ -55,9 +55,9 @@ public function testAccept($mode, $expected) $iterator = new SortableIterator($inner, $mode); if (!is_callable($mode) && - ($mode == SortableIterator::SORT_BY_ACCESSED_TIME - || $mode == SortableIterator::SORT_BY_CHANGED_TIME - || $mode == SortableIterator::SORT_BY_MODIFIED_TIME)) { + ($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); @@ -66,7 +66,6 @@ public function testAccept($mode, $expected) public function getAcceptData() { - $sortByName = array( '.bar', '.foo', From 041ad8eec81ddb8e29afc0a00f839d23b3826f1a Mon Sep 17 00:00:00 2001 From: Alex Bakhturin Date: Thu, 25 Sep 2014 09:10:39 -0700 Subject: [PATCH 3/4] Apply the coding standard-fixing patch. --- .../Finder/Tests/Iterator/SortableIteratorTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php b/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php index 65c8a37a22d89..1a92875679e39 100644 --- a/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php +++ b/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php @@ -120,10 +120,10 @@ public function getAcceptData() 'test.py', 'foo', 'toto', - 'foo bar' + 'foo bar', ), // This file was accessed after sleeping for 1 sec - array('.bar') + array('.bar'), ); $sortByChangedTime = array( @@ -136,10 +136,10 @@ public function getAcceptData() 'foo', 'foo/bar.tmp', 'toto', - 'foo bar' + 'foo bar', ), array('test.php'), - array('test.py') + array('test.py'), ); $sortByModifiedTime = array( @@ -152,10 +152,10 @@ public function getAcceptData() 'foo', 'foo/bar.tmp', 'toto', - 'foo bar' + 'foo bar', ), array('test.php'), - array('test.py') + array('test.py'), ); return array( From 979fe0e3d052faf03944c78e84b71fd73cdd0f4d Mon Sep 17 00:00:00 2001 From: Alex Bakhturin Date: Thu, 25 Sep 2014 13:45:26 -0700 Subject: [PATCH 4/4] Removed a redundant check. --- .../Component/Finder/Tests/Iterator/SortableIteratorTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php b/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php index 1a92875679e39..e2f433f8e74c3 100644 --- a/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php +++ b/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php @@ -54,10 +54,9 @@ public function testAccept($mode, $expected) $iterator = new SortableIterator($inner, $mode); - if (!is_callable($mode) && - ($mode === SortableIterator::SORT_BY_ACCESSED_TIME + if ($mode === SortableIterator::SORT_BY_ACCESSED_TIME || $mode === SortableIterator::SORT_BY_CHANGED_TIME - || $mode === SortableIterator::SORT_BY_MODIFIED_TIME)) { + || $mode === SortableIterator::SORT_BY_MODIFIED_TIME) { $this->assertOrderedIteratorForGroups($expected, $iterator); } else { $this->assertOrderedIterator($expected, $iterator); 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