-
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for FetchRemoteTemplate
- Loading branch information
Showing
2 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} | ||
} |