Created
June 17, 2014 04:52
-
-
Save sk8terboi87/062c66ffbc1514e8973a to your computer and use it in GitHub Desktop.
ppt
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 | |
Class Pay { | |
public function doPay($cart) { | |
return '112345'; | |
} | |
} |
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 | |
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; | |
} | |
} |
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 | |
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); | |
} | |
} |
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 | |
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