您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

141 行
4.5KB

  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\Repository;
  11. use Composer\Config;
  12. use Composer\Downloader\TransportException;
  13. use Composer\EventDispatcher\EventDispatcher;
  14. use Composer\IO\IOInterface;
  15. use Fxp\Composer\AssetPlugin\Repository\NpmRepository;
  16. /**
  17. * Tests of NPM repository.
  18. *
  19. * @author François Pluchino <francois.pluchino@gmail.com>
  20. */
  21. class NpmRepositoryTest extends AbstractAssetsRepositoryTest
  22. {
  23. /**
  24. * {@inheritdoc}
  25. */
  26. protected function getType()
  27. {
  28. return 'npm';
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. protected function getRegistry(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null)
  34. {
  35. return new NpmRepository($repoConfig, $io, $config, $eventDispatcher);
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. protected function getMockPackageForVcsConfig()
  41. {
  42. return array(
  43. 'repository' => array(
  44. 'type' => 'vcs',
  45. 'url' => 'http://foo.tld',
  46. ),
  47. );
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. protected function getMockSearchResult($name = 'mock-package')
  53. {
  54. return array();
  55. }
  56. public function testWhatProvidesWithCamelcasePackageName()
  57. {
  58. $name = $this->getType().'-asset/CamelCasePackage';
  59. $rfs = $this->replaceRegistryRfsByMock();
  60. $rfs->expects($this->any())
  61. ->method('getContents')
  62. ->will($this->throwException(new TransportException('Package not found', 404)));
  63. $this->assertCount(0, $this->rm->getRepositories());
  64. $this->assertCount(0, $this->registry->whatProvides($this->pool, $name));
  65. $this->assertCount(0, $this->registry->whatProvides($this->pool, $name));
  66. $this->assertCount(0, $this->rm->getRepositories());
  67. }
  68. public function testWatProvidesWithoutRepositoryUrl()
  69. {
  70. $name = $this->getType().'-asset/foobar';
  71. $rfs = $this->replaceRegistryRfsByMock();
  72. $rfs->expects($this->any())
  73. ->method('getContents')
  74. ->will($this->returnValue(json_encode(array(
  75. 'repository' => array(
  76. 'type' => 'vcs',
  77. ),
  78. 'versions' => array(
  79. '1.0.0' => array(
  80. 'name' => 'foobar',
  81. 'version' => '0.0.1',
  82. 'dependencies' => array(),
  83. 'dist' => array(
  84. 'shasum' => '1d408b3fdb76923b9543d96fb4c9dfd535d9cb5d',
  85. 'tarball' => 'http://registry.tld/foobar/-/foobar-1.0.0.tgz',
  86. ),
  87. ),
  88. ),
  89. ))));
  90. $this->assertCount(0, $this->rm->getRepositories());
  91. $this->assertCount(0, $this->registry->whatProvides($this->pool, $name));
  92. $this->assertCount(0, $this->registry->whatProvides($this->pool, $name));
  93. $this->assertCount(1, $this->rm->getRepositories());
  94. }
  95. public function testWatProvidesWithoutRepositoryUrlAndWithoutVersions()
  96. {
  97. $this->setExpectedException('Fxp\Composer\AssetPlugin\Exception\InvalidCreateRepositoryException', '"repository.url" parameter of "foobar"');
  98. $name = $this->getType().'-asset/foobar';
  99. $rfs = $this->replaceRegistryRfsByMock();
  100. $rfs->expects($this->any())
  101. ->method('getContents')
  102. ->will($this->returnValue(json_encode(array())));
  103. $this->assertCount(0, $this->rm->getRepositories());
  104. $this->registry->whatProvides($this->pool, $name);
  105. }
  106. public function testWhatProvidesWithGitPlusHttpsUrl()
  107. {
  108. $name = $this->getType().'-asset/existing';
  109. $rfs = $this->replaceRegistryRfsByMock();
  110. $rfs->expects($this->any())
  111. ->method('getContents')
  112. ->will($this->returnValue(json_encode(array(
  113. 'repository' => array(
  114. 'type' => 'vcs',
  115. 'url' => 'git+https://foo.tld',
  116. ),
  117. ))));
  118. $this->assertCount(0, $this->rm->getRepositories());
  119. $this->assertCount(0, $this->registry->whatProvides($this->pool, $name));
  120. $this->assertCount(0, $this->registry->whatProvides($this->pool, $name));
  121. $this->assertCount(1, $this->rm->getRepositories());
  122. }
  123. }