forked from php-censor/php-censor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuilderTest.php
More file actions
191 lines (149 loc) · 5.18 KB
/
Copy pathBuilderTest.php
File metadata and controls
191 lines (149 loc) · 5.18 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
<?php
declare(strict_types=1);
namespace Tests\PHPCensor;
use Monolog\Logger;
use PHPCensor\Builder;
use PHPCensor\Configuration;
use PHPCensor\Common\Application\ConfigurationInterface;
use PHPCensor\DatabaseManager;
use PHPCensor\Helper\CommandExecutor;
use PHPCensor\Logging\BuildLogger;
use PHPCensor\Model\Build;
use PHPCensor\Model\Project;
use PHPCensor\Store\BuildErrorWriter;
use PHPCensor\StoreRegistry;
use PHPUnit\Framework\TestCase;
use Psr\Log\LogLevel;
class TestBuilder extends Builder
{
public function getCommandExecutor(): CommandExecutor
{
return $this->commandExecutor;
}
}
class BuilderTest extends TestCase
{
private BuildLogger $buildLogger;
private Builder $builder;
protected function setUp(): void
{
parent::setUp();
$configuration = new Configuration('');
$databaseManager = $this
->getMockBuilder(DatabaseManager::class)
->setConstructorArgs([$configuration])
->getMock();
$storeRegistry = new StoreRegistry($databaseManager);
$project = $this
->getMockBuilder(Project::class)
->setConstructorArgs([$storeRegistry])
->getMock();
$build = $this
->getMockBuilder(Build::class)
->setConstructorArgs([$storeRegistry])
->getMock();
$build
->method('getId')
->willReturn(10);
$build
->method('getProjectId')
->willReturn(20);
$build
->method('getBranch')
->willReturn('master');
$build
->method('getProject')
->willReturn($project);
$logger = $this->getMockBuilder(Logger::class)
->setConstructorArgs(['Test'])
->getMock();
$this->buildLogger = $this->getMockBuilder(BuildLogger::class)
->setConstructorArgs([$logger, $build])
->getMock();
$this->builder = $this->getMockBuilder(TestBuilder::class)
->setConstructorArgs([$configuration, $databaseManager, $storeRegistry, $build, $this->buildLogger])
->onlyMethods(['executeCommand'])
->getMock();
}
public function testConstruct(): void
{
self::assertInstanceOf(Builder::class, $this->builder);
}
public function testGetBuildLogger(): void
{
self::assertInstanceOf(BuildLogger::class, $this->builder->getBuildLogger());
}
public function testGetConfiguration(): void
{
self::assertInstanceOf(ConfigurationInterface::class, $this->builder->getConfiguration());
self::assertInstanceOf(Configuration::class, $this->builder->getConfiguration());
}
public function testGetCurrentStage(): void
{
self::assertNull($this->builder->getCurrentStage());
$this->builder->execute();
self::assertEquals(Build::STAGE_COMPLETE, $this->builder->getCurrentStage());
}
public function testGetBuildErrorWriter(): void
{
self::assertInstanceOf(BuildErrorWriter::class, $this->builder->getBuildErrorWriter());
}
public function testLogExecOutput(): void
{
self::assertTrue($this->builder->getCommandExecutor()->logExecOutput);
$this->builder->logExecOutput();
self::assertTrue($this->builder->getCommandExecutor()->logExecOutput);
$this->builder->logExecOutput(true);
self::assertTrue($this->builder->getCommandExecutor()->logExecOutput);
$this->builder->logExecOutput(false);
self::assertFalse($this->builder->getCommandExecutor()->logExecOutput);
}
public function testGetConfig(): void
{
self::assertEquals([], $this->builder->getConfig());
self::assertEquals(null, $this->builder->getConfig('test'));
$this->builder->setConfig(['test' => 'test-value']);
self::assertEquals(['test' => 'test-value'], $this->builder->getConfig());
self::assertEquals('test-value', $this->builder->getConfig('test'));
}
public function testLogDebug(): void
{
$this->buildLogger
->expects($this->once())
->method('logDebug')
->with('Debug message');
$this->builder->logDebug('Debug message');
}
public function testLogSuccess(): void
{
$this->buildLogger
->expects($this->once())
->method('logSuccess')
->with('Success message');
$this->builder->logSuccess('Success message');
}
public function testLogWarning(): void
{
$this->buildLogger
->expects($this->once())
->method('logWarning')
->with('Warning message');
$this->builder->logWarning('Warning message');
}
public function testLogFailure(): void
{
$this->buildLogger
->expects($this->once())
->method('logFailure')
->with('Failure message', null);
$this->builder->logFailure('Failure message');
}
public function testLog(): void
{
$this->buildLogger
->expects($this->once())
->method('log')
->with('Log message', LogLevel::INFO, []);
$this->builder->log('Log message');
}
}