1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace TheCodingMachine\Discovery; |
5
|
|
|
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
|
8
|
|
|
class AssetTypeTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
public function testAssetTypeName() |
11
|
|
|
{ |
12
|
|
|
$assetType = new AssetType('type'); |
13
|
|
|
$this->assertSame('type', $assetType->getName()); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function testAssetTypeAdd() |
17
|
|
|
{ |
18
|
|
|
$operation1 = new AssetOperation(AssetOperation::ADD, new Asset('a', 'package_a', 'dir_a', 0, [])); |
19
|
|
|
$operation2 = new AssetOperation(AssetOperation::ADD, new Asset('b', 'package_b', 'dir_b', -0.5, [])); |
20
|
|
|
$operation3 = new AssetOperation(AssetOperation::ADD, new Asset('c', 'package_c', 'dir_c', 0.5, [])); |
21
|
|
|
$operation4 = new AssetOperation(AssetOperation::ADD, new Asset('d', 'package_d', 'dir_d', -0.5, [])); |
22
|
|
|
$operation5 = new AssetOperation(AssetOperation::ADD, new Asset('e', 'package_e', 'dir_e', 0, [])); |
23
|
|
|
|
24
|
|
|
$assetType = new AssetType('type'); |
25
|
|
|
$assetType->addAssetOperation($operation1); |
26
|
|
|
$assetType->addAssetOperation($operation2); |
27
|
|
|
$assetType->addAssetOperation($operation3); |
28
|
|
|
$assetType->addAssetOperation($operation4); |
29
|
|
|
$assetType->addAssetOperation($operation5); |
30
|
|
|
|
31
|
|
|
$assets = $assetType->getAssets(); |
32
|
|
|
$this->assertCount(5, $assets); |
33
|
|
|
$this->assertSame('c', $assets[0]->getValue()); |
34
|
|
|
$this->assertSame('a', $assets[1]->getValue()); |
35
|
|
|
$this->assertSame('e', $assets[2]->getValue()); |
36
|
|
|
$this->assertSame('b', $assets[3]->getValue()); |
37
|
|
|
$this->assertSame('d', $assets[4]->getValue()); |
38
|
|
|
|
39
|
|
|
// Let's test again to test the "caching" of the sort. |
40
|
|
|
$assets = $assetType->getAssets(); |
41
|
|
|
$this->assertCount(5, $assets); |
42
|
|
|
|
43
|
|
|
$assetValues = $assetType->getValues(); |
44
|
|
|
$this->assertSame(['c', 'a', 'e', 'b', 'd'], $assetValues); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testAssetTypeJson() |
48
|
|
|
{ |
49
|
|
|
$operation1 = new AssetOperation(AssetOperation::ADD, new Asset('a', 'package_a', 'dir_a', 0, [])); |
50
|
|
|
|
51
|
|
|
$assetType = new AssetType('type'); |
52
|
|
|
$assetType->addAssetOperation($operation1); |
53
|
|
|
|
54
|
|
|
$array = json_decode(json_encode($assetType), true); |
55
|
|
|
$this->assertSame([ |
56
|
|
|
[ |
57
|
|
|
'value' => 'a', |
58
|
|
|
'package' => 'package_a', |
59
|
|
|
'packageDir' => 'dir_a', |
60
|
|
|
'priority' => 0, |
61
|
|
|
'metadata' => [], |
62
|
|
|
] |
63
|
|
|
], $array); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testAssetTypeRemove() |
67
|
|
|
{ |
68
|
|
|
$operation1 = new AssetOperation(AssetOperation::ADD, new Asset('a', 'package_a', 'dir_a', 0, [])); |
69
|
|
|
$operation2 = new AssetOperation(AssetOperation::ADD, new Asset('b', 'package_b', 'dir_b', -0.5, [])); |
70
|
|
|
$operation3 = new AssetOperation(AssetOperation::REMOVE, new Asset('a', 'package_b', 'dir_b', -0.5, [])); |
71
|
|
|
|
72
|
|
|
$assetType = new AssetType('type'); |
73
|
|
|
$assetType->addAssetOperation($operation1); |
74
|
|
|
$assetType->addAssetOperation($operation2); |
75
|
|
|
$assetType->addAssetOperation($operation3); |
76
|
|
|
|
77
|
|
|
$assets = $assetType->getAssets(); |
78
|
|
|
$this->assertCount(1, $assets); |
79
|
|
|
$this->assertSame('b', $assets[0]->getValue()); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|