コード例 #1
0
ファイル: car_test.php プロジェクト: ymnl007/designpatterns
 public function testItCanRepaintFromBlackToRed()
 {
     $car = new Example\Car(new Example\BlackBrush());
     $car->repaint();
     $this->assertEquals('Red', $car->getCurrentColor());
 }
コード例 #2
0
ファイル: car_usage.php プロジェクト: ymnl007/designpatterns
<?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