Skip to content

Commit

Permalink
Tweak specs, accept only integers for money values
Browse files Browse the repository at this point in the history
  • Loading branch information
Paweł Jędrzejewski committed Mar 9, 2013
1 parent a1eff40 commit d8450c5
Show file tree
Hide file tree
Showing 22 changed files with 335 additions and 112 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Expand Up @@ -5,10 +5,14 @@ php:
- 5.4
- 5.5

before_script: composer install --dev --prefer-source
matrix:
allow_failure:
- php: 5.5

before_script: composer install --dev --prefer-source > /dev/null

script: bin/phpspec run -fpretty --verbose

notifications:
irc: "irc.freenode.org#sylius-dev"
email: "travis-ci@sylius.org"
email: "travis-ci@sylius.org"
irc: "irc.freenode.org#sylius-dev"
37 changes: 19 additions & 18 deletions CHANGELOG.md
@@ -1,30 +1,31 @@
CHANGELOG
=========

### v0.3.0 (2013-xx-xx)
### v0.3.0

* Remove `CartOperator` & `CartOperatorInterface`,
* Remove `CartOperator` & `CartOperatorInterface`.
* Introduce `SyliusCartEvents` & event listeners.
* Removed the ``sylius_cart`` prefix from services and models, used ``sylius`` instead.
* All money values are represented as integers.

### v0.2.0 (2012-12-27)
### v0.2.0

* Introduce default cart entity,
* Use Doctrine RTEL to map interfaces instead of real entities,
* Rename `CartController::showAction` to `CartController::summaryAction`,
* Renamed `SyliusCartBundle:Cart:show.html` template to ``SyliusCartBundle:Cart:summary.html`,
* Introduce default cart entity.
* Use Doctrine RTEL to map interfaces instead of real entities.
* Rename `CartController::showAction` to `CartController::summaryAction`.
* Renamed `SyliusCartBundle:Cart:show.html` template to ``SyliusCartBundle:Cart:summary.html`.
* Add base controller.

### v0.1.0 (2012-12-05)
### v0.1.0

