mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-30 19:50:12 +02:00
PHP7 Command
This commit is contained in:
@@ -6,44 +6,27 @@ use DesignPatterns\Behavioral\Command\AddMessageDateCommand;
|
||||
use DesignPatterns\Behavioral\Command\HelloCommand;
|
||||
use DesignPatterns\Behavioral\Command\Invoker;
|
||||
use DesignPatterns\Behavioral\Command\Receiver;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* UndoableCommandTest has the role of the Client in the Command Pattern.
|
||||
*/
|
||||
class UndoableCommandTest extends PHPUnit_Framework_TestCase
|
||||
class UndoableCommandTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var Invoker
|
||||
*/
|
||||
protected $invoker;
|
||||
|
||||
/**
|
||||
* @var Receiver
|
||||
*/
|
||||
protected $receiver;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->invoker = new Invoker();
|
||||
$this->receiver = new Receiver();
|
||||
}
|
||||
|
||||
public function testInvocation()
|
||||
{
|
||||
$this->invoker->setCommand(new HelloCommand($this->receiver));
|
||||
$this->invoker->run();
|
||||
$this->assertEquals($this->receiver->getOutput(), 'Hello World');
|
||||
$invoker = new Invoker();
|
||||
$receiver = new Receiver();
|
||||
|
||||
$messageDateCommand = new AddMessageDateCommand($this->receiver);
|
||||
$invoker->setCommand(new HelloCommand($receiver));
|
||||
$invoker->run();
|
||||
$this->assertEquals($receiver->getOutput(), 'Hello World');
|
||||
|
||||
$messageDateCommand = new AddMessageDateCommand($receiver);
|
||||
$messageDateCommand->execute();
|
||||
|
||||
$this->invoker->run();
|
||||
$this->assertEquals($this->receiver->getOutput(), "Hello World\nHello World [".date('Y-m-d').']');
|
||||
$invoker->run();
|
||||
$this->assertEquals($receiver->getOutput(), "Hello World\nHello World [".date('Y-m-d').']');
|
||||
|
||||
$messageDateCommand->undo();
|
||||
|
||||
$this->invoker->run();
|
||||
$this->assertEquals($this->receiver->getOutput(), "Hello World\nHello World [".date('Y-m-d')."]\nHello World");
|
||||
$invoker->run();
|
||||
$this->assertEquals($receiver->getOutput(), "Hello World\nHello World [".date('Y-m-d')."]\nHello World");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user