Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Add LoggableRunner #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"require": {
"php": ">=5.3.3",
"psr/log": "~1.0",
"star/collection": "~1.0",
"symfony/yaml": "~2.1.0",
"symfony/console": "~2.6.0",
Expand Down
2 changes: 1 addition & 1 deletion lib/Data/Fibonacci/FibonacciKata.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use Star\Kata\Domain\Environment;
use Star\Kata\Domain\Kata;
use Star\Kata\Domain\KataRunner;
use Star\Kata\Domain\Runner\KataRunner;
use Star\Kata\Domain\Objective\Objective;
use Star\Kata\Domain\Objective\ObjectiveResult;
use Star\Kata\Domain\StartedKata;
Expand Down
1 change: 1 addition & 0 deletions lib/Domain/Kata.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Star\Kata\Domain\Objective\Objective;
use Star\Kata\Domain\Objective\ObjectiveResult;
use Star\Kata\Domain\Runner\KataRunner;

/**
* Class Kata
Expand Down
1 change: 1 addition & 0 deletions lib/Domain/KataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Star\Kata\Domain\Exception\DirtyEnvironmentException;
use Star\Kata\Domain\Exception\EntityNotFoundException;
use Star\Kata\Domain\Exception\InvalidArgumentException;
use Star\Kata\Domain\Runner\KataRunner;

/**
* Class KataService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
* (c) Yannick Voyer (http://github.com/yvoyer)
*/

namespace Star\Kata\Domain;
namespace Star\Kata\Domain\Runner;

use Star\Kata\Domain\Kata;
use Star\Kata\Domain\Objective\ObjectiveResult;

