mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-02 21:17:29 +02:00
fix: classes renaming to correspond to UML diagram
This commit is contained in:
@@ -4,19 +4,19 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace DesignPatterns\Behavioral\State;
|
namespace DesignPatterns\Behavioral\State;
|
||||||
|
|
||||||
class OrderContext
|
class ContextOrder
|
||||||
{
|
{
|
||||||
private State $state;
|
private StateOrder $state;
|
||||||
|
|
||||||
public static function create(): OrderContext
|
public static function create(): ContextOrder
|
||||||
{
|
{
|
||||||
$order = new self();
|
$order = new self();
|
||||||
$order->state = new StateCreated();
|
$order->state = new CreateOrder();
|
||||||
|
|
||||||
return $order;
|
return $order;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setState(State $state)
|
public function setState(StateOrder $state)
|
||||||
{
|
{
|
||||||
$this->state = $state;
|
$this->state = $state;
|
||||||
}
|
}
|
@@ -4,11 +4,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace DesignPatterns\Behavioral\State;
|
namespace DesignPatterns\Behavioral\State;
|
||||||
|
|
||||||
class StateCreated implements State
|
class CreateOrder implements StateOrder
|
||||||
{
|
{
|
||||||
public function proceedToNext(OrderContext $context)
|
public function proceedToNext(ContextOrder $context)
|
||||||
{
|
{
|
||||||
$context->setState(new StateShipped());
|
$context->setState(new ShippingOrder());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toString(): string
|
public function toString(): string
|
@@ -4,9 +4,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace DesignPatterns\Behavioral\State;
|
namespace DesignPatterns\Behavioral\State;
|
||||||
|
|
||||||
class StateDone implements State
|
class OrderDone implements StateOrder
|
||||||
{
|
{
|
||||||
public function proceedToNext(OrderContext $context)
|
public function proceedToNext(ContextOrder $context)
|
||||||
{
|
{
|
||||||
// there is nothing more to do
|
// there is nothing more to do
|
||||||
}
|
}
|
@@ -4,11 +4,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace DesignPatterns\Behavioral\State;
|
namespace DesignPatterns\Behavioral\State;
|
||||||
|
|
||||||
class StateShipped implements State
|
class ShippingOrder implements StateOrder
|
||||||
{
|
{
|
||||||
public function proceedToNext(OrderContext $context)
|
public function proceedToNext(ContextOrder $context)
|
||||||
{
|
{
|
||||||
$context->setState(new StateDone());
|
$context->setState(new OrderDone());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toString(): string
|
public function toString(): string
|
@@ -4,9 +4,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace DesignPatterns\Behavioral\State;
|
namespace DesignPatterns\Behavioral\State;
|
||||||
|
|
||||||
interface State
|
interface StateOrder
|
||||||
{
|
{
|
||||||
public function proceedToNext(OrderContext $context);
|
public function proceedToNext(ContextOrder $context);
|
||||||
|
|
||||||
public function toString(): string;
|
public function toString(): string;
|
||||||
}
|
}
|
@@ -4,21 +4,21 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace DesignPatterns\Behavioral\State\Tests;
|
namespace DesignPatterns\Behavioral\State\Tests;
|
||||||
|
|
||||||
use DesignPatterns\Behavioral\State\OrderContext;
|
use DesignPatterns\Behavioral\State\ContextOrder;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class StateTest extends TestCase
|
class StateTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testIsCreatedWithStateCreated()
|
public function testIsCreatedWithStateCreated()
|
||||||
{
|
{
|
||||||
$orderContext = OrderContext::create();
|
$orderContext = ContextOrder::create();
|
||||||
|
|
||||||
$this->assertSame('created', $orderContext->toString());
|
$this->assertSame('created', $orderContext->toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanProceedToStateShipped()
|
public function testCanProceedToStateShipped()
|
||||||
{
|
{
|
||||||
$contextOrder = OrderContext::create();
|
$contextOrder = ContextOrder::create();
|
||||||
$contextOrder->proceedToNext();
|
$contextOrder->proceedToNext();
|
||||||
|
|
||||||
$this->assertSame('shipped', $contextOrder->toString());
|
$this->assertSame('shipped', $contextOrder->toString());
|
||||||
@@ -26,7 +26,7 @@ class StateTest extends TestCase
|
|||||||
|
|
||||||
public function testCanProceedToStateDone()
|
public function testCanProceedToStateDone()
|
||||||
{
|
{
|
||||||
$contextOrder = OrderContext::create();
|
$contextOrder = ContextOrder::create();
|
||||||
$contextOrder->proceedToNext();
|
$contextOrder->proceedToNext();
|
||||||
$contextOrder->proceedToNext();
|
$contextOrder->proceedToNext();
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ class StateTest extends TestCase
|
|||||||
|
|
||||||
public function testStateDoneIsTheLastPossibleState()
|
public function testStateDoneIsTheLastPossibleState()
|
||||||
{
|
{
|
||||||
$contextOrder = OrderContext::create();
|
$contextOrder = ContextOrder::create();
|
||||||
$contextOrder->proceedToNext();
|
$contextOrder->proceedToNext();
|
||||||
$contextOrder->proceedToNext();
|
$contextOrder->proceedToNext();
|
||||||
$contextOrder->proceedToNext();
|
$contextOrder->proceedToNext();
|
||||||
|
Reference in New Issue
Block a user