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\File; |
9
|
|
|
use CompoLab\Domain\ValueObject\Url; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
final class RepositoryTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
public function testBuildFromPath() |
15
|
|
|
{ |
16
|
|
|
$repository = Repository::buildFromPath( |
17
|
|
|
new Url('https://composer.my-website.com'), |
18
|
|
|
new Dir(__DIR__ . '/../../cache'), |
19
|
|
|
__DIR__ . '/../../data/packages.json' |
20
|
|
|
); |
21
|
|
|
|
22
|
|
|
$this->assertInstanceOf(Url::class, $repository->getBaseUrl()); |
23
|
|
|
$this->assertEquals('https://composer.my-website.com/foobar/baz', (string) $repository->getUrl('/foobar/baz')); |
24
|
|
|
$this->assertEquals('https://composer.my-website.com/packages.json', (string) $repository->getIndexUrl()); |
25
|
|
|
|
26
|
|
|
$this->assertInstanceOf(Dir::class, $repository->getCachePath()); |
27
|
|
|
$this->assertInstanceOf(File::class, $repository->getIndexFile()); |
28
|
|
|
|
29
|
|
|
$this->assertEquals(4, count($repository)); |
30
|
|
|
$this->assertInstanceOf(Package::class, $repository->getPackages()[0]); |
31
|
|
|
|
32
|
|
|
$json = json_decode(file_get_contents(__DIR__ . '/../../data/composer.json'), true); |
33
|
|
|
$package = Package::buildFromArray(__DIR__ . '/../../cache', array_merge($json, [ |
34
|
|
|
'version' => 'dev-feature', |
35
|
|
|
'source' => [ |
36
|
|
|
'type' => 'git', |
37
|
|
|
'url' => '[email protected]:vendor/project.git', |
38
|
|
|
'reference' => '8c7g1iu6249c789d4b6365c0d4c1205d36498i64', |
39
|
|
|
], |
40
|
|
|
])); |
41
|
|
|
|
42
|
|
|
$repository->addPackage($package); |
43
|
|
|
$this->assertEquals(5, count($repository)); |
44
|
|
|
|
45
|
|
|
$repository->removePackage($package); |
46
|
|
|
$this->assertEquals(4, count($repository)); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|