1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +00:00

Refactored FilesystemRegistry to FilesystemRepository

This commit is contained in:
everzet 2011-09-25 20:59:10 +03:00
parent 5c841187fd
commit 20318f77a0
5 changed files with 137 additions and 349 deletions

View file

@ -0,0 +1,55 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Repository;
use Composer\Repository\FilesystemRepository;
class FilesystemRepositoryTest extends \PHPUnit_Framework_TestCase
{
private $dir;
private $repositoryFile;
protected function setUp()
{
$this->dir = sys_get_temp_dir().'/.composer';
$this->repositoryFile = $this->dir.'/some_registry-reg.json';
if (file_exists($this->repositoryFile)) {
unlink($this->repositoryFile);
}
}
public function testRepositoryReadWrite()
{
$this->assertFileNotExists($this->repositoryFile);
$repository = new FilesystemRepository($this->repositoryFile);
$repository->getPackages();
$repository->write();
$this->assertFileExists($this->repositoryFile);
file_put_contents($this->repositoryFile, json_encode(array(
array('name' => 'package1', 'version' => '1.0.0-beta', 'type' => 'vendor')
)));
$repository = new FilesystemRepository($this->repositoryFile);
$repository->getPackages();
$repository->write();
$this->assertFileExists($this->repositoryFile);
$data = json_decode(file_get_contents($this->repositoryFile), true);
$this->assertEquals(array(
array('name' => 'package1', 'type' => 'vendor', 'version' => '1.0.0', 'releaseType' => 'beta', 'names' => array('package1'))
), $data);
}
}