-
Notifications
You must be signed in to change notification settings - Fork 2
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
5 changed files
with
215 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the streak package. | ||
* | ||
* (C) Alan Gabriel Bem <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Streak\Application\Command; | ||
|
||
use Streak\Application\Command; | ||
|
||
/** | ||
* @author Alan Gabriel Bem <[email protected]> | ||
*/ | ||
class ScheduleCommand implements Command | ||
{ | ||
private $command; | ||
|
||
private $when; | ||
|
||
public function __construct(Command $command, \DateTimeInterface $when) | ||
{ | ||
$this->command = $command; | ||
$this->when = $when; | ||
} | ||
|
||
public function command() : Command | ||
{ | ||
return $this->command; | ||
} | ||
|
||
public function when() : \DateTimeInterface | ||
{ | ||
return $this->when; | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the streak package. | ||
* | ||
* (C) Alan Gabriel Bem <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Streak\Application\Command; | ||
|
||
use Streak\Application\Command; | ||
use Streak\Application\CommandHandler; | ||
use Streak\Application\Exception; | ||
|
||
/** | ||
* @author Alan Gabriel Bem <[email protected]> | ||
*/ | ||
class ScheduleCommandHandler implements CommandHandler | ||
{ | ||
private $commands; | ||
|
||
public function __construct(ScheduledCommand\Repository $commands) | ||
{ | ||
$this->commands = $commands; | ||
} | ||
|
||
public function handle(Command $command) : void | ||
{ | ||
if (!$command instanceof ScheduleCommand) { | ||
throw new Exception\CommandNotSupported($command); | ||
} | ||
|
||
$this->commands->add($command); | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the streak package. | ||
* | ||
* (C) Alan Gabriel Bem <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Streak\Application\Command\ScheduledCommand; | ||
|
||
use Streak\Application\Command\ScheduleCommand; | ||
|
||
/** | ||
* @author Alan Gabriel Bem <[email protected]> | ||
*/ | ||
interface Repository | ||
{ | ||
public function add(ScheduleCommand $command) : void; | ||
} |
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,65 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the streak package. | ||
* | ||
* (C) Alan Gabriel Bem <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Streak\Application\Command; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Streak\Application\Command; | ||
use Streak\Application\Exception; | ||
|
||
/** | ||
* @author Alan Gabriel Bem <[email protected]> | ||
* | ||
* @covers \Streak\Application\Command\ScheduleCommandHandler | ||
*/ | ||
class ScheduleCommandHandlerTest extends TestCase | ||
{ | ||
/** | ||
* @var ScheduledCommand\Repository|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $repository; | ||
|
||
/** | ||
* @var Command|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $command; | ||
|
||
protected function setUp() | ||
{ | ||
$this->repository = $this->getMockBuilder(ScheduledCommand\Repository::class)->getMockForAbstractClass(); | ||
$this->command = $this->getMockBuilder(Command::class)->getMockForAbstractClass(); | ||
} | ||
|
||
public function testSuccess() | ||
{ | ||
$command = new ScheduleCommand($this->command, new \DateTime()); | ||
|
||
$this->repository | ||
->expects($this->once()) | ||
->method('add') | ||
->with($command); | ||
|
||
$handler = new ScheduleCommandHandler($this->repository); | ||
$handler->handle($command); | ||
} | ||
|
||
public function testFailure() | ||
{ | ||
$handler = new ScheduleCommandHandler($this->repository); | ||
|
||
$exception = new Exception\CommandNotSupported($this->command); | ||
$this->expectExceptionObject($exception); | ||
|
||
$handler->handle($this->command); | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the streak package. | ||
* | ||
* (C) Alan Gabriel Bem <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Streak\Application\Command; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Streak\Application\Command; | ||
|
||
/** | ||
* @author Alan Gabriel Bem <[email protected]> | ||
* | ||
* @covers \Streak\Application\Command\ScheduleCommand | ||
*/ | ||
class ScheduleCommandTest extends TestCase | ||
{ | ||
/** | ||
* @var Command|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $command; | ||
|
||
protected function setUp() | ||
{ | ||
$this->command = $this->getMockBuilder(Command::class)->getMockForAbstractClass(); | ||
} | ||
|
||
public function testCommand() | ||
{ | ||
$now = new \DateTime(); | ||
$scheduled = new ScheduleCommand($this->command, $now); | ||
|
||
$this->assertSame($this->command, $scheduled->command()); | ||
$this->assertSame($now, $scheduled->when()); | ||
} | ||
} |