* First development release,
* Introduced ItemResolvingException,
* More complete set of [phpspec2](http://phpspec.net) examples,
* Changed configuration schema,
* Bundle now uses [SyliusResourceBundle](http://github.com/Sylius/SyliusResourceBundle) for model persistence,
* Models now depend on Doctrine collections,
* New controller,
* Renamed **Item** to **CartItem**,
* Renamed **ItemType** to **CartItemType**,
* Introduce specs with [phpspec2](http://phpspec.net),
* First development release.
* Introduced ItemResolvingException.
* More complete set of [phpspec2](http://phpspec.net) examples.
* Changed configuration schema.
* Bundle now uses [SyliusResourceBundle](http://github.com/Sylius/SyliusResourceBundle) for model persistence.
* Models now depend on Doctrine collections.
* New controller.
* Renamed **Item** to **CartItem**.
* Renamed **ItemType** to **CartItemType**.
* Introduce specs with [phpspec2](http://phpspec.net).
* Renamed **CartFormType** to **CartType** to be consistent.
7 changes: 4 additions & 3 deletions EventListener/CartListener.php
Expand Up @@ -12,12 +12,11 @@
namespace Sylius\Bundle\CartBundle\EventListener;

use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Validator\ValidatorInterface;

use Sylius\Bundle\CartBundle\Event\CartEvent;
use Sylius\Bundle\CartBundle\Model\CartInterface;
use Sylius\Bundle\CartBundle\SyliusCartEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Validator\ValidatorInterface;

/**
* Cart & item changes listener.
Expand All @@ -34,6 +33,8 @@ class CartListener implements EventSubscriberInterface
private $cartManager;

/**
* Validator.
*
* @var ValidatorInterface
*/
private $validator;
Expand Down
27 changes: 24 additions & 3 deletions Model/Cart.php
Expand Up @@ -101,6 +101,8 @@ public function isLocked()
public function setLocked($locked)
{
$this->locked = $locked;

return $this;
}

/**
Expand All @@ -121,6 +123,8 @@ public function setTotalItems($totalItems)
}

$this->totalItems = $totalItems;

return $this;
}

/**
Expand All @@ -133,6 +137,8 @@ public function changeTotalItems($amount)
if (0 > $this->totalItems) {
$this->totalItems = 0;
}

return $this;
}

/**
Expand All @@ -154,14 +160,19 @@ public function getItems()
/**
* {@inheritdoc}
*/
public function setItems(Collection $items){
public function setItems(Collection $items)
{
foreach($this->items as $item){
$this->removeItem($item);
}

foreach($items as $item){
$this->addItem($item);
}

return $this;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -199,10 +210,11 @@ public function addItem(CartItemInterface $item)

$this->items->add($item);
$item->setCart($this);

return $this;
}


/**
* {@inheritdoc}
*/
Expand All @@ -213,6 +225,7 @@ public function removeItem(CartItemInterface $item)

$item->setCart(null);
}

return $this;
}

Expand All @@ -229,6 +242,8 @@ public function getTotal()
public function setTotal($total)
{
$this->total = $total;

return $this;
}

public function calculateTotal()
Expand All @@ -241,6 +256,8 @@ public function calculateTotal()

$this->total += $item->getTotal();
}

return $this;
}

/**
Expand All @@ -265,6 +282,8 @@ public function getExpiresAt()
public function setExpiresAt(\DateTime $expiresAt = null)
{
$this->expiresAt = $expiresAt;

return $this;
}

/**
Expand All @@ -276,5 +295,7 @@ public function incrementExpiresAt()
$expiresAt->add(new \DateInterval('PT3H'));

$this->expiresAt = $expiresAt;

return $this;
}
}
24 changes: 24 additions & 0 deletions Model/CartItem.php
Expand Up @@ -20,6 +20,8 @@ class CartItem implements CartItemInterface
{
/**
* Cart item id.
*
* @var mixed
*/
protected $id;

Expand Down Expand Up @@ -83,6 +85,8 @@ public function getCart()
public function setCart(CartInterface $cart = null)
{
$this->cart = $cart;

return $this;
}

/**
Expand All @@ -98,7 +102,15 @@ public function getQuantity()
*/
public function setQuantity($quantity)
{
if (!is_integer($quantity)) {
throw new \InvalidArgumentException(
sprintf('Cart item accepts only integer as quantity, "%s" given.', gettype($quantity))
);
}

$this->quantity = $quantity;

return $this;
}

/**
Expand All @@ -114,7 +126,15 @@ public function getUnitPrice()
*/
public function setUnitPrice($unitPrice)
{
if (!is_integer($unitPrice)) {
throw new \InvalidArgumentException(
sprintf('Cart item accepts only integer as unit price, "%s" given.', gettype($unitPrice))
);
}

$this->unitPrice = $unitPrice;

return $this;
}

/**
Expand All @@ -131,6 +151,8 @@ public function getTotal()
public function setTotal($total)
{
$this->total = $total;

return $this;
}

/**
Expand All @@ -139,6 +161,8 @@ public function setTotal($total)
public function calculateTotal()
{
$this->total = $this->quantity * $this->unitPrice;

return $this;
}

/**
Expand Down
11 changes: 3 additions & 8 deletions README.md
Expand Up @@ -2,7 +2,7 @@ SyliusCartBundle [![Build status...](https://secure.travis-ci.org/Sylius/SyliusC
================

Flexible cart engine for Symfony2. Should be considered as a base for building solution that fits your exact needs.
[Read the documentation](http://sylius.readthedocs.org/en/latest/bundles/SyliusCartBundle/index.html) to know more features.
[Read the documentation](http://docs.sylius.org/en/latest/bundles/SyliusCartBundle/index.html) to know more features.

Sylius
------
Expand All @@ -22,17 +22,12 @@ $ bin/phpspec run -f pretty
Documentation
-------------

Documentation is available on [**readthedocs.org**](http://sylius.readthedocs.org/en/latest/bundles/SyliusCartBundle/index.html).

Code examples
-------------

If you want to see working implementation, try out the [Sylius sandbox application](http://github.com/Sylius/Sylius-Sandbox).
Documentation is available on [**docs.sylius.org**](http://docs.sylius.org/en/latest/bundles/SyliusCartBundle/index.html).

Contributing
------------

All informations about contributing to Sylius can be found on [this page](http://sylius.readthedocs.org/en/latest/contributing/index.html).
All informations about contributing to Sylius can be found on [this page](http://docs.sylius.org/en/latest/contributing/index.html).

Mailing lists
-------------
Expand Down
17 changes: 13 additions & 4 deletions spec/Sylius/Bundle/CartBundle/Controller/CartController.php
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace spec\Sylius\Bundle\CartBundle\Controller;

use PHPSpec2\ObjectBehavior;
Expand All @@ -16,22 +25,22 @@ function let()
$this->beConstructedWith('sylius', 'cart', 'SyliusCartBundle:Cart');
}

function it_should_be_initializable()
function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\Controller\CartController');
}

function it_should_be_a_controller()
function it_is_a_Symfony_controller()
{
$this->shouldHaveType('Symfony\Bundle\FrameworkBundle\Controller\Controller');
}

function it_should_be_Sylius_resource_controller()
function it_extends_Sylius_resource_controller()
{
$this->shouldHaveType('Sylius\Bundle\ResourceBundle\Controller\ResourceController');
}

function it_should_extend_base_Sylius_cart_bundle_controller()
function it_extends_base_Sylius_cart_bundle_controller()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\Controller\Controller');
}
Expand Down
18 changes: 13 additions & 5 deletions spec/Sylius/Bundle/CartBundle/Controller/CartItemController.php
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace spec\Sylius\Bundle\CartBundle\Controller;

use PHPSpec2\ObjectBehavior;
Expand All @@ -16,24 +25,23 @@ function let()
$this->beConstructedWith('sylius_cart', 'item', 'SyliusCartBundle:CartItem');
}

function it_should_be_initializable()
function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\Controller\CartItemController');
}

function it_should_be_a_controller()
function it_is_a_controller()
{
$this->shouldHaveType('Symfony\Bundle\FrameworkBundle\Controller\Controller');
}

function it_should_be_Sylius_resource_controller()
function it_extends_Sylius_resource_controller()
{
$this->shouldHaveType('Sylius\Bundle\ResourceBundle\Controller\ResourceController');
}

function it_should_extend_base_Sylius_cart_bundle_controller()
function it_extends_base_Sylius_cart_bundle_controller()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\Controller\Controller');
}
}

0 comments on commit d8450c5

Please sign in to comment.