LoaderTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 92
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testConcat() 0 26 1
A testRewrite() 0 26 1
1
<?php
2
namespace Redaxscript\Tests\Asset;
3
4
use org\bovigo\vfs\vfsStream as Stream;
5
use Redaxscript\Asset;
6
use Redaxscript\Registry;
7
use Redaxscript\Tests\TestCaseAbstract;
8
use function file_get_contents;
9
10
/**
11
 * LoaderTest
12
 *
13
 * @since 3.0.0
14
 *
15
 * @package Redaxscript
16
 * @category Tests
17
 * @author Henry Ruhs
18
 *
19
 * @covers Redaxscript\Asset\Loader
20
 */
21
22
class LoaderTest extends TestCaseAbstract
23
{
24
	/**
25
	 * setUp
26
	 *
27
	 * @since 3.1.0
28
	 */
29
30
	public function setUp() : void
31
	{
32
		parent::setUp();
33
		Stream::setup('root', 0777, $this->getJSON('tests' . DIRECTORY_SEPARATOR . 'unit-provider' . DIRECTORY_SEPARATOR . 'Asset' . DIRECTORY_SEPARATOR . 'LoaderTest_setUp.json'));
34
	}
35
36
	/**
37
	 * testConcat
38
	 *
39
	 * @since 3.0.0
40
	 *
41
	 * @param array $registryArray
42
	 * @param array $collectionArray
43
	 * @param array $expectArray
44
	 *
45
	 * @dataProvider providerAutoloader
46
	 */
47
48
	public function testConcat(array $registryArray = [], array $collectionArray = [], array $expectArray = []) : void
49
	{
50
		/* setup */
51
52
		$optionArray =
53
		[
54
			'directory' => Stream::url('root' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'styles'),
55
			'extension' => 'css',
56
			'attribute' => 'href',
57
			'lifetime' => 86400
58
		];
59
		$this->_registry->init($registryArray);
60
		$loader = new Asset\Loader($this->_registry);
61
		$loader
62
			->init($collectionArray)
63
			->concat($optionArray)
64
			->concat($optionArray);
65
66
		/* actual */
67
68
		$actualArray = $loader->getCollectionArray();
69
70
		/* compare */
71
72
		$this->assertEquals($expectArray, $actualArray);
73
	}
74
75
	/**
76
	 * testRewrite
77
	 *
78
	 * @since 3.0.0
79
	 *
80
	 * @param array $collectionArray
81
	 * @param array $rewriteArray
82
	 * @param string $expect
83
	 *
84
	 * @dataProvider providerAutoloader
85
	 */
86
87
	public function testRewrite(array $collectionArray = [], array $rewriteArray = [], string $expect = null) : void
88
	{
89
		/* setup */
90
91
		$optionArray =
92
		[
93
			'directory' => Stream::url('root' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'styles'),
94
			'extension' => 'css',
95
			'attribute' => 'href',
96
			'lifetime' => 86400
97
		];
98
		$loader = new Asset\Loader(Registry::getInstance());
99
		$loader
100
			->init($collectionArray)
101
			->concat($optionArray, $rewriteArray)
102
			->concat($optionArray, $rewriteArray);
103
104
		/* actual */
105
106
		$file = $loader->getCollectionArray()['bundle']['href'];
107
		$actual = file_get_contents($file);
108
109
		/* compare */
110
111
		$this->assertEquals($expect, $actual);
112
	}
113
}
114