GitHubDriver: better handle empty composer.json file (#11552)
parent
8f49166ec6
commit
cf8ea3c70e
|
@ -310,7 +310,7 @@ class GitHubDriver extends VcsDriver
|
||||||
$resource = $this->getContents($resource['git_url'])->decodeJson();
|
$resource = $this->getContents($resource['git_url'])->decodeJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($resource['content']) || $resource['encoding'] !== 'base64' || !($content = base64_decode($resource['content']))) {
|
if (!isset($resource['content']) || $resource['encoding'] !== 'base64' || false === ($content = base64_decode($resource['content']))) {
|
||||||
throw new \RuntimeException('Could not retrieve ' . $file . ' for '.$identifier);
|
throw new \RuntimeException('Could not retrieve ' . $file . ' for '.$identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -401,6 +401,34 @@ class GitHubDriverTest extends TestCase
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetEmptyFileContent(): void
|
||||||
|
{
|
||||||
|
$repoUrl = 'http://github.com/composer/packagist';
|
||||||
|
|
||||||
|
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
||||||
|
$io->expects($this->any())
|
||||||
|
->method('isInteractive')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
|
$httpDownloader = $this->getHttpDownloaderMock($io, $this->config);
|
||||||
|
$httpDownloader->expects(
|
||||||
|
[
|
||||||
|
['url' => 'https://api.github.com/repos/composer/packagist', 'body' => '{"master_branch": "test_master", "owner": {"login": "composer"}, "name": "packagist", "archived": true}'],
|
||||||
|
['url' => 'https://api.github.com/repos/composer/packagist/contents/composer.json?ref=main', 'body' => '{"encoding":"base64","content":""}'],
|
||||||
|
],
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
$repoConfig = [
|
||||||
|
'url' => $repoUrl,
|
||||||
|
];
|
||||||
|
|
||||||
|
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, $this->getProcessExecutorMock());
|
||||||
|
$gitHubDriver->initialize();
|
||||||
|
|
||||||
|
$this->assertSame('', $gitHubDriver->getFileContent('composer.json', 'main'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|object $object
|
* @param string|object $object
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
|
|
Loading…
Reference in New Issue