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.

NpmRepositoryTest.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. }