Exemplo n.º 1
0
 /**
  * @dataProvider getDataBranches
  */
 public function testGetBranches($type, $filename, array $branches)
 {
     $repoUrl = 'http://github.com/composer-test/repo-name';
     $repoApiUrl = 'https://api.github.com/repos/composer-test/repo-name';
     $identifier = 'v0.0.0';
     $sha = 'SOMESHA';
     $io = $this->getMock('Composer\\IO\\IOInterface');
     $io->expects($this->any())->method('isInteractive')->will($this->returnValue(true));
     $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' => 'gh-pages'))));
     $remoteFilesystem->expects($this->any())->method('getLastHeaders')->will($this->returnValue(array()));
     $githubBranches = array();
     foreach ($branches as $branch => $sha) {
         $githubBranches[] = array('ref' => 'refs/heads/' . $branch, 'object' => array('sha' => $sha));
     }
     $remoteFilesystem->expects($this->at(1))->method('getContents')->will($this->returnValue(json_encode($githubBranches)));
     $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();
     $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
     $this->assertEquals('gh-pages', $gitHubDriver->getRootIdentifier());
     $this->assertSame($branches, $gitHubDriver->getBranches());
 }
 /**
  * @dataProvider getDataBranches
  *
  * @param string $type
  * @param string $filename
  * @param array  $branches
  * @param array  $gitBranches
  */
 public function testNoApi($type, $filename, array $branches, array $gitBranches)
 {
     $repoUrl = 'https://github.com/composer-test/repo-name';
     $packageName = $type . '-asset/repo-name';
     $io = $this->getMockBuilder('Composer\\IO\\IOInterface')->getMock();
     $io->expects($this->any())->method('isInteractive')->will($this->returnValue(true));
     $repoConfig = array('url' => $repoUrl, 'asset-type' => $type, 'filename' => $filename, 'package-name' => $packageName, 'vcs-driver-options' => array('github-no-api' => true));
     $process = $this->getMockBuilder('Composer\\Util\\ProcessExecutor')->getMock();
     $process->expects($this->any())->method('splitLines')->will($this->returnValue($gitBranches));
     $process->expects($this->any())->method('execute')->will($this->returnCallback(function () {
         return 0;
     }));
     /* @var IOInterface $io */
     /* @var ProcessExecutor $process */
     $gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $process, null);
     $gitHubDriver->initialize();
     $this->assertSame($branches, $gitHubDriver->getBranches());
 }
Exemplo n.º 3
0
    /**
     * @dataProvider getAssetTypes
     */
    public function testRedirectUrlRepositoryWithCache($type, $filename)
    {
        $originUrl = 'github.com';
        $owner = 'composer-test';
        $repository = 'repo-name';
        $repoUrl = 'http://'.$originUrl.'/'.$owner.'/'.$repository;
        $repoApiUrl = 'https://api.github.com/repos/composer-test/repo-name';
        $repoApiUrlNew = $repoApiUrl.'-new';
        $identifier = 'v0.0.0';
        $sha = 'SOMESHA';

        $io = $this->getMock('Composer\IO\IOInterface');
        $io->expects($this->any())
            ->method('isInteractive')
            ->will($this->returnValue(true));

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

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

        $repoConfig = array(
            'url'        => $repoUrl,
            'asset-type' => $type,
            'filename'   => $filename,
        );
        $repoUrl = 'https://github.com/composer-test/repo-name.git';

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

        $cache = new Cache($io, $this->config->get('cache-repo-dir').'/'.$originUrl.'/'.$owner.'/'.$repository);
        $cache->write('redirect-api', $repoApiUrlNew);

        $gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, null, $remoteFilesystem);
        $gitHubDriver->initialize();
        $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));

        $this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());

        $dist = $gitHubDriver->getDist($sha);
        $this->assertEquals('zip', $dist['type']);
        $this->assertEquals('https://api.github.com/repos/composer-test/repo-name/zipball/SOMESHA', $dist['url']);
        $this->assertEquals($sha, $dist['reference']);

        $source = $gitHubDriver->getSource($sha);
        $this->assertEquals('git', $source['type']);
        $this->assertEquals($repoUrl, $source['url']);
        $this->assertEquals($sha, $source['reference']);
    }