mirror of
https://github.com/composer/composer
synced 2025-05-09 00:22:53 +00:00
Fix CS & simplify code
This commit is contained in:
parent
4cab4b46e4
commit
fd38971777
4 changed files with 45 additions and 99 deletions
81
tests/Composer/Test/Util/SpdxLicenseIdentifierTest.php
Normal file
81
tests/Composer/Test/Util/SpdxLicenseIdentifierTest.php
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
namespace Composer\Test\Util;
|
||||
|
||||
use Composer\Test\TestCase;
|
||||
use Composer\Util\SpdxLicenseIdentifier;
|
||||
|
||||
class SpdxLicenseIdentifierTest extends TestCase
|
||||
{
|
||||
public static function provideValidLicenses()
|
||||
{
|
||||
$valid = array_merge(
|
||||
array(
|
||||
"MIT",
|
||||
"NONE",
|
||||
"NOASSERTION",
|
||||
"LicenseRef-3",
|
||||
array("LGPL-2.0", "GPL-3.0+"),
|
||||
"(LGPL-2.0 or GPL-3.0+)",
|
||||
"(EUDatagrid and GPL-3.0+)",
|
||||
),
|
||||
json_decode(file_get_contents(__DIR__ . '/../../../../res/spdx-identifier.json'))
|
||||
);
|
||||
|
||||
foreach ($valid as &$r) {
|
||||
$r = array($r);
|
||||
}
|
||||
|
||||
return $valid;
|
||||
}
|
||||
|
||||
public static function provideInvalidLicenses()
|
||||
{
|
||||
return array(
|
||||
array(""),
|
||||
array("The system pwns you"),
|
||||
array("()"),
|
||||
array("(MIT)"),
|
||||
array("MIT NONE"),
|
||||
array("MIT (MIT and MIT)"),
|
||||
array("(MIT and MIT) MIT"),
|
||||
array(array("LGPL-2.0", "The system pwns you")),
|
||||
array("and GPL-3.0+"),
|
||||
array("EUDatagrid and GPL-3.0+"),
|
||||
array("(GPL-3.0 and GPL-2.0 or GPL-3.0+)"),
|
||||
array("(EUDatagrid and GPL-3.0+ and )"),
|
||||
array("(EUDatagrid xor GPL-3.0+)"),
|
||||
array("(MIT Or MIT)"),
|
||||
array("(NONE or MIT)"),
|
||||
array("(NOASSERTION or MIT)"),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideValidLicenses
|
||||
* @param $license
|
||||
*/
|
||||
public function testValidate($license)
|
||||
{
|
||||
$validator = new SpdxLicenseIdentifier();
|
||||
$this->assertTrue($validator->validate($license));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInvalidLicenses
|
||||
* @param string|array $invalidLicense
|
||||
*/
|
||||
public function testInvalidLicenses($invalidLicense)
|
||||
{
|
||||
$validator = new SpdxLicenseIdentifier();
|
||||
$this->assertFalse($validator->validate($invalidLicense));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidArgument()
|
||||
{
|
||||
$validator = new SpdxLicenseIdentifier();
|
||||
$validator->validate(null);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue