Esempio n. 1
0
 public function testCheckoutCanUseStrategies()
 {
     $price = 100;
     $grandPrice = Example\Checkout::calculate($price, new Example\EuropePricingStrategy(), new Example\VipPricingStrategy());
     $this->assertEquals(110, $grandPrice);
 }
Esempio n. 2
0
<?php

require 'checkout.php';
use DesignPatterns\Strategy\Example\Checkout as Example;
// 20
echo 'The taxes amount for a $100 purchase from European client is: ' . Example\EuropePricingStrategy::calculateTaxes(100) . "\n";
// -10
echo 'A discount for $100 purchase from a VIP client is: ' . Example\VipPricingStrategy::negativeDiscount(100) . "\n";
// 110
echo 'The grand price for a $100 purchase for VIP Client from Europe is: ' . Example\Checkout::calculate(100, new Example\EuropePricingStrategy(), new Example\VipPricingStrategy());