GitlabRepositoryManagerTest::tearDownAfterClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace CompoLab\Tests\Application;
4
5
use CompoLab\Application\GitlabRepositoryManager;
6
use CompoLab\Domain\Repository;
7
use CompoLab\Domain\ValueObject\Dir;
8
use CompoLab\Domain\ValueObject\Url;
9
use CompoLab\Infrastructure\JsonRepositoryCache;
10
use CompoLab\Tests\Utils\DummyHttpClient;
11
use Gitlab\Client;
12
use Gitlab\HttpClient\Builder;
13
use Gitlab\Model\Branch;
14
use Gitlab\Model\Project;
15
use Gitlab\Model\Tag;
16
use PHPUnit\Framework\TestCase;
17
18
final class GitlabRepositoryManagerTest extends TestCase
19
{
20
    /** @var JsonRepositoryCache */
21
    private static $cache;
22
23
    /** @var GitlabRepositoryManager */
24
    private static $manager;
25
26
    public static function setUpBeforeClass()
27
    {
28
        self::$cache = new JsonRepositoryCache(new Repository(
29
            new Url('https://composer.my-website.com'),
30
            new Dir(__DIR__ . '/../../cache')
31
        ));
32
33
        self::$manager = new GitlabRepositoryManager(self::$cache);
34
    }
35
36
    public function testAddProject()
37
    {
38
        $client = new Client(new Builder(
39
            new DummyHttpClient(file_get_contents(__DIR__ . '/../../data/composer.json'))
40
        ));
41
42
        $project = Project::fromArray($client, [
43
            'id' => 1,
44
            'name' => 'project',
45
            'description' => null,
46
            'web_url' => 'https://composer.my-website.com/vendor/project',
47
            'avatar_url' => null,
48
            'git_ssh_url' => '[email protected]:project.git',
49
            'git_http_url' => 'https://composer.my-website.com/vendor/project.git',
50
            'namespace' => 'default',
51
            'visibility_level' => 0,
52
            'path_with_namespace' => 'vendor/project',
53
            'default_branch' => 'master',
54
            'ci_config_path' => null,
55
            'homepage' => 'https://composer.my-website.com/vendor/project',
56
            'url' => '[email protected]:project.git',
57
            'ssh_url' => '[email protected]:project.git',
58
            'http_url' => 'https://composer.my-website.com/vendor/project.git',
59
            'ssh_url_to_repo' => 'https://composer.my-website.com/vendor/project.git',
60
        ]);
61
62
        $branch = Branch::fromArray($client, $project, [
63
            'name' => '2.0',
64
            'commit' => [
65
                'id' => '6a6e0ea9479c821d4b5728c0d3c9840e71085e82',
66
            ],
67
        ]);
68
69
        $tag = Tag::fromArray($client, $project, [
70
            'name' => 'v1.2.3',
71
            'commit' => [
72
                'id' => '6a6e0ea9479c821d4b5728c0d3c9840e71085e82',
73
            ],
74
        ]);
75
76
        self::$manager->registerBranch($branch);
77
        self::$manager->registerTag($tag);
78
        self::$manager->save();
79
        self::assertEquals(2, count(self::$cache));
80
81
        self::$manager->deleteTag($tag);
82
        self::$manager->save();
83
        self::assertEquals(1, count(self::$cache));
84
    }
85
86
    public static function tearDownAfterClass()
87
    {
88
        // Clean packages for future tests
89
        file_put_contents(__DIR__ . '/../../cache/packages.json', '{}');
90
    }
91
}
92