Skip to content

Commit

Permalink
Added unit tests for FetchRemoteTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Dec 11, 2014
1 parent 5fe71f4 commit 2775489
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Step/Template/FetchRemoteTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private function fetchGitTemplate($gitUrl, OutputInterface $output)

$directory = $this->createTempDirectory('couscous_template_');

$this->commandRunner->run("git clone $gitUrl $directory 2>&1");
$this->commandRunner->run("git clone $gitUrl $directory");

return $directory;
}
Expand Down
83 changes: 83 additions & 0 deletions tests/UnitTest/Step/Template/FetchRemoteTemplateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace Couscous\Tests\UnitTest\Step\Template;

use Couscous\Step\Template\FetchRemoteTemplate;
use Couscous\Tests\UnitTest\Mock\MockRepository;
use Symfony\Component\Console\Output\NullOutput;

/**
* @covers \Couscous\Step\Template\FetchRemoteTemplate
*/
class FetchRemoteTemplateTest extends \PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function it_should_skip_if_no_template_url()
{
$filesystem = $this->getMock('Symfony\Component\Filesystem\Filesystem');
$commandRunner = $this->getMock('Couscous\CommandRunner');

$step = new FetchRemoteTemplate($filesystem, $commandRunner);

$repository = new MockRepository();

$commandRunner->expects($this->never())
->method('run');

$step->__invoke($repository, new NullOutput());

$this->assertNull($repository->metadata['template.directory']);
}

/**
* @test
*/
public function it_should_clone_and_set_the_template_directory()
{
$filesystem = $this->getMock('Symfony\Component\Filesystem\Filesystem');
$commandRunner = $this->getMock('Couscous\CommandRunner');

$step = new FetchRemoteTemplate($filesystem, $commandRunner);

$repository = new MockRepository();
$repository->metadata['template.url'] = 'git://foo';

$commandRunner->expects($this->once())
->method('run')
->with($this->matches('git clone git://foo %s'));

$step->__invoke($repository, new NullOutput());

$this->assertNotNull($repository->metadata['template.directory']);
}

/**
* @test
*/
public function it_should_not_clone_twice_if_regenerating()
{
$filesystem = $this->getMock('Symfony\Component\Filesystem\Filesystem');
$commandRunner = $this->getMock('Couscous\CommandRunner');

$step = new FetchRemoteTemplate($filesystem, $commandRunner);

$commandRunner->expects($this->once())
->method('run')
->with($this->matches('git clone git://foo %s'));

// Calling once
$repository = new MockRepository();
$repository->metadata['template.url'] = 'git://foo';
$step->__invoke($repository, new NullOutput());
$this->assertNotNull($repository->metadata['template.directory']);

// Calling twice
$repository = new MockRepository();
$repository->regenerate = true;
$repository->metadata['template.url'] = 'git://foo';
$step->__invoke($repository, new NullOutput());
$this->assertNotNull($repository->metadata['template.directory']);
}
}

0 comments on commit 2775489

Please sign in to comment.