41 private $assertCountBefore;
47 protected function setUp() : void
49 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
50 $this->
dbManager = M::mock(DbManager::class);
51 $this->licenseDao = M::mock(LicenseDao::class);
52 $this->compatibilityDao = M::mock(CompatibilityDao::class);
53 $this->
dbManager->shouldReceive(
'booleanFromDb')
54 ->andReturnUsing(
function ($value) {
55 return $value ===
't';
58 $this->
dbManager, M::mock(UserDao::class), $this->licenseDao,
59 $this->compatibilityDao);
68 $this->addToAssertionCount(
69 \Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore);
80 $this->
dbManager->shouldReceive(
'getSingleRow')
81 ->andReturn([
"compatibility" => $compatibility,
"comment" => $comment]);
95 $this->compatibilityDao->shouldReceive(
'updateRuleFromArray')
96 ->once()->with([4 => [
"result" =>
false]])->andReturn(1);
98 $log = Reflectory::invokeObjectsMethodnameWith($this->yamlImport,
100 [[
"compatibility" =>
"false",
"comment" =>
"A rule"], 4]);
102 $this->assertEquals(
"updated compatibility", $log);
116 $this->compatibilityDao->shouldReceive(
'updateRuleFromArray')
117 ->once()->with([4 => [
"comment" =>
"An updated rule"]])->andReturn(1);
119 $log = Reflectory::invokeObjectsMethodnameWith($this->yamlImport,
121 [[
"compatibility" =>
"true",
"comment" =>
"An updated rule"], 4]);
123 $this->assertEquals(
"updated comment", $log);
136 $this->compatibilityDao->shouldReceive(
'updateRuleFromArray')
137 ->once()->with([4 => [
"result" =>
true,
138 "comment" =>
"An updated rule"]])->andReturn(1);
140 $log = Reflectory::invokeObjectsMethodnameWith($this->yamlImport,
142 [[
"compatibility" =>
"true",
"comment" =>
"An updated rule"], 4]);
144 $this->assertEquals(
"updated compatibility, updated comment", $log);
158 $this->compatibilityDao->shouldNotReceive(
'updateRuleFromArray');
160 $log = Reflectory::invokeObjectsMethodnameWith($this->yamlImport,
162 [[
"compatibility" =>
"true",
"comment" =>
"A rule"], 4]);
164 $this->assertEmpty($log);
176 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
177 ->with(
"NotALicense",
null)->andReturn(
null);
178 $this->expectException(\UnexpectedValueException::class);
180 Reflectory::invokeObjectsMethodnameWith($this->yamlImport,
'handleYaml',
182 "firstname" =>
"NotALicense",
183 "secondname" =>
null,
185 "secondtype" =>
"Strong Copyleft",
186 "compatibility" =>
"true",
187 "comment" =>
"A rule"
200 $this->expectException(\UnexpectedValueException::class);
202 Reflectory::invokeObjectsMethodnameWith($this->yamlImport,
'handleYaml',
204 "firstname" =>
"MIT",
205 "secondname" =>
null,
207 "secondtype" =>
"Strong Copyleft",
208 "comment" =>
"A rule"
221 $firstLicense = M::mock(License::class);
222 $firstLicense->shouldReceive(
'getId')->andReturn(306);
223 $secondLicense = M::mock(License::class);
224 $secondLicense->shouldReceive(
'getId')->andReturn(188);
225 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
226 ->with(
"MIT",
null)->andReturn($firstLicense);
227 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
228 ->with(
"GPL-2.0-only",
null)->andReturn($secondLicense);
230 $this->
dbManager->shouldReceive(
'getSingleRow')->andReturn(
false);
231 $this->compatibilityDao->shouldReceive(
'insertRule')
232 ->once()->with(306, 188,
null,
null,
"A rule",
"true")->andReturn(9);
234 $this->assertEquals(9,
235 Reflectory::invokeObjectsMethodnameWith($this->yamlImport,
'handleYaml',
237 "firstname" =>
"MIT",
238 "secondname" =>
"GPL-2.0-only",
240 "secondtype" =>
null,
241 "compatibility" =>
"true",
242 "comment" =>
"A rule"
Test for LicenseCompatibilityRulesYamlImport.
testHandleYamlWithMissingColumn()
Test for LicenseCompatibilityRulesYamlImport::handleYaml() with a missing column.
testHandleYamlWithUnknownLicense()
Test for LicenseCompatibilityRulesYamlImport::handleYaml() with a license unknown to the server.
testUpdateLicenseWithBothChanged()
Test for LicenseCompatibilityRulesYamlImport::updateLicense() when both values changed.
whenStoredRuleIs($compatibility, $comment)
Make the DB return the given rule as the currently stored one.
testUpdateLicenseWithNoChange()
Test for LicenseCompatibilityRulesYamlImport::updateLicense() when nothing changed.
testUpdateLicenseWithOnlyCommentChanged()
Test for LicenseCompatibilityRulesYamlImport::updateLicense() when only the description changed.
setUp()
One time setup for test.
testHandleYamlResolvesLicenseIds()
Test for LicenseCompatibilityRulesYamlImport::handleYaml() resolving the license short names.
testUpdateLicenseWithOnlyCompatibilityChanged()
Test for LicenseCompatibilityRulesYamlImport::updateLicense() when only the compatibility changed.
Import licenses from YAML.
fo_dbManager * dbManager
fo_dbManager object
Utility functions for specific applications.