SPDXLicenseIdentifierTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Composer\Test\Util;
  3. use Composer\Test\TestCase;
  4. use Composer\Util\SPDXLicenseIdentifier;
  5. class SPDXLicenseIdentifierTest extends TestCase
  6. {
  7. public static function provideValidLicenses()
  8. {
  9. $valid = array_merge(
  10. array(
  11. "MIT",
  12. "NONE",
  13. "NOASSERTION",
  14. "LicenseRef-3",
  15. array("LGPL-2.0", "GPL-3.0+"),
  16. "(LGPL-2.0 or GPL-3.0+)",
  17. "(EUDatagrid and GPL-3.0+)",
  18. ),
  19. json_decode(file_get_contents(__DIR__ . '/../../../../res/spdx-identifier.json'))
  20. );
  21. foreach ($valid as &$r) {
  22. $r = array($r);
  23. }
  24. return $valid;
  25. }
  26. public static function provideInvalidLicenses()
  27. {
  28. return array(
  29. array(NULL),
  30. array(""),
  31. array("The system pwns you"),
  32. array("()"),
  33. array("(MIT)"),
  34. array("MIT NONE"),
  35. array("MIT (MIT and MIT)"),
  36. array("(MIT and MIT) MIT"),
  37. array(array("LGPL-2.0", "The system pwns you")),
  38. array("and GPL-3.0+"),
  39. array("EUDatagrid and GPL-3.0+"),
  40. array("(GPL-3.0 and GPL-2.0 or GPL-3.0+)"),
  41. array("(EUDatagrid and GPL-3.0+ and )"),
  42. array("(EUDatagrid xor GPL-3.0+)"),
  43. array("(MIT Or MIT)"),
  44. array("(NONE or MIT)"),
  45. array("(NOASSERTION or MIT)"),
  46. );
  47. }
  48. /**
  49. * @dataProvider provideValidLicenses
  50. * @param $license
  51. */
  52. public function testConstructor($license)
  53. {
  54. $identifier = new SPDXLicenseIdentifier($license);
  55. $this->assertInstanceOf('Composer\Util\SPDXLicenseIdentifier', $identifier);
  56. }
  57. /**
  58. * @dataProvider provideInvalidLicenses
  59. * @expectedException InvalidArgumentException
  60. * @param string|array $invalidLicense
  61. */
  62. public function testInvalidLicenses($invalidLicense)
  63. {
  64. $identifier = new SPDXLicenseIdentifier($invalidLicense);
  65. }
  66. public function testGetLicense()
  67. {
  68. $license = new SPDXLicenseIdentifier('NONE');
  69. $string = $license->getLicense();
  70. $this->assertInternalType('string', $string);
  71. $string = (string)$license;
  72. $this->assertInternalType('string', $string);
  73. }
  74. }