1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CompoLab\Tests\Domain; |
4
|
|
|
|
5
|
|
|
use CompoLab\Domain\Package; |
6
|
|
|
use CompoLab\Domain\Repository; |
7
|
|
|
use CompoLab\Domain\ValueObject\Dir; |
8
|
|
|
use CompoLab\Domain\ValueObject\Url; |
9
|
|
|
use CompoLab\Domain\ValueObject\Version; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
final class PackageTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
private static $repository; |
15
|
|
|
|
16
|
|
|
public static function setUpBeforeClass() |
17
|
|
|
{ |
18
|
|
|
self::$repository = new Repository( |
19
|
|
|
new Url('https://composer.my-website.com'), |
20
|
|
|
new Dir(__DIR__ . '/../../cache') |
21
|
|
|
); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testBuildFromArrayWithoutAsset() |
25
|
|
|
{ |
26
|
|
|
$this->expectException(\RuntimeException::class); |
27
|
|
|
|
28
|
|
|
Package::buildFromArray(__DIR__ . '/../../cache', [ |
29
|
|
|
'name' => 'vendor/project', |
30
|
|
|
'version' => 'dev-master', |
31
|
|
|
]); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testBuildFromArray() |
35
|
|
|
{ |
36
|
|
|
$json = json_decode(file_get_contents(__DIR__ . '/../../data/composer.json'), true); |
37
|
|
|
|
38
|
|
|
$package = Package::buildFromArray(__DIR__ . '/../../cache', array_merge($json, [ |
39
|
|
|
'version' => 'dev-master', |
40
|
|
|
'source' => [ |
41
|
|
|
'type' => 'git', |
42
|
|
|
'url' => '[email protected]:vendor/project.git', |
43
|
|
|
'reference' => '6a6e0ea9479c821d4b5728c0d3c9840e71085e82', |
44
|
|
|
], |
45
|
|
|
])); |
46
|
|
|
|
47
|
|
|
$this->assertEquals('vendor/project', $package->getName()); |
48
|
|
|
$this->assertInstanceOf(Version::class, $package->getVersion()); |
49
|
|
|
|
50
|
|
|
$packageArray = json_decode(json_encode($package), true); |
51
|
|
|
|
52
|
|
|
$this->assertEquals('[email protected]:vendor/project.git', $packageArray['source']['url']); |
53
|
|
|
|
54
|
|
|
$this->assertArrayHasKey('name', $packageArray); |
55
|
|
|
$this->assertArrayHasKey('version', $packageArray); |
56
|
|
|
$this->assertArrayHasKey('source', $packageArray); |
57
|
|
|
$this->assertArrayHasKey('minimum-stability', $packageArray); |
58
|
|
|
$this->assertArrayHasKey('require', $packageArray); |
59
|
|
|
$this->assertArrayHasKey('require-dev', $packageArray); |
60
|
|
|
$this->assertArrayHasKey('autoload', $packageArray); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|