1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace TheCodingMachine\Discovery; |
5
|
|
|
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
|
8
|
|
|
class DiscoveryTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
public function setUp(): void |
11
|
|
|
{ |
12
|
|
|
parent::setUp(); |
13
|
|
|
// Let's load the autogenerated class for the unit tests. |
14
|
|
|
require_once __DIR__.'/../.discovery/Discovery.php'; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function testSingleton() |
18
|
|
|
{ |
19
|
|
|
$this->assertSame(Discovery::getInstance(), Discovery::getInstance()); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testValues() |
23
|
|
|
{ |
24
|
|
|
$result = Discovery::getInstance()->get('test-asset'); |
25
|
|
|
|
26
|
|
|
$this->assertSame([ 'a1', 'a2', 'b' ], $result); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testEmptyValues() |
30
|
|
|
{ |
31
|
|
|
$result = Discovery::getInstance()->get('not-exist'); |
32
|
|
|
|
33
|
|
|
$this->assertSame([], $result); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testAssetType() |
37
|
|
|
{ |
38
|
|
|
$result = Discovery::getInstance()->getAssetType('test-asset'); |
39
|
|
|
|
40
|
|
|
$this->assertSame('a1', $result->getAssets()[0]->getValue()); |
41
|
|
|
$this->assertSame('package/a', $result->getAssets()[0]->getPackage()); |
42
|
|
|
$this->assertSame('fixtures/package_a/', $result->getAssets()[0]->getPackageDir()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testEmptyAssetType() |
46
|
|
|
{ |
47
|
|
|
$result = Discovery::getInstance()->getAssetType('not-exist'); |
48
|
|
|
|
49
|
|
|
$this->assertSame([], $result->getAssets()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testLocalDiscoveryJsonDetection() |
53
|
|
|
{ |
54
|
|
|
$result = Discovery::getInstance()->getAssetType('local'); |
55
|
|
|
|
56
|
|
|
$this->assertSame('local', $result->getAssets()[0]->getValue()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
} |
60
|
|
|
|