Skip to content

Instantly share code, notes, and snippets.

@mageekguy
Created November 13, 2012 12:54
Show Gist options
  • Save mageekguy/4065624 to your computer and use it in GitHub Desktop.
Save mageekguy/4065624 to your computer and use it in GitHub Desktop.
<?php
namespace tests\units;
require __DIR__ . '/../../order.php';
require __DIR__ . '/mageekguy.atoum.phar';
use
mageekguy\atoum
;
class order extends atoum\test
{
public function test__construct()
{
$this
->if($order = new \order())
->then
->array($order->getArticles())->isEmpty()
;
}
public function testAddArticle()
{
$this
->if($order = new \order)
->then
->object($order->addArticle($reference1 = uniqid(), $quantity1 = rand(1, PHP_INT_MAX)))->isIdenticalTo($order)
->array($order->getArticles())->containsValues(array($reference1 => $quantity1))
->object($order->addArticle($reference2 = uniqid(), $quantity2 = rand(1, PHP_INT_MAX)))->isIdenticalTo($order)
->array($order->getArticles())->containsValues(array($reference2 => $quantity2))
;
}
public function testUpdateQuantity()
{
$this
->if($order = new \order())
->and($order->addArticle($reference1 = uniqid(), 1))
->and($order->addArticle($reference2 = uniqid(), 2))
->then
->object($order->updateQuantity($reference1, $quantity1 = rand(2, PHP_INT_MAX)))->isIdenticalTo($order)
->array($order->getArticles())->containsValues(array($reference1 => $quantity1))
->exception(function() use ($order) { $order->updateQuantity(uniqid(), rand(1, PHP_INT_MAX)); })
->isInstanceOf('InvalidArgumentException')
->hasMessage('Reference not ordered')
;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment