-
-
Save anonymous/88399d23a9c2871f76c3 to your computer and use it in GitHub Desktop.
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
/** | |
* Class ShoppingCartTest | |
* | |
* @package ShoppingCart\test\Entity | |
*/ | |
class ShoppingCartTest extends \PHPUnit_Framework_TestCase | |
{ | |
/** | |
* @dataProvider productProvider | |
*/ | |
public function testAdd($productArr) | |
{ | |
$ShoppingCart = new ShoppingCart($this->mockTransitory($productArr)); | |
foreach ($productArr as $item) { | |
$ShoppingCart->add($item['product'], $item['quantity']); | |
} | |
foreach ($productArr as $item) { | |
$this->assertEquals($item['quantity'], $ShoppingCart->quantityByItem($item['product'])); | |
} | |
} | |
public function productProvider() | |
{ | |
return [ | |
[ | |
[ | |
[ | |
'product' => $this->productFactory(0), | |
'quantity' => 10, | |
], | |
[ | |
'product' => $this->productFactory(1), | |
'quantity' => 6 | |
], | |
], | |
] | |
]; | |
} | |
private function productFactory($index) | |
{ | |
$productArr[] = | |
new Product( | |
); | |
$productArr[] = | |
new Product( | |
); | |
return $productArr[$index]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment