$output = []; foreach ($codes as $code) { // @TODO create an actual $product, and initialize it $output[] = $product->getShopProductCode() . ' - ' . $product->getShopDescription(); } return implode(PHP_EOL, $output); } } interface ProductInterface { public function initialize($code); public function getShopProductCode(); public function getShopDescription(); } } namespace MyCompanyShop { use ShopingCartFramework\ProductInterface; // @TODO implement MyShopProduct prototype } namespace { use ShopingCartFramework\Shop; use MyCompanyShop\MyShopProduct; $mockWebService = function ($code) { static $data = ['BumperSticker1' => 'Cool bumper sticker', 'CoffeeTableBook5' => 'Coffee Table book']; return $data[$code]; }; $shop = new Shop(new MyShopProduct($mockWebService)); $productsToList = ['BumperSticker1', 'CoffeeTableBook5']; echo $shop->listProducts($productsToList); // simulation of Shopping Cart Listings Page }
public function getShopProductCode(); public function getShopDescription(); } interface ShippingMethodInterface { public function getName(); public function getCostEstimate($miles, ProductInterface $product); } } namespace MyCompanyShop { use ShopingCartFramework\ShopFactoryInterface; use ShopingCartFramework\ProductInterface; use ShopingCartFramework\ShippingMethodInterface; // @TODO Implement the abstract factory MyShopProductFactory // @TODO Implement the product MyShopProduct // @TODO Implement Shipping Method MyShippingMethod } namespace { use ShopingCartFramework\Shop; use MyCompanyShop\MyShopProductFactory; $productData = ['BumperSticker1' => ['Bumper Sticker Item #1', 1], 'BumperSticker3' => ['Bumper Sticker Item #3', 1], 'BumperSticker5' => ['Bumper Sticker Item #5', 1], 'CoffeeTableBook6' => ['Coffee Table Book Item #6 (500 pages)', 5], 'CoffeeTableBook7' => ['Coffee Table Book Item #7 (300 pages)', 3], 'CoffeeTableBook9' => ['Coffee Table Book Item #9 (900 pages)', 9]]; $shippingMethodData = ['UPS' => [1.4, 1.1], 'FEXED' => [2.2, 1.3]]; $shop = new Shop(new MyShopProductFactory($productData, $shippingMethodData)); $targetOutput = <<<EOS BumperSticker1 - Bumper Sticker Item #1 / via: UPS, cost: \$15.1 CoffeeTableBook6 - Coffee Table Book Item #6 (500 pages) / via: UPS, cost: \$19.5 EOS; // simulation of Shopping Cart Listings Page $actualOutput = $shop->listProductsWithShippingCost(['BumperSticker1', 'CoffeeTableBook6'], 'UPS', 10); assert($actualOutput == $targetOutput); }
interface ProductFactoryInterface { public function createProduct($productCode); } interface ProductInterface { public function getShopProductCode(); public function getShopDescription(); } } namespace MyCompanyShop { use ShopingCartFramework\ProductFactoryInterface; use ShopingCartFramework\ProductInterface; // @TODO implement MyShopProductFactory with internal database of: // $database = [ // 'BumperSticker1' => 'Cool bumper sticker', // 'CoffeeTableBook5' => 'Coffee Table book', // ]; // @TODO implement MyShopProduct } namespace { use ShopingCartFramework\Shop; use MyCompanyShop\MyShopProductFactory; $shop = new Shop(new MyShopProductFactory()); $productsToList = ['BumperSticker1', 'CoffeeTableBook5']; $targetOutput = <<<EOS BumperSticker1 - Cool bumper sticker CoffeeTableBook5 - Coffee Table book EOS; assert($targetOutput == $shop->listProducts($productsToList)); }