$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 }
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)); }