Completed
Push — master ( cbd317...231b94 )
by Henry
09:43
created

tests/phpunit/Filesystem/FilesystemTest.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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()
30
	{
31
		Stream::setup('root', 0777, $this->getJSON('tests' . DIRECTORY_SEPARATOR. 'provider' . DIRECTORY_SEPARATOR. 'Filesystem' . DIRECTORY_SEPARATOR. 'FilesystemTest_setUp.json'));
0 ignored issues
show
It seems like $this->getJSON('tests' ....systemTest_setUp.json') targeting Redaxscript\Tests\TestCaseAbstract::getJSON() can also be of type null; however, org\bovigo\vfs\vfsStream::setup() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
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 = [])
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->assertObject($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 = [])
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 = [])
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