Created
March 17, 2016 06:59
-
-
Save geshan/948631b7ddcb7cb630bf to your computer and use it in GitHub Desktop.
simple-unit-test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace DataProvider\Example\Test; | |
use DataProvider\Example\Checkout; | |
use PHPUnit_Framework_TestCase; | |
/** | |
* Checkout test for Cash and Credit card. | |
*/ | |
class CheckoutTest extends PHPUnit_Framework_TestCase | |
{ | |
/** | |
* @var Checkout | |
*/ | |
protected $checkout; | |
public function setup() | |
{ | |
$this->checkout = new Checkout(); | |
} | |
/** | |
* Data provider for testCalculateTotal | |
* variables are in the order of | |
* $paymentMethod, $expectedTotal. | |
* | |
* @return type | |
*/ | |
public function paymentMethodProvider() | |
{ | |
return [ | |
['Cash', 100.00], | |
['Credit Card', 95.00], | |
]; | |
} | |
/** | |
* Test to check if the order total is calculated correctly | |
* for given payment method. | |
* | |
* @param string $paymentMethod | |
* @param float $expectedTotal | |
* | |
* @dataProvider paymentMethodProvider | |
*/ | |
public function testCalculateTotal($paymentMethod, $expectedTotal) | |
{ | |
$this->checkout->calculateTotal($paymentMethod); | |
$this->assertEquals( | |
$this->checkout->getTotal(), | |
$expectedTotal, | |
sprintf('Testing total calculation for %s.', $paymentMethod) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment