Skip to content

Instantly share code, notes, and snippets.

@sk8terboi87
Created June 17, 2014 04:52
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 sk8terboi87/062c66ffbc1514e8973a to your computer and use it in GitHub Desktop.
Save sk8terboi87/062c66ffbc1514e8973a to your computer and use it in GitHub Desktop.
ppt
<?php
Class Pay {
public function doPay($cart) {
return '112345';
}
}
<?php
require 'Pay.php';
Class Cart {
private $items = [
'Item 1',
'Item 2',
'Item 3'
];
private $cart = [];
public function __construct() {
}
public function add($item, $pay) {
if($item === null) {
return "Item is empty";
}
if($this->checkExists($item) === false) {
return 'Item doesn"t exists';
}
if($this->alreadyInCart($item) === true) {
return 'Item already added';
}
array_push($this->cart, $item);
$pay->doPay($this->cart);
}
public function checkExists($item) {
if(in_array($item, $this->items)) {
return true;
}
return false;
}
public function alreadyInCart($item) {
if(in_array($item, $this->cart)) {
return true;
}
return false;
}
}
<?php
require "Cart.php";
Class CartTest extends PHPUnit_Framework_TestCase {
protected function setUp() {
$this->payMock = $this->getMock('Pay', array('doPay'));
}
public function testItemIsNotEmpty() {
// Arrange
$c = new Cart(null);
// Act
$return = $c->add(null, $this->payMock);
// Assert
$this->assertEquals('Item is empty', $return);
}
public function testItemExistsInItemList() {
$c = new Cart(null);
$return = $c->add('test', $this->payMock);
$this->assertEquals('Item doesn"t exists', $return);
}
public function testItemAlreadyAddToCart() {
$c = new Cart(null);
$c->add('Item 1', $this->payMock);
$return = $c->add('Item 1', $this->payMock);
$this->assertEquals('Item already added', $return);
}
public function testItemNotExceedsMaximumLimit() {
}
public function testItemsSentToPay() {
$c = new Cart();
$this->payMock->expects($this->once())
->method('doPay')
->with($this->equalTo(['Item 1']));
$c->add('Item 1', $this->payMock);
}
}
<?php
Class Item {
public function getItem($item) {
if($item === null) {
return "Item is empty";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment