-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathBuildFactoryTest.php
More file actions
169 lines (136 loc) · 4.93 KB
/
Copy pathBuildFactoryTest.php
File metadata and controls
169 lines (136 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
declare(strict_types=1);
namespace Tests\PHPCensor;
use PHPCensor\BuildFactory;
use PHPCensor\Common\Application\ConfigurationInterface;
use PHPCensor\Configuration;
use PHPCensor\DatabaseManager;
use PHPCensor\Model\Build;
use PHPCensor\Model\Project;
use PHPCensor\Store\BuildStore;
use PHPCensor\Store\ProjectStore;
use PHPCensor\StoreRegistry;
use PHPUnit\Framework\TestCase;
use PHPCensor\Model\Build\LocalBuild;
use PHPCensor\Model\Build\GitBuild;
use PHPCensor\Model\Build\GitlabBuild;
use PHPCensor\Model\Build\GithubBuild;
use PHPCensor\Model\Build\BitbucketBuild;
use PHPCensor\Model\Build\GogsBuild;
use PHPCensor\Model\Build\HgBuild;
use PHPCensor\Model\Build\BitbucketHgBuild;
use PHPCensor\Model\Build\BitbucketServerBuild;
use PHPCensor\Model\Build\SvnBuild;
class BuildFactoryTest extends TestCase
{
private ConfigurationInterface $configuration;
private DatabaseManager $databaseManager;
private StoreRegistry $storeRegistry;
private ProjectStore $projectStore;
private BuildFactory $factory;
protected function setUp(): void
{
parent::setUp();
$this->configuration = new Configuration('');
$this->databaseManager = $this
->getMockBuilder(DatabaseManager::class)
->setConstructorArgs([$this->configuration])
->getMock();
$this->storeRegistry = $this
->getMockBuilder(StoreRegistry::class)
->setConstructorArgs([$this->databaseManager])
->getMock();
$this->projectStore = $this
->getMockBuilder(ProjectStore::class)
->setConstructorArgs([$this->databaseManager, $this->storeRegistry])
->getMock();
$this->factory = new BuildFactory($this->configuration, $this->storeRegistry);
}
protected function tearDown(): void
{
parent::tearDown();
}
public function testConstruct(): void
{
self::assertInstanceOf(BuildFactory::class, $this->factory);
}
public function testGetBuildDefault(): void
{
$this->storeRegistry
->method('get')
->with('Project')
->willReturn($this->projectStore);
$rawBuild = new Build($this->storeRegistry, []);
$build = $this->factory->getBuild($rawBuild);
self::assertInstanceOf(Build::class, $build);
}
/**
* @dataProvider buildTypesProvider
*/
public function testGetBuild(string $buildType, string $expectedBuildClass): void
{
$this->storeRegistry
->method('get')
->with('Project')
->willReturn($this->projectStore);
$rawBuild = new Build($this->storeRegistry, ['project_id' => 10]);
$this->projectStore
->method('getById')
->with(10)
->willReturn(new Project($this->storeRegistry, ['type' => $buildType]));
$build = $this->factory->getBuild($rawBuild);
self::assertInstanceOf($expectedBuildClass, $build);
}
public function buildTypesProvider(): array
{
return [
[Project::TYPE_LOCAL, LocalBuild::class],
[Project::TYPE_GIT, GitBuild::class],
[Project::TYPE_GITHUB, GithubBuild::class],
[Project::TYPE_BITBUCKET, BitbucketBuild::class],
[Project::TYPE_GITLAB, GitlabBuild::class],
[Project::TYPE_GOGS, GogsBuild::class],
[Project::TYPE_HG, HgBuild::class],
[Project::TYPE_BITBUCKET_HG, BitbucketHgBuild::class],
[Project::TYPE_BITBUCKET_SERVER, BitbucketServerBuild::class],
[Project::TYPE_SVN, SvnBuild::class],
['unknown', Build::class],
];
}
public function testGetBuildById(): void
{
$rawBuild = new Build($this->storeRegistry, ['project_id' => 10]);
$buildStore = $this
->getMockBuilder(BuildStore::class)
->setConstructorArgs([$this->databaseManager, $this->storeRegistry])
->getMock();
$build = new Build($this->storeRegistry, ['id' => 222]);
$buildStore
->method('getById')
->with(20)
->willReturn($build);
$this->storeRegistry
->method('get')
->with('Build')
->willReturn($buildStore);
$buildByFactory = $this->factory->getBuildById(20);
self::assertEquals($build, $buildByFactory);
}
public function testGetBuildByIdWithEmptyBuild(): void
{
$buildStore = $this
->getMockBuilder(BuildStore::class)
->setConstructorArgs([$this->databaseManager, $this->storeRegistry])
->getMock();
$buildStore
->method('getById')
->with(20)
->willReturn(null);
$this->storeRegistry
->method('get')
->with('Build')
->willReturn($buildStore);
$buildByFactory = $this->factory->getBuildById(20);
self::assertEquals(null, $buildByFactory);
}
}