Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/finder/Tests/Iterator/IteratorTestCase.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
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 use PHPUnit\Framework\TestCase; | |
15 | |
16 abstract class IteratorTestCase extends TestCase | |
17 { | |
18 protected function assertIterator($expected, \Traversable $iterator) | |
19 { | |
20 // set iterator_to_array $use_key to false to avoid values merge | |
21 // this made FinderTest::testAppendWithAnArray() fail with GnuFinderAdapter | |
22 $values = array_map(function (\SplFileInfo $fileinfo) { return str_replace('/', DIRECTORY_SEPARATOR, $fileinfo->getPathname()); }, iterator_to_array($iterator, false)); | |
23 | |
24 $expected = array_map(function ($path) { return str_replace('/', DIRECTORY_SEPARATOR, $path); }, $expected); | |
25 | |
26 sort($values); | |
27 sort($expected); | |
28 | |
29 $this->assertEquals($expected, array_values($values)); | |
30 } | |
31 | |
32 protected function assertOrderedIterator($expected, \Traversable $iterator) | |
33 { | |
34 $values = array_map(function (\SplFileInfo $fileinfo) { return $fileinfo->getPathname(); }, iterator_to_array($iterator)); | |
35 | |
36 $this->assertEquals($expected, array_values($values)); | |
37 } | |
38 | |
39 /** | |
40 * Same as assertOrderedIterator, but checks the order of groups of | |
41 * array elements. | |
42 * | |
43 * @param array $expected - an array of arrays. For any two subarrays | |
44 * $a and $b such that $a goes before $b in $expected, the method | |
45 * asserts that any element of $a goes before any element of $b | |
46 * in the sequence generated by $iterator | |
47 * @param \Traversable $iterator | |
48 */ | |
49 protected function assertOrderedIteratorForGroups($expected, \Traversable $iterator) | |
50 { | |
51 $values = array_values(array_map(function (\SplFileInfo $fileinfo) { return $fileinfo->getPathname(); }, iterator_to_array($iterator))); | |
52 | |
53 foreach ($expected as $subarray) { | |
54 $temp = array(); | |
55 while (count($values) && count($temp) < count($subarray)) { | |
56 $temp[] = array_shift($values); | |
57 } | |
58 sort($temp); | |
59 sort($subarray); | |
60 $this->assertEquals($subarray, $temp); | |
61 } | |
62 } | |
63 | |
64 /** | |
65 * Same as IteratorTestCase::assertIterator with foreach usage. | |
66 * | |
67 * @param array $expected | |
68 * @param \Traversable $iterator | |
69 */ | |
70 protected function assertIteratorInForeach($expected, \Traversable $iterator) | |
71 { | |
72 $values = array(); | |
73 foreach ($iterator as $file) { | |
74 $this->assertInstanceOf('Symfony\\Component\\Finder\\SplFileInfo', $file); | |
75 $values[] = $file->getPathname(); | |
76 } | |
77 | |
78 sort($values); | |
79 sort($expected); | |
80 | |
81 $this->assertEquals($expected, array_values($values)); | |
82 } | |
83 | |
84 /** | |
85 * Same as IteratorTestCase::assertOrderedIterator with foreach usage. | |
86 * | |
87 * @param array $expected | |
88 * @param \Traversable $iterator | |
89 */ | |
90 protected function assertOrderedIteratorInForeach($expected, \Traversable $iterator) | |
91 { | |
92 $values = array(); | |
93 foreach ($iterator as $file) { | |
94 $this->assertInstanceOf('Symfony\\Component\\Finder\\SplFileInfo', $file); | |
95 $values[] = $file->getPathname(); | |
96 } | |
97 | |
98 $this->assertEquals($expected, array_values($values)); | |
99 } | |
100 } |