Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Dec 6, 2014
1 parent 8ecc1e3 commit 806a6ee
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class Generator
*/
private $steps;

/**
* @param Filesystem $filesystem
* @param StepInterface[] $steps
*/
public function __construct(Filesystem $filesystem, array $steps)
{
$this->filesystem = $filesystem;
Expand Down
55 changes: 55 additions & 0 deletions tests/UnitTest/GeneratorTest.php
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;
}
}
84 changes: 84 additions & 0 deletions tests/UnitTest/Model/RepositoryTest.php
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]);
}
}

0 comments on commit 806a6ee

Please sign in to comment.