Skip to content

Commit

Permalink
Add nonexistent packages in cache
Browse files Browse the repository at this point in the history
  • Loading branch information
francoispluchino committed Aug 4, 2014
1 parent 4be7d01 commit bb0eb2b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 13 deletions.
20 changes: 10 additions & 10 deletions Repository/Vcs/GitDriver.php
Expand Up @@ -39,19 +39,19 @@ public function getComposerInformation($identifier)
$this->process->execute(sprintf('git show %s', $resource), $composer, $this->repoDir);

if (!trim($composer)) {
return null;
$composer = array('_nonexistent_package' => true);
} else {
$composer = JsonFile::parseJson($composer, $resource);

if (!isset($composer['time'])) {
$this->process->execute(sprintf('git log -1 --format=%%at %s', escapeshellarg($identifier)), $output, $this->repoDir);
$date = new \DateTime('@'.trim($output), new \DateTimeZone('UTC'));
$composer['time'] = $date->format('Y-m-d H:i:s');
}
}

$composer = JsonFile::parseJson($composer, $resource);

if (!isset($composer['time'])) {
$this->process->execute(sprintf('git log -1 --format=%%at %s', escapeshellarg($identifier)), $output, $this->repoDir);
$date = new \DateTime('@'.trim($output), new \DateTimeZone('UTC'));
$composer['time'] = $date->format('Y-m-d H:i:s');
}

$this->infoCache[$identifier] = $composer;
Util::writeCache($this->cache, $this->repoConfig['asset-type'], $identifier, $composer);
$this->infoCache[$identifier] = $composer;
}

return $this->infoCache[$identifier];
Expand Down
4 changes: 3 additions & 1 deletion Repository/Vcs/GitHubDriver.php
Expand Up @@ -45,9 +45,11 @@ public function getComposerInformation($identifier)

if ($composer) {
$composer = $this->convertComposerContent($composer, $resource, $identifier);
Util::writeCache($this->cache, $this->repoConfig['asset-type'], $identifier, $composer);
} else {
$composer = array('_nonexistent_package' => true);
}

Util::writeCache($this->cache, $this->repoConfig['asset-type'], $identifier, $composer);
$this->infoCache[$identifier] = $composer;
}

Expand Down
6 changes: 5 additions & 1 deletion Tests/Repository/Vcs/GitDriverTest.php
Expand Up @@ -87,7 +87,11 @@ public function testPublicRepositoryWithEmptyComposer($type, $filename)
$gitDriver = new GitDriver($repoConfig, $io, $this->config, $process, null);
$gitDriver->initialize();

$this->assertNull($gitDriver->getComposerInformation($identifier));
$validEmpty = array(
'_nonexistent_package' => true,
);

$this->assertSame($validEmpty, $gitDriver->getComposerInformation($identifier));
}

/**
Expand Down
54 changes: 53 additions & 1 deletion Tests/Repository/Vcs/GitHubDriverTest.php
Expand Up @@ -398,7 +398,11 @@ public function testGetComposerInformationWithGitDriver($type, $filename)
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $process, null);
$gitHubDriver->initialize();

$this->assertNull($gitHubDriver->getComposerInformation($identifier));
$validEmpty = array(
'_nonexistent_package' => true,
);

$this->assertSame($validEmpty, $gitHubDriver->getComposerInformation($identifier));
}

/**
Expand Down Expand Up @@ -481,6 +485,54 @@ public function testGetComposerInformationWithFilesystemCache($type, $filename)
* @dataProvider getAssetTypes
*/
public function testGetComposerInformationWithEmptyContent($type, $filename)
{
$repoUrl = 'http://github.com/composer-test/repo-name';
$repoApiUrl = 'https://api.github.com/repos/composer-test/repo-name';
$identifier = 'v0.0.0';

$io = $this->getMock('Composer\IO\IOInterface');

$remoteFilesystem = $this->getMockBuilder('Composer\Util\RemoteFilesystem')
->setConstructorArgs(array($io))
->getMock();

$remoteFilesystem->expects($this->at(0))
->method('getContents')
->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
->will($this->returnValue($this->createJsonComposer(array('master_branch' => 'test_master'))));

$remoteFilesystem->expects($this->at(1))
->method('getContents')
->with($this->equalTo('github.com'), $this->equalTo('https://api.github.com/repos/composer-test/repo-name/contents/'.$filename.'?ref='.$identifier), $this->equalTo(false))
->will($this->throwException(new TransportException('Not Found', 404)));
$remoteFilesystem->expects($this->at(2))
->method('getContents')
->with($this->equalTo('github.com'), $this->equalTo('https://api.github.com/repos/composer-test/repo-name/contents/'.$filename.'?ref='.$identifier), $this->equalTo(false))
->will($this->throwException(new TransportException('Not Found', 404)));

$repoConfig = array(
'url' => $repoUrl,
'asset-type' => $type,
'filename' => $filename,
);

/* @var IOInterface $io */
/* @var RemoteFilesystem $remoteFilesystem */

$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, null, $remoteFilesystem);
$gitHubDriver->initialize();

$validEmpty = array(
'_nonexistent_package' => true,
);

$this->assertSame($validEmpty, $gitHubDriver->getComposerInformation($identifier));
}

/**
* @dataProvider getAssetTypes
*/
public function testGetComposerInformationWithRuntimeException($type, $filename)
{
$this->setExpectedException('RuntimeException');

Expand Down

0 comments on commit bb0eb2b

Please sign in to comment.