FileTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 108
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testCreate() 0 16 1
A testReadAndWrite() 0 20 1
A testRemove() 0 16 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
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() : void
29
	{
30
		Stream::setup('root', 0777, $this->getJSON('tests' . DIRECTORY_SEPARATOR. 'unit-provider' . DIRECTORY_SEPARATOR. 'Filesystem' . DIRECTORY_SEPARATOR. 'FilesystemTest_setUp.json'));
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 = []) : void
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 = []) : void
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 = []) : void
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