You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
7.3KB

  1. <?php
  2. /*
  3. * This file is part of the Fxp Composer Asset Plugin package.
  4. *
  5. * (c) François Pluchino <francois.pluchino@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Fxp\Composer\AssetPlugin\Tests\Converter;
  11. use Fxp\Composer\AssetPlugin\Converter\NpmPackageConverter;
  12. use Fxp\Composer\AssetPlugin\Type\AssetTypeInterface;
  13. /**
  14. * Tests of npm package converter.
  15. *
  16. * @author François Pluchino <francois.pluchino@gmail.com>
  17. */
  18. class NpmPackageConverterTest extends AbstractPackageConverterTest
  19. {
  20. protected function setUp()
  21. {
  22. parent::setUp();
  23. /* @var AssetTypeInterface $type */
  24. $type = $this->type;
  25. $this->converter = new NpmPackageConverter($type);
  26. $this->asset = (array) json_decode(file_get_contents(__DIR__.'/../Fixtures/package/npm.json'), true);
  27. }
  28. public function testConvert()
  29. {
  30. $composer = $this->converter->convert($this->asset);
  31. $this->assertArrayHasKey('name', $composer);
  32. $this->assertSame('ASSET/'.$this->asset['name'], $composer['name']);
  33. $this->assertArrayHasKey('type', $composer);
  34. $this->assertSame('ASSET_TYPE', $composer['type']);
  35. $this->assertArrayHasKey('description', $composer);
  36. $this->assertSame($this->asset['description'], $composer['description']);
  37. $this->assertArrayHasKey('version', $composer);
  38. $this->assertSame('1.0.0-pre', $composer['version']);
  39. $this->assertArrayHasKey('keywords', $composer);
  40. $this->assertSame($this->asset['keywords'], $composer['keywords']);
  41. $this->assertArrayHasKey('homepage', $composer);
  42. $this->assertSame($this->asset['homepage'], $composer['homepage']);
  43. $this->assertArrayHasKey('license', $composer);
  44. $this->assertSame($this->asset['license'], $composer['license']);
  45. $this->assertArrayHasKey('authors', $composer);
  46. $this->assertSame(array_merge(array($this->asset['author']), $this->asset['contributors']), $composer['authors']);
  47. $this->assertArrayHasKey('require', $composer);
  48. $this->assertSame(array(
  49. 'ASSET/library1' => '>= 1.0.0',
  50. 'ASSET/library2' => '>= 1.0.0',
  51. 'ASSET/library2-0.9.0' => '0.9.0',
  52. 'ASSET/library3' => '*',
  53. 'ASSET/library4' => '1.2.3',
  54. 'ASSET/library5' => 'dev-default#0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b',
  55. 'ASSET/library6' => 'dev-branch',
  56. 'ASSET/library7' => 'dev-1.2.* || 1.2.*',
  57. 'ASSET/library8' => 'dev-1.2.x || 1.2.x',
  58. 'ASSET/library9' => 'dev-master',
  59. 'ASSET/library10' => '1.0.0',
  60. 'ASSET/library11' => '*',
  61. 'ASSET/library12' => '>=1 <2',
  62. 'ASSET/library13' => '>=1 <2',
  63. 'ASSET/library14' => '*',
  64. 'ASSET/library15' => '*',
  65. 'ASSET/library16' => '>=1 <2',
  66. 'ASSET/test-library17-file' => '*',
  67. 'ASSET/test-library18-file' => '1.2.3',
  68. 'ASSET/test-library19-file' => '*',
  69. 'ASSET/library20' => '1 || 2',
  70. ), $composer['require']);
  71. $this->assertArrayHasKey('require-dev', $composer);
  72. $validDevRequires = $composer['require-dev'];
  73. unset($validDevRequires['ASSET/library3']);
  74. $this->assertSame(array(
  75. 'ASSET/dev-library1' => '>= 1.0.0',
  76. 'ASSET/dev-library2' => '>= 1.0.0',
  77. 'ASSET/dev-library2-0.9.0' => '0.9.0',
  78. ), $validDevRequires);
  79. $this->assertArrayHasKey('bin', $composer);
  80. $this->assertTrue(is_array($composer['bin']));
  81. $this->assertSame($this->asset['bin'], $composer['bin'][0]);
  82. $this->assertArrayHasKey('extra', $composer);
  83. $this->assertArrayHasKey('npm-asset-bugs', $composer['extra']);
  84. $this->assertSame($this->asset['bugs'], $composer['extra']['npm-asset-bugs']);
  85. $this->assertArrayHasKey('npm-asset-files', $composer['extra']);
  86. $this->assertSame($this->asset['files'], $composer['extra']['npm-asset-files']);
  87. $this->assertArrayHasKey('npm-asset-main', $composer['extra']);
  88. $this->assertSame($this->asset['main'], $composer['extra']['npm-asset-main']);
  89. $this->assertArrayHasKey('npm-asset-man', $composer['extra']);
  90. $this->assertSame($this->asset['man'], $composer['extra']['npm-asset-man']);
  91. $this->assertArrayHasKey('npm-asset-directories', $composer['extra']);
  92. $this->assertSame($this->asset['directories'], $composer['extra']['npm-asset-directories']);
  93. $this->assertArrayHasKey('npm-asset-repository', $composer['extra']);
  94. $this->assertSame($this->asset['repository'], $composer['extra']['npm-asset-repository']);
  95. $this->assertArrayHasKey('npm-asset-scripts', $composer['extra']);
  96. $this->assertSame($this->asset['scripts'], $composer['extra']['npm-asset-scripts']);
  97. $this->assertArrayHasKey('npm-asset-config', $composer['extra']);
  98. $this->assertSame($this->asset['config'], $composer['extra']['npm-asset-config']);
  99. $this->assertArrayHasKey('npm-asset-bundled-dependencies', $composer['extra']);
  100. $this->assertSame($this->asset['bundledDependencies'], $composer['extra']['npm-asset-bundled-dependencies']);
  101. $this->assertArrayHasKey('npm-asset-optional-dependencies', $composer['extra']);
  102. $this->assertSame($this->asset['optionalDependencies'], $composer['extra']['npm-asset-optional-dependencies']);
  103. $this->assertArrayHasKey('npm-asset-engines', $composer['extra']);
  104. $this->assertSame($this->asset['engines'], $composer['extra']['npm-asset-engines']);
  105. $this->assertArrayHasKey('npm-asset-engine-strict', $composer['extra']);
  106. $this->assertSame($this->asset['engineStrict'], $composer['extra']['npm-asset-engine-strict']);
  107. $this->assertArrayHasKey('npm-asset-os', $composer['extra']);
  108. $this->assertSame($this->asset['os'], $composer['extra']['npm-asset-os']);
  109. $this->assertArrayHasKey('npm-asset-cpu', $composer['extra']);
  110. $this->assertSame($this->asset['cpu'], $composer['extra']['npm-asset-cpu']);
  111. $this->assertArrayHasKey('npm-asset-prefer-global', $composer['extra']);
  112. $this->assertSame($this->asset['preferGlobal'], $composer['extra']['npm-asset-prefer-global']);
  113. $this->assertArrayHasKey('npm-asset-private', $composer['extra']);
  114. $this->assertSame($this->asset['private'], $composer['extra']['npm-asset-private']);
  115. $this->assertArrayHasKey('npm-asset-publish-config', $composer['extra']);
  116. $this->assertSame($this->asset['publishConfig'], $composer['extra']['npm-asset-publish-config']);
  117. $this->assertArrayNotHasKey('time', $composer);
  118. $this->assertArrayNotHasKey('support', $composer);
  119. $this->assertArrayNotHasKey('conflict', $composer);
  120. $this->assertArrayNotHasKey('replace', $composer);
  121. $this->assertArrayNotHasKey('provide', $composer);
  122. $this->assertArrayNotHasKey('suggest', $composer);
  123. $this->assertArrayNotHasKey('autoload', $composer);
  124. $this->assertArrayNotHasKey('autoload-dev', $composer);
  125. $this->assertArrayNotHasKey('include-path', $composer);
  126. $this->assertArrayNotHasKey('target-dir', $composer);
  127. $this->assertArrayNotHasKey('archive', $composer);
  128. }
  129. }