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

tests/phpunit/Filesystem/FileTest.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
 * FileTest
10
 *
11
 * @since 3.2.0
12
 *
13
 * @package Redaxscript
14
 * @category Tests
15
 * @author Henry Ruhs
16
 *
17
 * @covers Redaxscript\Filesystem\File
18
 */
19
20
class FileTest 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
	 * testCreate
35
	 *
36
	 * @since 3.2.0
37
	 *
38
	 * @param string $root
39
	 * @param bool $recursive
40
	 * @param string $file
41
	 * @param array $expectArray
42
	 *
43
	 * @dataProvider providerAutoloader
44
	 */
45
46
	public function testCreate(string $root = null, bool $recursive = null, string $file = null, array $expectArray = [])
47
	{
48
		/* setup */
49
50
		$filesystem = new Filesystem\File();
51
		$filesystem->init(Stream::url($root), $recursive);
52
		$filesystem->createFile($file);
53
54
		/* actual */
55
56
		$actualArray = $filesystem->getArray();
57
58
		/* compare */
59
60
		$this->assertEquals($expectArray, $actualArray);
61
	}
62
63
	/**
64
	 * testReadAndWrite
65
	 *
66
	 * @since 3.2.0
67
	 *
68
	 * @param string $root
69
	 * @param bool $recursive
70
	 * @param string $file
71
	 * @param string $content
72
	 * @param array $expectArray
73
	 *
74
	 * @dataProvider providerAutoloader
75
	 */
76
77
	public function testReadAndWrite(string $root = null, bool $recursive = null, string $file = null, string $content = null, array $expectArray = [])
78
	{
79
		/* setup */
80
81
		$filesystem = new Filesystem\File();
82
		$filesystem->init(Stream::url($root), $recursive);
83
		$filesystem->writeFile($file, $content);
84
85
		/* actual */
86
87
		$actualArray =
88
		[
89
			$filesystem->readFile($file),
90
			$filesystem->renderFile($file)
91
		];
92
93
		/* compare */
94
95
		$this->assertEquals($expectArray, $actualArray);
96
	}
97
98
	/**
99
	 * testRemove
100
	 *
101
	 * @since 3.2.0
102
	 *
103
	 * @param string $root
104
	 * @param bool $recursive
105
	 * @param string $file
106
	 * @param array $expectArray
107
	 *
108
	 * @dataProvider providerAutoloader
109
	 */
110
111
	public function testRemove(string $root = null, bool $recursive = null, string $file = null, array $expectArray = [])
112
	{
113
		/* setup */
114
115
		$filesystem = new Filesystem\File();
116
		$filesystem->init(Stream::url($root), $recursive);
117
		$filesystem->removeFile($file);
118
119
		/* actual */
120
121
		$actualArray = $filesystem->getArray();
122
123
		/* compare */
124
125
		$this->assertEquals($expectArray, $actualArray);
126
	}
127
}
128