/
vfsStreamContainerIteratorTestCase.php
105 lines (96 loc) · 2.49 KB
/
vfsStreamContainerIteratorTestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* This file is part of vfsStream.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package org\bovigo\vfs
*/
namespace org\bovigo\vfs;
use bovigo\callmap\NewInstance;
use PHPUnit\Framework\TestCase;
/**
* Test for org\bovigo\vfs\vfsStreamContainerIterator.
*/
class vfsStreamContainerIteratorTestCase extends TestCase
{
/**
* instance to test
*
* @type vfsStreamDirectory
*/
private $dir;
/**
* child one
*
* @type vfsStreamContent
*/
private $child1;
/**
* child two
*
* @type vfsStreamContent
*/
private $child2;
/**
* set up test environment
*/
public function setUp()
{
$this->dir = new vfsStreamDirectory('foo');
$this->child1 = NewInstance::of(vfsStreamContent::class)->returns([
'getName' => 'bar'
]);
$this->dir->addChild($this->child1);
$this->child2 = NewInstance::of(vfsStreamContent::class)->returns([
'getName' => 'baz'
]);
$this->dir->addChild($this->child2);
}
/**
* clean up test environment
*/
public function tearDown()
{
vfsStream::enableDotfiles();
}
public function provideSwitchWithExpectations(): array
{
return [
[[vfsStream::class, 'disableDotfiles'], []],
[[vfsStream::class, 'enableDotfiles'], ['.', '..']]
];
}
private function getDirName($dir): string
{
if (is_string($dir)) {
return $dir;
}
return $dir->getName();
}
/**
* @param callable $switchDotFiles
* @param array $dirNames
* @test
* @dataProvider provideSwitchWithExpectations
*/
public function iteration(callable $switchDotFiles, array $dirs)
{
$dirs[] = $this->child1;
$dirs[] = $this->child2;
$switchDotFiles();
$dirIterator = $this->dir->getIterator();
foreach ($dirs as $dir) {
$this->assertEquals($this->getDirName($dir), $dirIterator->key());
$this->assertTrue($dirIterator->valid());
if (!is_string($dir)) {
$this->assertSame($dir, $dirIterator->current());
}
$dirIterator->next();
}
$this->assertFalse($dirIterator->valid());
$this->assertNull($dirIterator->key());
$this->assertNull($dirIterator->current());
}
}