Example #1
0
 public function testItCanRepaintFromBlackToRed()
 {
     $car = new Example\Car(new Example\BlackBrush());
     $car->repaint();
     $this->assertEquals('Red', $car->getCurrentColor());
 }
Example #2
0
<?php

require 'car.php';
use DesignPatterns\State\Example\Car as Example;
// Initialize car with Red Brush
$car = new Example\Car(new Example\RedBrush());
echo 'Initial car color: ' . $car->getCurrentColor() . "\n";
// Red
// Repaint car (Red Brush should know which brush should be used next)
$car->repaint();
echo 'Color after repaint: ' . $car->getCurrentColor();
// Black