/** * @covers Cilex\Store\Transaction::getTotalValue * @covers Cilex\Store\Transaction::add * @covers Cilex\Store\Transaction::addDiscount * @covers Cilex\Store\Transaction::getSubTotal */ public function testGetTotalValueWithDiscount() { $this->object->add(1.25); $this->object->add(1.25); $this->object->addDiscount(20, $this->object->getSubTotal()); $this->assertEquals(2.0, $this->object->getTotalValue()); }
/** * {@inheritDoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $productsToBuy = $input->getArgument(self::ARGUMENT_PRODUCTS_TO_BUY); $discount = $input->getArgument(self::ARGUMENT_DISCOUNT); $locale = $input->getArgument(self::ARGUMENT_LOCALE); //create a new transaction $transaction = new \Cilex\Store\Transaction(new \Cilex\Store\Products()); //set locale $locale ? setlocale(LC_MONETARY, $locale) : false; if ($productsToBuy) { foreach ($productsToBuy as $product) { //add products $transaction->addProduct($product, $this->products[$product]); } } //if a deposit has been made if ($discount && $discount > 0) { $transaction->addDiscount((int) $discount, (double) $transaction->getSubTotal()); } //output $output->writeln($transaction->getReceipt()); }