Completed
Push — master ( 8809d0...5c8ee8 )
by Henry
06:08
created

tests/phpunit/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()
31
	{
32
		parent::setUp();
33
		Stream::setup('root', 0777, $this->getJSON('tests' . DIRECTORY_SEPARATOR . 'provider' . DIRECTORY_SEPARATOR . 'Asset' . DIRECTORY_SEPARATOR . 'LoaderTest_setUp.json'));
0 ignored issues
show
It seems like $this->getJSON('tests' ....LoaderTest_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...
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 = [])
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)
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