-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
143 additions
and
0 deletions.
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,55 @@ | ||
<?php | ||
|
||
namespace Couscous\Tests\UnitTest; | ||
|
||
use Couscous\Generator; | ||
use Couscous\Model\Repository; | ||
use Couscous\Tests\UnitTest\Mock\MockRepository; | ||
use Symfony\Component\Console\Output\NullOutput; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
|
||
/** | ||
* @covers \Couscous\Generator | ||
*/ | ||
class GeneratorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function it_should_invoke_every_step() | ||
{ | ||
$filesystem = $this->createFileSystem(); | ||
$repository = new MockRepository(); | ||
$output = new NullOutput(); | ||
|
||
$steps = [ | ||
$this->createStep($repository, $output), | ||
$this->createStep($repository, $output), | ||
$this->createStep($repository, $output), | ||
]; | ||
|
||
$generator = new Generator($filesystem, $steps); | ||
|
||
$generator->generate($repository, $output); | ||
} | ||
|
||
/** | ||
* @return \PHPUnit_Framework_MockObject_MockObject|Filesystem | ||
*/ | ||
private function createFilesystem() | ||
{ | ||
return $this->getMock('Symfony\Component\Filesystem\Filesystem'); | ||
} | ||
|
||
private function createStep(Repository $repository, OutputInterface $output) | ||
{ | ||
$step = $this->getMockForAbstractClass('Couscous\Step\StepInterface'); | ||
|
||
$step->expects($this->once()) | ||
->method('__invoke') | ||
->with($repository, $output); | ||
|
||
return $step; | ||
} | ||
} |
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,84 @@ | ||
<?php | ||
|
||
namespace Couscous\Tests\UnitTest\Model; | ||
|
||
use Couscous\Model\File; | ||
use Couscous\Model\File\HtmlFile; | ||
use Couscous\Model\File\MarkdownFile; | ||
use Couscous\Model\Repository; | ||
|
||
/** | ||
* @covers \Couscous\Model\Repository | ||
*/ | ||
class RepositoryTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function it_should_contain_files() | ||
{ | ||
$repository = new Repository('source', 'target'); | ||
|
||
$file1 = $this->createFile('file1'); | ||
$file2 = $this->createFile('file2'); | ||
|
||
$repository->addFile($file1); | ||
$repository->addFile($file2); | ||
$expected = [ | ||
'file1' => $file1, | ||
'file2' => $file2, | ||
]; | ||
$this->assertSame($expected, $repository->getFiles()); | ||
|
||
$repository->removeFile($file1); | ||
$this->assertSame(['file2' => $file2], $repository->getFiles()); | ||
|
||
$repository->removeFile($file2); | ||
$this->assertSame([], $repository->getFiles()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function replace_should_replace_files() | ||
{ | ||
$repository = new Repository('source', 'target'); | ||
|
||
$file1 = $this->createFile('file1'); | ||
$file2 = $this->createFile('file2'); | ||
|
||
$repository->addFile($file1); | ||
$this->assertSame(['file1' => $file1], $repository->getFiles()); | ||
|
||
$repository->replaceFile($file1, $file2);; | ||
$this->assertSame(['file2' => $file2], $repository->getFiles()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_should_return_files_by_type() | ||
{ | ||
$repository = new Repository('source', 'target'); | ||
|
||
$file1 = new MarkdownFile('file1', 'Hello'); | ||
$file2 = new HtmlFile('file2', 'Hello'); | ||
|
||
$repository->addFile($file1); | ||
$repository->addFile($file2); | ||
|
||
$markdownFiles = $repository->findFilesByType('Couscous\Model\File\MarkdownFile'); | ||
$this->assertSame(['file1' => $file1], $markdownFiles); | ||
|
||
$htmlFiles = $repository->findFilesByType('Couscous\Model\File\HtmlFile'); | ||
$this->assertSame(['file2' => $file2], $htmlFiles); | ||
} | ||
|
||
/** | ||
* @return \PHPUnit_Framework_MockObject_MockObject|File | ||
*/ | ||
private function createFile($name) | ||
{ | ||
return $this->getMockForAbstractClass('Couscous\Model\File', [$name]); | ||
} | ||
} |