forked from php-censor/php-censor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildServiceTest.php
More file actions
192 lines (160 loc) · 6.58 KB
/
Copy pathBuildServiceTest.php
File metadata and controls
192 lines (160 loc) · 6.58 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
namespace Tests\PHPCensor\Service;
use PHPCensor\Model\Build;
use PHPCensor\Service\BuildService;
/**
* Unit tests for the ProjectService class.
*
* @author Dan Cryer <dan@block8.co.uk>
*/
class BuildServiceTest extends \PHPUnit\Framework\TestCase
{
/**
* @var BuildService $testedService
*/
protected $testedService;
/**
* @var \ $mockBuildStore
*/
protected $mockBuildStore;
/**
* @var \ $mockEnvironmentStore
*/
protected $mockEnvironmentStore;
public function setUp()
{
$this->mockBuildStore = $this->getMockBuilder('PHPCensor\Store\BuildStore')->getMock();
$this->mockBuildStore
->expects($this->any())
->method('save')
->will($this->returnArgument(0));
$this->mockEnvironmentStore = $this->getMockBuilder('PHPCensor\Store\EnvironmentStore')->getMock();
$this->mockEnvironmentStore
->expects($this->any())
->method('getByProjectId')
->will($this->returnValue(['items' => [], 'count' => 0]));
$mockProjectStore = $this->getMockBuilder('PHPCensor\Store\ProjectStore')->getMock();
$this->testedService = new BuildService($this->mockBuildStore, $mockProjectStore);
}
public function testExecute_CreateBasicBuild()
{
$project = $this
->getMockBuilder('PHPCensor\Model\Project')
->setMethods(['getEnvironmentStore'])
->getMock();
$project->expects($this->any())
->method('getEnvironmentStore')
->will($this->returnValue($this->mockEnvironmentStore));
$project->setType('github');
$project->setId(101);
$returnValue = $this->testedService->createBuild($project, null);
self::assertEquals(101, $returnValue->getProjectId());
self::assertEquals(Build::STATUS_PENDING, $returnValue->getStatus());
self::assertNull($returnValue->getStartDate());
self::assertNull($returnValue->getFinishDate());
self::assertNull($returnValue->getLog());
self::assertEquals(null, $returnValue->getCommitMessage());
self::assertNull($returnValue->getCommitterEmail());
self::assertEquals(['branches' => []], $returnValue->getExtra());
self::assertEquals('master', $returnValue->getBranch());
self::assertInstanceOf('DateTime', $returnValue->getCreateDate());
self::assertEquals('', $returnValue->getCommitId());
self::assertEquals(Build::SOURCE_UNKNOWN, $returnValue->getSource());
}
public function testExecute_CreateBuildWithOptions()
{
$project = $this
->getMockBuilder('PHPCensor\Model\Project')
->setMethods(['getEnvironmentStore'])
->getMock();
$project->expects($this->any())
->method('getEnvironmentStore')
->will($this->returnValue($this->mockEnvironmentStore));
$project->setType('hg');
$project->setId(101);
$returnValue = $this->testedService->createBuild(
$project,
null,
'123',
'testbranch',
null,
'test@example.com',
'test'
);
self::assertEquals('testbranch', $returnValue->getBranch());
self::assertEquals('123', $returnValue->getCommitId());
self::assertEquals('test', $returnValue->getCommitMessage());
self::assertEquals('test@example.com', $returnValue->getCommitterEmail());
}
public function testExecute_CreateBuildWithExtra()
{
$project = $this
->getMockBuilder('PHPCensor\Model\Project')
->setMethods(['getEnvironmentStore'])
->getMock();
$project->expects($this->any())
->method('getEnvironmentStore')
->will($this->returnValue($this->mockEnvironmentStore));
$project->setType('bitbucket');
$project->setId(101);
$returnValue = $this->testedService->createBuild(
$project,
null,
'',
null,
null,
null,
null,
Build::SOURCE_UNKNOWN,
0,
['item1' => 1001]
);
self::assertEquals(1001, $returnValue->getExtra('item1'));
}
/**
* @throws \Exception
*/
public function testExecute_CreateDuplicateBuild()
{
$build = new Build();
$build->setId(1);
$build->setProjectId(101);
$build->setCommitId('abcde');
$build->setStatusFailed();
$build->setLog('Test');
$build->setBranch('example_branch');
$build->setStartDate(new \DateTime());
$build->setFinishDate(new \DateTime());
$build->setCommitMessage('test');
$build->setCommitterEmail('test@example.com');
$build->setExtra(['item1' => 1001]);
$build->setSource(Build::SOURCE_MANUAL_CONSOLE);
$returnValue = $this->testedService->createDuplicateBuild($build, Build::SOURCE_MANUAL_REBUILD_CONSOLE);
self::assertNotEquals($build->getId(), $returnValue->getId());
self::assertEquals($build->getProjectId(), $returnValue->getProjectId());
self::assertEquals($build->getCommitId(), $returnValue->getCommitId());
self::assertNotEquals($build->getStatus(), $returnValue->getStatus());
self::assertEquals(Build::STATUS_PENDING, $returnValue->getStatus());
self::assertNull($returnValue->getLog());
self::assertEquals($build->getBranch(), $returnValue->getBranch());
self::assertNotEquals($build->getCreateDate(), $returnValue->getCreateDate());
self::assertNull($returnValue->getStartDate());
self::assertNull($returnValue->getFinishDate());
self::assertEquals('test', $returnValue->getCommitMessage());
self::assertEquals('test@example.com', $returnValue->getCommitterEmail());
self::assertEquals($build->getExtra('item1'), $returnValue->getExtra('item1'));
self::assertEquals(Build::SOURCE_MANUAL_REBUILD_CONSOLE, $returnValue->getSource());
self::assertEquals($build->getId(), $returnValue->getParentId());
}
public function testExecute_DeleteBuild()
{
$store = $this->getMockBuilder('PHPCensor\Store\BuildStore')->getMock();
$store->expects($this->once())
->method('delete')
->will($this->returnValue(true));
$mockProjectStore = $this->getMockBuilder('PHPCensor\Store\ProjectStore')->getMock();
$service = new BuildService($store, $mockProjectStore);
$build = new Build();
self::assertEquals(true, $service->deleteBuild($build));
}
}