Completed
Push — master ( 1da492...320203 )
by Henry
07:00
created

tests/unit/Asset/LoaderTest.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\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'));
0 ignored issues
show
The method getJSON() does not seem to exist on object<Redaxscript\Tests\Asset\LoaderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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