protected function getRepoWithMockedGithubClient($bundleClassName, $bundleClassContentsLink, $validComposerFile = true)
{
$json = json_decode(file_get_contents($bundleClassContentsLink), true);
$githubApiContentsMock = $this->getMockBuilder('Github\\Api\\Repository\\Contents')->disableOriginalConstructor()->getMock();
$githubApiMock = $this->getMockBuilder('Github\\Api\\Repo')->disableOriginalConstructor()->getMock();
$githubApiMock->expects($this->at(0))->method('contents')->will($this->returnValue($githubApiContentsMock));
if (!$validComposerFile) {
$composerContent = file_get_contents(__DIR__ . '/fixtures/encoded-invalid-composer.json');
} else {
$composerContent = file_get_contents(__DIR__ . '/fixtures/encoded-composer.json');
}
$composer = json_decode($composerContent, true);
$githubApiContentsMock->expects($this->at(0))->method('show')->with('KnpLabs', 'KnpMenuBundle', 'composer.json')->will($this->returnValue($composer));
if (!$validComposerFile) {
$githubApiTreesMock = $this->getMockBuilder('Github\\Api\\GitData\\Trees')->disableOriginalConstructor()->getMock();
$githubApiTreesMock->expects($this->at(0))->method('show')->with('KnpLabs', 'KnpMenuBundle', 'master', true)->will($this->returnValue(array("tree" => array(array("path" => $bundleClassName)))));
}
$githubGitMock = $this->getMockBuilder('Github\\Api\\GitData')->disableOriginalConstructor()->getMock();
if (!$validComposerFile) {
$githubGitMock->expects($this->at(0))->method('trees')->will($this->returnValue($githubApiTreesMock));
}
if (!$validComposerFile) {
$githubApiContentsMock->expects($this->at(1))->method('show')->with('KnpLabs', 'KnpMenuBundle', $bundleClassName)->will($this->returnValue($json));
}
$githubMock = $this->getMock('Github\\Client');
$githubMock->expects($this->at(0))->method('api')->with('repo')->will($this->returnValue($githubApiMock));
if (!$validComposerFile) {
$githubMock->expects($this->at(1))->method('api')->with('git')->will($this->returnValue($githubGitMock));
}
$output = $this->getMock('Symfony\\Component\\Console\\Output\\OutputInterface');
$repoManager = $this->getMockBuilder('Knp\\Bundle\\KnpBundlesBundle\\Git\\RepoManager')->disableOriginalConstructor()->getMock();
return new Repo($githubMock, $output, $repoManager, new EventDispatcher(), $this->getOwnerManagerMock());
}