Exemplo n.º 1
0
    /**
     * @covers ::execute
     */
    public function testExecute()
    {
        $client = new ClientMock();
        $client->queueResponse('packagist/list.json')->queueResponse('packagist/list.json')->queueResponse('packagist/list.empty.json');
        $command = new SearchCommand($client);
        $console = new Application();
        $console->add($command);
        $tester = new CommandTester($console->get('search'));
        $tester->execute([]);
        $expected = <<<RESPONSE
Available Init Templates:
  clippings/package-template
  harp-orm/harp-template
  openbuildings/jam-template

RESPONSE;
        $this->assertEquals($expected, $tester->getDisplay());
        $tester->execute(['filter' => 'clip']);
        $expected = <<<RESPONSE
Available Init Templates:
  clippings/package-template

RESPONSE;
        $this->assertEquals($expected, $tester->getDisplay());
        $expected = <<<RESPONSE
No templates found

RESPONSE;
        $tester->execute([]);
        $this->assertEquals($expected, $tester->getDisplay());
    }
 /**
  * @covers ::getDefault
  */
 public function testGetDefaultGithub()
 {
     $gitConfig = $this->getMockBuilder('CL\\ComposerInit\\GitConfig')->getMock();
     $gitConfig->method('getOrigin')->willReturn('octocat/Hello-World');
     $github = new ClientMock();
     $github->queueResponse('github/repo.json');
     $prompt = new DescriptionPrompt($gitConfig, $github);
     $this->assertEquals('This your first repo!', $prompt->getDefault());
     $history = $github->getHistory();
     $this->assertEquals('/repos/octocat/Hello-World', (string) $history[0]['request']->getUri());
 }
Exemplo n.º 3
0
 /**
  * @covers ::getPackageZipUrl
  */
 public function testGetPackageZipUrl()
 {
     $template = $this->getMockBuilder('CL\\ComposerInit\\Template')->disableOriginalConstructor()->getMock();
     $prompts = $this->getMockBuilder('CL\\ComposerInit\\Prompt\\Prompts')->disableOriginalConstructor()->getMock();
     $packagist = new ClientMock();
     $packagist->queueResponse('packagist/package.json');
     $command = new UseCommand($template, $prompts, $packagist);
     $url = $command->getPackageZipUrl('clippings/package-template');
     $expected = 'https://api.github.com/repos/clippings/package-template/zipball/60c22c4aa0ae0afc3b0d7176a7154a9f2a005c0c';
     $this->assertEquals($expected, $url);
     $history = $packagist->getHistory();
     $this->assertEquals('/packages/clippings/package-template.json', (string) $history[0]['request']->getUri());
 }
Exemplo n.º 4
0
 /**
  * @covers ::putInto
  */
 public function testPutInto()
 {
     $client = new ClientMock();
     $client->queueResponse('test.zip');
     $template = $this->getMockBuilder('CL\\ComposerInit\\Template')->setConstructorArgs([$client])->setMethods(['putFile', 'putDir'])->getMock();
     $template->open('TEST');
     $template->setValues(['author_name' => 'AUTHOR', 'title' => 'TITLE']);
     $template->expects($this->at(0))->method('putFile')->with('temp/.DS_Store');
     $template->expects($this->at(1))->method('putFile')->with('temp/.gitignore', "/vendor/\n/build/\n");
     $template->expects($this->at(2))->method('putFile')->with('temp/README.md', "# Test Project Named TITLE\n");
     $template->expects($this->at(3))->method('putDir')->with('temp/src/');
     $template->expects($this->at(4))->method('putFile')->with('temp/src/Init.php', "<?php\n\n/**\n * @author    AUTHOR\n */\nclass Init {}\n");
     $template->putInto('temp');
 }
 /**
  * @covers ::getDefaults
  */
 public function testGetDefaultsFull()
 {
     $gitConfig = $this->getMockBuilder('CL\\ComposerInit\\GitConfig')->getMock();
     $gitConfig->method('getOrigin')->willReturn('octocat/Hello-World');
     $gitConfig->method('get')->with($this->equalTo('user.name'))->willReturn('TEST_USER');
     $github = new ClientMock();
     $github->queueResponse('github/repo.json')->queueResponse('github/organization.json')->queueResponse('github/user.json');
     $prompt = new CopyrightPrompt($gitConfig, $github);
     $expected = ['github', 'monalisa octocat', 'TEST_USER', get_current_user()];
     $this->assertEquals($expected, $prompt->getDefaults());
     $history = $github->getHistory();
     $this->assertEquals('/repos/octocat/Hello-World', (string) $history[0]['request']->getUri());
     $this->assertEquals('/orgs/github', (string) $history[1]['request']->getUri());
     $this->assertEquals('/users/octocat', (string) $history[2]['request']->getUri());
 }