FilesystemTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 112
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetSortArray() 0 15 1
A setUp() 0 4 1
A testGetIterator() 0 27 3
A testGetArray() 0 15 1
1
<?php
2
namespace Redaxscript\Tests\Filesystem;
3
4
use org\bovigo\vfs\vfsStream as Stream;
5
use Redaxscript\Filesystem;
6
use Redaxscript\Tests\TestCaseAbstract;
7
use function iterator_count;
8
9
/**
10
 * FilesystemTest
11
 *
12
 * @since 3.2.0
13
 *
14
 * @package Redaxscript
15
 * @category Tests
16
 * @author Henry Ruhs
17
 *
18
 * @covers Redaxscript\Filesystem\Filesystem
19
 */
20
21
class FilesystemTest extends TestCaseAbstract
22
{
23
	/**
24
	 * setUp
25
	 *
26
	 * @since 3.2.0
27
	 */
28
29
	public function setUp() : void
30
	{
31
		Stream::setup('root', 0777, $this->getJSON('tests' . DIRECTORY_SEPARATOR. 'unit-provider' . DIRECTORY_SEPARATOR. 'Filesystem' . DIRECTORY_SEPARATOR. 'FilesystemTest_setUp.json'));
32
	}
33
34
	/**
35
	 * testGetIterator
36
	 *
37
	 * @since 3.2.0
38
	 *
39
	 * @param string $root
40
	 * @param bool $recursive
41
	 * @param array $filterArray
42
	 * @param array $expectArray
43
	 *
44
	 * @dataProvider providerAutoloader
45
	 */
46
47
	public function testGetIterator(string $root = null, bool $recursive = false, array $filterArray = [], array $expectArray = []) : void
48
	{
49
		/* setup */
50
51
		$filesystem = new Filesystem\Filesystem();
52
		$filesystem->init(Stream::url($root), $recursive, $filterArray);
53
54
		/* actual */
55
56
		$actualIterator = $filesystem->getIterator();
57
58
		/* process iterator */
59
60
		if (iterator_count($actualIterator))
61
		{
62
			foreach ($actualIterator as $key => $item)
63
			{
64
				$file = $item->getFileName();
65
				$path = $item->getPathName();
66
				$this->assertEquals($expectArray[$file], $this->normalizeSeparator($path));
67
			}
68
		}
69
		else
70
		{
71
			$this->assertIsObject($actualIterator);
72
		}
73
	}
74
75
	/**
76
	 * testGetArray
77
	 *
78
	 * @since 3.2.0
79
	 *
80
	 * @param string $root
81
	 * @param bool $recursive
82
	 * @param array $filterArray
83
	 * @param array $expectArray
84
	 *
85
	 * @dataProvider providerAutoloader
86
	 */
87
88
	public function testGetArray(string $root = null, bool $recursive = false, array $filterArray = [], array $expectArray = []) : void
89
	{
90
		/* setup */
91
92
		$filesystem = new Filesystem\Filesystem();
93
		$filesystem->init(Stream::url($root), $recursive, $filterArray);
94
95
		/* actual */
96
97
		$actualArray = $filesystem->getArray();
98
99
		/* compare */
100
101
		$this->assertEquals($expectArray, $actualArray);
102
	}
103
104
	/**
105
	 * testGetSortArray
106
	 *
107
	 * @since 3.2.0
108
	 *
109
	 * @param string $root
110
	 * @param bool $recursive
111
	 * @param array $filterArray
112
	 * @param array $expectArray
113
	 *
114
	 * @dataProvider providerAutoloader
115
	 */
116
117
	public function testGetSortArray(string $root = null, bool $recursive = false, array $filterArray = [], array $expectArray = []) : void
118
	{
119
		/* setup */
120
121
		$filesystem = new Filesystem\Filesystem();
122
		$filesystem->init(Stream::url($root), $recursive, $filterArray);
123
124
		/* actual */
125
126
		$actualArray = $filesystem->getSortArray();
127
128
		/* compare */
129
130
		$this->assertEquals($expectArray, $actualArray);
131
	}
132
}
133