/**
* Class KataRunner
*
* @author Yannick Voyer (http://github.com/yvoyer)
*
* @package Star\Kata\Domain
* @package Star\Kata\Domain\Runner
*/
interface KataRunner
{
Expand Down
59 changes: 59 additions & 0 deletions lib/Domain/Runner/LoggableRunner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* This file is part of the phpkata project.
*
* (c) Yannick Voyer (http://github.com/yvoyer)
*/

namespace Star\Kata\Domain\Runner;

use Psr\Log\LoggerInterface;
use Star\Kata\Domain\Kata;
use Star\Kata\Domain\Objective\ObjectiveResult;

/**
* Class LoggableRunner
*
* @author Yannick Voyer (http://github.com/yvoyer)
*
* @package Star\Kata\Domain\Runner
*/
final class LoggableRunner implements KataRunner
{
/**
* @var KataRunner
*/
private $runner;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @param KataRunner $runner
* @param LoggerInterface $logger todo use adapter to kata package interface
*/
public function __construct(KataRunner $runner, LoggerInterface $logger)
{
$this->runner = $runner;
$this->logger = $logger;
}

/**
* @param Kata $kata
*
* @return ObjectiveResult
*/
public function run(Kata $kata)
{
$result = $this->runner->run($kata);
if ($result->isFailure()) {
$this->logger->error('KATA has failed (use renderer)');
} elseif ($result->isSuccess()) {
$this->logger->info('KATA has succeed (use renderer)');
}

return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* (c) Yannick Voyer (http://github.com/yvoyer)
*/

namespace Star\Kata\Infrastructure\PHPUnit;
namespace Star\Kata\Domain\Runner;

use Star\Kata\Domain\Kata;
use Star\Kata\Domain\KataRunner;
use Star\Kata\Domain\Objective\ObjectiveResult;
use Star\Kata\Infrastructure\PHPUnit\Runner\PHPUnitTestRunner;

Expand All @@ -17,7 +16,7 @@
*
* @author Yannick Voyer (http://github.com/yvoyer)
*
* @package Star\Kata\Infrastructure\PHPUnit
* @package Star\Kata\Domain\Runner
*/
final class PHPUnitKataRunner implements KataRunner
{
Expand Down
2 changes: 1 addition & 1 deletion lib/KataApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use Star\Kata\Command\StartCommand;
use Star\Kata\Data\Fibonacci\FibonacciKata;
use Star\Kata\Domain\Environment;
use Star\Kata\Domain\Runner\PHPUnitKataRunner;
use Star\Kata\Infrastructure\InMemory\KataCollection;
use Star\Kata\Infrastructure\PHPUnit\PHPUnitKataRunner;
use Star\Kata\Domain\KataService;
use Symfony\Component\Console\Application;

Expand Down
83 changes: 83 additions & 0 deletions tests/PHPUnit/Domain/Runner/LoggableRunnerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* This file is part of the phpkata project.
*
* (c) Yannick Voyer (http://github.com/yvoyer)
*/

namespace Star\Kata\Domain\Runner;

use Star\Kata\KataMock;
use Star\Kata\Stub\Objective\FailureResultStub;
use Star\Kata\Stub\Objective\SuccessResultStub;

/**
* Class LoggableRunnerTest
*
* @author Yannick Voyer (http://github.com/yvoyer)
*
* @package Star\Kata\Domain\Runner
*/
final class LoggableRunnerTest extends \PHPUnit_Framework_TestCase
{
use KataMock;

/**
* @var LoggableRunner
*/
private $runner;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $kata;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $wrappedRunner;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $logger;

public function setUp()
{
$this->logger = $this->getMock('Psr\Log\LoggerInterface');
$this->kata = $this->getMockKata();
$this->wrappedRunner = $this->getMockKataRunner();

$this->runner = new LoggableRunner($this->wrappedRunner, $this->logger);
}

public function test_it_should_log_the_success()
{
$result = new SuccessResultStub();
$this->wrappedRunner
->expects($this->once())
->method('run')
->willReturn($result);

$this->logger
->expects($this->once())
->method('info');

$this->assertSame($result, $this->runner->run($this->kata));
}

public function test_it_should_the_failures()
{
$result = new FailureResultStub();
$this->wrappedRunner
->expects($this->once())
->method('run')
->willReturn($result);

$this->logger
->expects($this->once())
->method('error');

$this->assertSame($result, $this->runner->run($this->kata));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* (c) Yannick Voyer (http://github.com/yvoyer)
*/

namespace Star\Kata\Infrastructure\PHPUnit;
namespace Star\Kata\Domain\Runner;

use Star\Fixture\Null\NullKata;
use Star\Kata\KataMock;
Expand All @@ -15,7 +15,7 @@
*
* @author Yannick Voyer (http://github.com/yvoyer)
*
* @package Star\Kata\Infrastructure\PHPUnit
* @package Star\Kata\Domain\Runner
*/
final class PHPUnitKataRunnerTest extends \PHPUnit_Framework_TestCase
{
Expand Down
10 changes: 9 additions & 1 deletion tests/PHPUnit/KataMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function getMockKataRepository()
*/
protected function getMockKataRunner()
{
return $this->getMock('Star\Kata\Domain\KataRunner');
return $this->getMock('Star\Kata\Domain\Runner\KataRunner');
}

/**
Expand All @@ -55,4 +55,12 @@ protected function getMockObjective()
{
return $this->getMock('Star\Kata\Domain\Objective\Objective');
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
protected function getMockObjectiveResult()
{
return $this->getMock('Star\Kata\Domain\Objective\ObjectiveResult');
}
}
69 changes: 69 additions & 0 deletions tests/PHPUnit/Stub/Objective/FailureResultStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* This file is part of the phpkata project.
*
* (c) Yannick Voyer (http://github.com/yvoyer)
*/

namespace Star\Kata\Stub\Objective;

use Star\Kata\Domain\Objective\Objective;
use Star\Kata\Domain\Objective\ObjectiveResult;

/**
* Class FailureResultStub
*
* @author Yannick Voyer (http://github.com/yvoyer)
*
* @package Star\Kata\Stub\Objective
*/
final class FailureResultStub implements ObjectiveResult
{
/**
* @return int
*/
public function points()
{
return 0;
}

/**
* @return int
*/
public function maxPoints()
{
return 1;
}

/**
* @return bool
*/
public function isSuccess()
{
return false;
}

/**
* @return bool
*/
public function isFailure()
{
return true;
}

/**
* @return Objective
*/
public function objective()
{
throw new \RuntimeException('Method ' . __METHOD__ . ' not implemented yet.');
}

/**
* @param string $requirement
*/
public function failRequirement($requirement)
{
throw new \RuntimeException('Method ' . __METHOD__ . ' not implemented yet.');
}
}
Loading