TYPO3  7.6
IteratorTestCase.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Symfony\Component\Finder\Tests\Iterator;
13 
14 abstract class IteratorTestCase extends \PHPUnit_Framework_TestCase
15 {
16  protected function assertIterator($expected, \Traversable $iterator)
17  {
18  // set iterator_to_array $use_key to false to avoid values merge
19  // this made FinderTest::testAppendWithAnArray() failed with GnuFinderAdapter
20  $values = array_map(function (\SplFileInfo $fileinfo) { return str_replace('/', DIRECTORY_SEPARATOR, $fileinfo->getPathname()); }, iterator_to_array($iterator, false));
21 
22  $expected = array_map(function ($path) { return str_replace('/', DIRECTORY_SEPARATOR, $path); }, $expected);
23 
24  sort($values);
25  sort($expected);
26 
27  $this->assertEquals($expected, array_values($values));
28  }
29 
30  protected function assertOrderedIterator($expected, \Traversable $iterator)
31  {
32  $values = array_map(function (\SplFileInfo $fileinfo) { return $fileinfo->getPathname(); }, iterator_to_array($iterator));
33 
34  $this->assertEquals($expected, array_values($values));
35  }
36 
47  protected function assertOrderedIteratorForGroups($expected, \Traversable $iterator)
48  {
49  $values = array_values(array_map(function (\SplFileInfo $fileinfo) { return $fileinfo->getPathname(); }, iterator_to_array($iterator)));
50 
51  foreach ($expected as $subarray) {
52  $temp = array();
53  while (count($values) && count($temp) < count($subarray)) {
54  $temp[] = array_shift($values);
55  }
56  sort($temp);
57  sort($subarray);
58  $this->assertEquals($subarray, $temp);
59  }
60  }
61 
68  protected function assertIteratorInForeach($expected, \Traversable $iterator)
69  {
70  $values = array();
71  foreach ($iterator as $file) {
72  $this->assertInstanceOf('Symfony\\Component\\Finder\\SplFileInfo', $file);
73  $values[] = $file->getPathname();
74  }
75 
76  sort($values);
77  sort($expected);
78 
79  $this->assertEquals($expected, array_values($values));
80  }
81 
88  protected function assertOrderedIteratorInForeach($expected, \Traversable $iterator)
89  {
90  $values = array();
91  foreach ($iterator as $file) {
92  $this->assertInstanceOf('Symfony\\Component\\Finder\\SplFileInfo', $file);
93  $values[] = $file->getPathname();
94  }
95 
96  $this->assertEquals($expected, array_values($values));
97  }
98 }