Skip to content

Instantly share code, notes, and snippets.

@geshan
Created March 17, 2016 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geshan/948631b7ddcb7cb630bf to your computer and use it in GitHub Desktop.
Save geshan/948631b7ddcb7cb630bf to your computer and use it in GitHub Desktop.
simple-unit-test
<?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