1
0
Fork 0

Merge pull request #71 from fabpot/filesystem-bug

Filesystem bug

Object of class Composer\Json\JsonFile could not be converted to string
pull/77/merge
Nils Adermann 2011-10-30 05:04:37 -07:00
commit 56fab04c93
3 changed files with 47 additions and 4 deletions

View File

@ -34,6 +34,11 @@ class JsonFile
$this->path = $path; $this->path = $path;
} }
public function getPath()
{
return $this->path;
}
/** /**
* Checks whether json file exists. * Checks whether json file exists.
* *

View File

@ -43,13 +43,14 @@ class FilesystemRepository extends ArrayRepository implements WritableRepository
{ {
parent::initialize(); parent::initialize();
$packages = null; if (!$this->file->exists()) {
if ($this->file->exists()) { return;
$packages = $this->file->read();
} }
$packages = $this->file->read();
if (!is_array($packages)) { if (!is_array($packages)) {
throw new \UnexpectedValueException('Could not parse package list from the '.$this->file.' repository'); throw new \UnexpectedValueException('Could not parse package list from the '.$this->file->getPath().' repository');
} }
$loader = new ArrayLoader($this->repositoryManager); $loader = new ArrayLoader($this->repositoryManager);

View File

@ -43,6 +43,43 @@ class FilesystemRepositoryTest extends \PHPUnit_Framework_TestCase
$this->assertSame('vendor', $packages[0]->getType()); $this->assertSame('vendor', $packages[0]->getType());
} }
/**
* @expectedException \UnexpectedValueException
*/
public function testCorruptedRepositoryFile()
{
$json = $this->createJsonFileMock();
$repository = new FilesystemRepository($json);
$repository->setRepositoryManager($this->getMock('Composer\Repository\RepositoryManager'));
$json
->expects($this->once())
->method('read')
->will($this->returnValue('foo'));
$json
->expects($this->once())
->method('exists')
->will($this->returnValue(true));
$repository->getPackages();
}
public function testUnexistentRepositoryFile()
{
$json = $this->createJsonFileMock();
$repository = new FilesystemRepository($json);
$repository->setRepositoryManager($this->getMock('Composer\Repository\RepositoryManager'));
$json
->expects($this->once())
->method('exists')
->will($this->returnValue(false));
$this->assertEquals(array(), $repository->getPackages());
}
public function testRepositoryWrite() public function testRepositoryWrite()
{ {
$json = $this->createJsonFileMock(); $json = $this->createJsonFileMock();