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