FilesystemRepositoryTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Repository;
  12. use Composer\Repository\FilesystemRepository;
  13. use Composer\Package\MemoryPackage;
  14. class FilesystemRepositoryTest extends \PHPUnit_Framework_TestCase
  15. {
  16. public function testRepositoryRead()
  17. {
  18. $json = $this->createJsonFileMock();
  19. $repository = new FilesystemRepository($json);
  20. $repository->setRepositoryManager($this->getMock('Composer\Repository\RepositoryManager'));
  21. $json
  22. ->expects($this->once())
  23. ->method('read')
  24. ->will($this->returnValue(array(
  25. array('name' => 'package1', 'version' => '1.0.0-beta', 'type' => 'vendor')
  26. )));
  27. $json
  28. ->expects($this->once())
  29. ->method('exists')
  30. ->will($this->returnValue(true));
  31. $packages = $repository->getPackages();
  32. $this->assertSame(1, count($packages));
  33. $this->assertSame('package1', $packages[0]->getName());
  34. $this->assertSame('1.0.0.0-beta', $packages[0]->getVersion());
  35. $this->assertSame('vendor', $packages[0]->getType());
  36. }
  37. public function testRepositoryWrite()
  38. {
  39. $json = $this->createJsonFileMock();
  40. $repository = new FilesystemRepository($json);
  41. $repository->setRepositoryManager($this->getMock('Composer\Repository\RepositoryManager'));
  42. $json
  43. ->expects($this->once())
  44. ->method('read')
  45. ->will($this->returnValue(array()));
  46. $json
  47. ->expects($this->once())
  48. ->method('exists')
  49. ->will($this->returnValue(true));
  50. $json
  51. ->expects($this->once())
  52. ->method('write')
  53. ->with(array(
  54. array('name' => 'mypkg', 'type' => 'library', 'names' => array('mypkg'), 'version' => '0.1.10')
  55. ));
  56. $repository->addPackage(new MemoryPackage('mypkg', '0.1.10'));
  57. $repository->write();
  58. }
  59. private function createJsonFileMock()
  60. {
  61. return $this->getMockBuilder('Composer\Json\JsonFile')
  62. ->disableOriginalConstructor()
  63. ->getMock();
  64. }
  65. }