FilesystemRepositoryTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. $json
  21. ->expects($this->once())
  22. ->method('read')
  23. ->will($this->returnValue(array(
  24. array('name' => 'package1', 'version' => '1.0.0-beta', 'type' => 'vendor')
  25. )));
  26. $json
  27. ->expects($this->once())
  28. ->method('exists')
  29. ->will($this->returnValue(true));
  30. $packages = $repository->getPackages();
  31. $this->assertSame(1, count($packages));
  32. $this->assertSame('package1', $packages[0]->getName());
  33. $this->assertSame('1.0.0.0-beta', $packages[0]->getVersion());
  34. $this->assertSame('vendor', $packages[0]->getType());
  35. }
  36. public function testRepositoryWrite()
  37. {
  38. $json = $this->createJsonFileMock();
  39. $repository = new FilesystemRepository($json);
  40. $json
  41. ->expects($this->once())
  42. ->method('read')
  43. ->will($this->returnValue(array()));
  44. $json
  45. ->expects($this->once())
  46. ->method('exists')
  47. ->will($this->returnValue(true));
  48. $json
  49. ->expects($this->once())
  50. ->method('write')
  51. ->with(array(
  52. array('name' => 'mypkg', 'type' => 'library', 'names' => array('mypkg'), 'version' => '0.1.10')
  53. ));
  54. $repository->addPackage(new MemoryPackage('mypkg', '0.1.10'));
  55. $repository->write();
  56. }
  57. private function createJsonFileMock()
  58. {
  59. return $this->getMockBuilder('Composer\Json\JsonFile')
  60. ->disableOriginalConstructor()
  61. ->getMock();
  62. }
  63. }