FilesystemRepositoryTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. class FilesystemRepositoryTest extends \PHPUnit_Framework_TestCase
  14. {
  15. private $dir;
  16. private $repositoryFile;
  17. protected function setUp()
  18. {
  19. $this->dir = sys_get_temp_dir().'/.composer';
  20. $this->repositoryFile = $this->dir.'/some_registry-reg.json';
  21. if (file_exists($this->repositoryFile)) {
  22. unlink($this->repositoryFile);
  23. }
  24. }
  25. public function testRepositoryReadWrite()
  26. {
  27. $this->assertFileNotExists($this->repositoryFile);
  28. $repository = new FilesystemRepository($this->repositoryFile);
  29. $repository->getPackages();
  30. $repository->write();
  31. $this->assertFileExists($this->repositoryFile);
  32. file_put_contents($this->repositoryFile, json_encode(array(
  33. array('name' => 'package1', 'version' => '1.0.0-beta', 'type' => 'vendor')
  34. )));
  35. $repository = new FilesystemRepository($this->repositoryFile);
  36. $repository->getPackages();
  37. $repository->write();
  38. $this->assertFileExists($this->repositoryFile);
  39. $data = json_decode(file_get_contents($this->repositoryFile), true);
  40. $this->assertEquals(array(
  41. array('name' => 'package1', 'type' => 'vendor', 'version' => '1.0.0-beta', 'names' => array('package1'))
  42. ), $data);
  43. }
  44. }