Permalink
Browse files

Merge branch 'master' of git://github.com/Sylius/SyliusCartBundle

Conflicts:
	spec/Sylius/Bundle/CartBundle/Model/Cart.php
  • Loading branch information...
2 parents 0dcc80b + d8450c5 commit ab3b1d3da3cdcfd226c994ac3a1f25ecd2957372 @mykehsd committed Mar 27, 2013
Showing with 472 additions and 210 deletions.
  1. +7 −3 .travis.yml
  2. +20 −18 CHANGELOG.md
  3. +10 −9 Controller/CartController.php
  4. +15 −14 Controller/CartItemController.php
  5. +4 −2 Controller/Controller.php
  6. +2 −2 DependencyInjection/Configuration.php
  7. +14 −13 DependencyInjection/SyliusCartExtension.php
  8. +4 −3 EventListener/CartListener.php
  9. +24 −1 Model/Cart.php
  10. +24 −0 Model/CartItem.php
  11. +8 −0 Provider/CartProvider.php
  12. +8 −0 Provider/CartProviderInterface.php
  13. +3 −8 README.md
  14. +13 −13 Resources/config/driver/doctrine/orm.xml
  15. +4 −4 Resources/config/engine/twig.xml
  16. +5 −5 Resources/config/routing.yml
  17. +21 −21 Resources/config/services.xml
  18. +2 −2 Resources/config/validation.xml
  19. +2 −2 SyliusCartBundle.php
  20. +10 −10 SyliusCartEvents.php
  21. +13 −2 Twig/SyliusCartExtension.php
  22. +14 −5 spec/Sylius/Bundle/CartBundle/Controller/CartController.php
  23. +13 −5 spec/Sylius/Bundle/CartBundle/Controller/CartItemController.php
  24. +11 −2 spec/Sylius/Bundle/CartBundle/DependencyInjection/SyliusCartExtension.php
  25. +12 −3 spec/Sylius/Bundle/CartBundle/Entity/Cart.php
  26. +12 −3 spec/Sylius/Bundle/CartBundle/Entity/CartItem.php
  27. +12 −3 spec/Sylius/Bundle/CartBundle/Entity/DefaultCart.php
  28. +10 −1 spec/Sylius/Bundle/CartBundle/EventListener/CartListener.php
  29. +10 −1 spec/Sylius/Bundle/CartBundle/EventListener/FlashListener.php
  30. +13 −4 spec/Sylius/Bundle/CartBundle/Form/Type/CartItemType.php
  31. +13 −4 spec/Sylius/Bundle/CartBundle/Form/Type/CartType.php
  32. +52 −19 spec/Sylius/Bundle/CartBundle/Model/Cart.php
  33. +32 −9 spec/Sylius/Bundle/CartBundle/Model/CartItem.php
  34. +16 −7 spec/Sylius/Bundle/CartBundle/Provider/CartProvider.php
  35. +14 −5 spec/Sylius/Bundle/CartBundle/Storage/SessionCartStorage.php
  36. +11 −2 spec/Sylius/Bundle/CartBundle/SyliusCartBundle.php
  37. +14 −5 spec/Sylius/Bundle/CartBundle/Twig/SyliusCartExtension.php
View
10 .travis.yml
@@ -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"
View
38 CHANGELOG.md
@@ -1,29 +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.
View
19 Controller/CartController.php
@@ -64,14 +64,14 @@ public function saveAction(Request $request)
$form = $this->createForm('sylius_cart', $cart);
if ($form->bind($request)->isValid()) {
- /* @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
- $dispatcher = $this->container->get('event_dispatcher');
-
$event = new CartEvent($cart);
$event->isFresh(true);
- $dispatcher->dispatch(SyliusCartEvents::CART_SAVE_INITIALIZE, $event);
- $dispatcher->dispatch(SyliusCartEvents::CART_SAVE_COMPLETED, new FlashEvent());
+ // Update models
+ $this->dispatchEvent(SyliusCartEvents::CART_SAVE_INITIALIZE, $event);
+
+ // Write flash message
+ $this->dispatchEvent(SyliusCartEvents::CART_SAVE_COMPLETED, new FlashEvent());
}
return $this->renderResponse('summary.html', array(
@@ -88,10 +88,11 @@ public function saveAction(Request $request)
*/
public function clearAction()
{
- /* @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
- $dispatcher = $this->container->get('event_dispatcher');
- $dispatcher->dispatch(SyliusCartEvents::CART_CLEAR_INITIALIZE, new CartEvent($this->getCurrentCart()));
- $dispatcher->dispatch(SyliusCartEvents::CART_CLEAR_COMPLETED, new FlashEvent());
+ // Update models
+ $this->dispatchEvent(SyliusCartEvents::CART_CLEAR_INITIALIZE, new CartEvent($this->getCurrentCart()));
+
+ // Write flash message
+ $this->dispatchEvent(SyliusCartEvents::CART_CLEAR_COMPLETED, new FlashEvent());
return $this->redirectToCartSummary();
}
View
29 Controller/CartItemController.php
@@ -52,13 +52,11 @@ public function addAction(Request $request)
$cart = $this->getCurrentCart();
$emptyItem = $this->createNew();
- /* @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
- $dispatcher = $this->container->get('event_dispatcher');
-
try {
$item = $this->getResolver()->resolve($emptyItem, $request);
} catch (ItemResolvingException $exception) {
- $dispatcher->dispatch(SyliusCartEvents::ITEM_ADD_ERROR, new FlashEvent($exception->getMessage()));
+ // Write flash message
+ $this->dispatchEvent(SyliusCartEvents::ITEM_ADD_ERROR, new FlashEvent($exception->getMessage()));
return $this->redirectToCartSummary();
}
@@ -67,10 +65,12 @@ public function addAction(Request $request)
$event->isFresh(true);
$event->isValid(false);
- $dispatcher->dispatch(SyliusCartEvents::ITEM_ADD_INITIALIZE, $event);
- $dispatcher->dispatch(SyliusCartEvents::CART_SAVE_INITIALIZE, $event);
+ // Update models
+ $this->dispatchEvent(SyliusCartEvents::ITEM_ADD_INITIALIZE, $event);
+ $this->dispatchEvent(SyliusCartEvents::CART_SAVE_INITIALIZE, $event);
- $dispatcher->dispatch(SyliusCartEvents::ITEM_ADD_COMPLETED, new FlashEvent());
+ // Write flash message
+ $this->dispatchEvent(SyliusCartEvents::ITEM_ADD_COMPLETED, new FlashEvent());
return $this->redirectToCartSummary();
}
@@ -91,21 +91,22 @@ public function removeAction($id)
$cart = $this->getCurrentCart();
$item = $this->getRepository()->find($id);
- /* @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
- $dispatcher = $this->container->get('event_dispatcher');
-
if (!$item || false === $cart->hasItem($item)) {
- $dispatcher->dispatch(SyliusCartEvents::ITEM_REMOVE_ERROR, new FlashEvent());
+ // Write flash message
+ $this->dispatchEvent(SyliusCartEvents::ITEM_REMOVE_ERROR, new FlashEvent());
return $this->redirectToCartSummary();
}
$event = new CartItemEvent($cart, $item);
$event->isFresh(true);
- $dispatcher->dispatch(SyliusCartEvents::ITEM_REMOVE_INITIALIZE, $event);
- $dispatcher->dispatch(SyliusCartEvents::CART_SAVE_INITIALIZE, $event);
- $dispatcher->dispatch(SyliusCartEvents::ITEM_REMOVE_COMPLETED, new FlashEvent());
+ // Update models
+ $this->dispatchEvent(SyliusCartEvents::ITEM_REMOVE_INITIALIZE, $event);
+ $this->dispatchEvent(SyliusCartEvents::CART_SAVE_INITIALIZE, $event);
+
+ // Write flash message
+ $this->dispatchEvent(SyliusCartEvents::ITEM_REMOVE_COMPLETED, new FlashEvent());
return $this->redirectToCartSummary();
}
View
6 Controller/Controller.php
@@ -60,7 +60,9 @@ protected function getCurrentCart()
*/
protected function getProvider()
{
- return $this->get('sylius_cart.provider');
+
+ return $this->container->get('sylius.cart_provider');
+
}
/**
@@ -71,6 +73,6 @@ protected function getProvider()
*/
protected function getResolver()
{
- return $this->get('sylius_cart.resolver');
+ return $this->container->get('sylius.cart_resolver');
}
}
View
4 DependencyInjection/Configuration.php
@@ -39,9 +39,9 @@ public function getConfigTreeBuilder()
->children()
->scalarNode('driver')->isRequired()->cannotBeEmpty()->end()
->scalarNode('engine')->defaultValue('twig')->end()
- ->scalarNode('provider')->defaultValue('sylius_cart.provider.default')->end()
+ ->scalarNode('provider')->defaultValue('sylius.cart_provider.default')->end()
->scalarNode('resolver')->isRequired()->cannotBeEmpty()->end()
- ->scalarNode('storage')->defaultValue('sylius_cart.storage.session')->end()
+ ->scalarNode('storage')->defaultValue('sylius.cart_storage.session')->end()
->end()
;
View
27 DependencyInjection/SyliusCartExtension.php
@@ -47,38 +47,39 @@ public function load(array $config, ContainerBuilder $container)
if ('twig' !== $engine) {
throw new \InvalidArgumentException(sprintf('Templating engine "%s" is unsupported for by SyliusCartBundle', $config['engine']));
}
+
+ $container->setParameter('sylius_cart.driver', $driver);
$loader->load(sprintf('driver/%s.xml', $driver));
$loader->load(sprintf('engine/%s.xml', $engine));
- $container->setParameter('sylius_cart.driver', $driver);
- $container->setParameter('sylius_cart.engine', $engine);
+ $container->setParameter('sylius.engine', $engine);
- $container->setAlias('sylius_cart.provider', $config['provider']);
- $container->setAlias('sylius_cart.resolver', $config['resolver']);
- $container->setAlias('sylius_cart.storage', $config['storage']);
+ $container->setAlias('sylius.cart_provider', $config['provider']);
+ $container->setAlias('sylius.cart_resolver', $config['resolver']);
+ $container->setAlias('sylius.cart_storage', $config['storage']);
$classes = $config['classes'];
$cartClasses = $classes['cart'];
$cartItemClasses = $classes['item'];
- $container->setParameter('sylius_cart.controller.cart.class', $cartClasses['controller']);
- $container->setParameter('sylius_cart.form.type.cart.class', $cartClasses['form']);
+ $container->setParameter('sylius.controller.cart.class', $cartClasses['controller']);
+ $container->setParameter('sylius.form.type.cart.class', $cartClasses['form']);
if (isset($cartClasses['model'])) {
- $container->setParameter('sylius_cart.model.cart.class', $cartClasses['model']);
+ $container->setParameter('sylius.model.cart.class', $cartClasses['model']);
}
if (isset($cartClasses['repository'])) {
- $container->setParameter('sylius_cart.repository.cart.class', $cartClasses['repository']);
+ $container->setParameter('sylius.repository.cart.class', $cartClasses['repository']);
}
- $container->setParameter('sylius_cart.model.item.class', $cartItemClasses['model']);
- $container->setParameter('sylius_cart.controller.item.class', $cartItemClasses['controller']);
- $container->setParameter('sylius_cart.form.type.item.class', $cartItemClasses['form']);
+ $container->setParameter('sylius.model.cart_item.class', $cartItemClasses['model']);
+ $container->setParameter('sylius.controller.cart_item.class', $cartItemClasses['controller']);
+ $container->setParameter('sylius.form.type.cart_item.class', $cartItemClasses['form']);
if (isset($cartItemClasses['repository'])) {
- $container->setParameter('sylius_cart.repository.item.class', $cartItemClasses['repository']);
+ $container->setParameter('sylius.repository.cart_item.class', $cartItemClasses['repository']);
}
$loader->load('services.xml');
View
7 EventListener/CartListener.php
@@ -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.
@@ -34,6 +33,8 @@ class CartListener implements EventSubscriberInterface
private $cartManager;
/**
+ * Validator.
+ *
* @var ValidatorInterface
*/
private $validator;
View
25 Model/Cart.php
@@ -109,6 +109,8 @@ public function isLocked()
public function setLocked($locked)
{
$this->locked = $locked;
+
+ return $this;
}
/**
@@ -129,6 +131,8 @@ public function setTotalItems($totalItems)
}
$this->totalItems = $totalItems;
+
+ return $this;
}
/**
@@ -141,6 +145,8 @@ public function changeTotalItems($amount)
if (0 > $this->totalItems) {
$this->totalItems = 0;
}
+
+ return $this;
}
/**
@@ -196,7 +202,15 @@ public function getItems()
*/
public function setItems(Collection $items)
{
- $this->items = $items;
+ foreach($this->items as $item){
+ $this->removeItem($item);
+ }
+
+ foreach($items as $item){
+ $this->addItem($item);
+ }
+
+ return $this;
}
/**
@@ -240,6 +254,7 @@ public function addItem(CartItemInterface $item)
return $this;
}
+
/**
* {@inheritdoc}
*/
@@ -267,6 +282,8 @@ public function getTotal()
public function setTotal($total)
{
$this->total = $total;
+
+ return $this;
}
public function calculateTotal()
@@ -279,6 +296,8 @@ public function calculateTotal()
$this->total += $item->getTotal();
}
+
+ return $this;
}
/**
@@ -303,6 +322,8 @@ public function getExpiresAt()
public function setExpiresAt(\DateTime $expiresAt = null)
{
$this->expiresAt = $expiresAt;
+
+ return $this;
}
/**
@@ -314,5 +335,7 @@ public function incrementExpiresAt()
$expiresAt->add(new \DateInterval('PT3H'));
$this->expiresAt = $expiresAt;
+
+ return $this;
}
}
View
24 Model/CartItem.php
@@ -20,6 +20,8 @@ class CartItem implements CartItemInterface
{
/**
* Cart item id.
+ *
+ * @var mixed
*/
protected $id;
@@ -83,6 +85,8 @@ public function getCart()
public function setCart(CartInterface $cart = null)
{
$this->cart = $cart;
+
+ return $this;
}
/**
@@ -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;
}
/**
@@ -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;
}
/**
@@ -131,6 +151,8 @@ public function getTotal()
public function setTotal($total)
{
$this->total = $total;
+
+ return $this;
}
/**
@@ -139,6 +161,8 @@ public function setTotal($total)
public function calculateTotal()
{
$this->total = $this->quantity * $this->unitPrice;
+
+ return $this;
}
/**
View
8 Provider/CartProvider.php
@@ -68,6 +68,14 @@ public function __construct(CartStorageInterface $storage, ObjectManager $manage
/**
* {@inheritdoc}
*/
+ public function hasCart()
+ {
+ return null !== $this->cart;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function getCart()
{
if (null !== $this->cart) {
View
8 Provider/CartProviderInterface.php
@@ -22,6 +22,14 @@
interface CartProviderInterface
{
/**
+ * Returns true if a cart exists otherwise false.
+ * It does not create a new cart if none exists
+ *
+ * @return boolean
+ */
+ public function hasCart();
+
+ /**
* Returns current cart.
* If none found is by storage, it should create new one and save it.
*
View
11 README.md
@@ -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
------
@@ -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
-------------
View
26 Resources/config/driver/doctrine/orm.xml
@@ -17,37 +17,37 @@
http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
- <parameter key="sylius_cart.model.cart.class">Sylius\Bundle\CartBundle\Entity\DefaultCart</parameter>
+ <parameter key="sylius.model.cart.class">Sylius\Bundle\CartBundle\Entity\DefaultCart</parameter>
- <parameter key="sylius_cart.repository.cart.class">Sylius\Bundle\CartBundle\Entity\CartRepository</parameter>
- <parameter key="sylius_cart.repository.item.class">Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository</parameter>
+ <parameter key="sylius.repository.cart.class">Sylius\Bundle\CartBundle\Entity\CartRepository</parameter>
+ <parameter key="sylius.repository.cart_item.class">Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository</parameter>
</parameters>
<services>
- <service id="sylius_cart.manager.cart" alias="doctrine.orm.entity_manager" />
- <service id="sylius_cart.repository.cart" class="%sylius_cart.repository.cart.class%">
- <argument type="service" id="sylius_cart.manager.cart" />
+ <service id="sylius.manager.cart" alias="doctrine.orm.entity_manager" />
+ <service id="sylius.repository.cart" class="%sylius.repository.cart.class%">
+ <argument type="service" id="sylius.manager.cart" />
<argument type="service">
<service
- factory-service="sylius_cart.manager.cart"
+ factory-service="sylius.manager.cart"
factory-method="getClassMetadata"
class="Doctrine\ORM\Mapping\ClassMetadata"
>
- <argument>%sylius_cart.model.cart.class%</argument>
+ <argument>%sylius.model.cart.class%</argument>
</service>
</argument>
</service>
- <service id="sylius_cart.manager.item" alias="doctrine.orm.entity_manager" />
- <service id="sylius_cart.repository.item" class="%sylius_cart.repository.item.class%">
- <argument type="service" id="sylius_cart.manager.item" />
+ <service id="sylius.manager.cart_item" alias="doctrine.orm.entity_manager" />
+ <service id="sylius.repository.cart_item" class="%sylius.repository.cart_item.class%">
+ <argument type="service" id="sylius.manager.cart_item" />
<argument type="service">
<service
- factory-service="sylius_cart.manager.item"
+ factory-service="sylius.manager.cart_item"
factory-method="getClassMetadata"
class="Doctrine\ORM\Mapping\ClassMetadata"
>
- <argument>%sylius_cart.model.item.class%</argument>
+ <argument>%sylius.model.cart_item.class%</argument>
</service>
</argument>
</service>
View
8 Resources/config/engine/twig.xml
@@ -17,13 +17,13 @@
http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
- <parameter key="sylius_cart.twig.class">Sylius\Bundle\CartBundle\Twig\SyliusCartExtension</parameter>
+ <parameter key="sylius.cart_twig.class">Sylius\Bundle\CartBundle\Twig\SyliusCartExtension</parameter>
</parameters>
<services>
- <service id="sylius_cart.twig" class="%sylius_cart.twig.class%">
- <argument type="service" id="sylius_cart.provider" />
- <argument type="service" id="sylius_cart.repository.item" />
+ <service id="sylius.cart_twig" class="%sylius.cart_twig.class%">
+ <argument type="service" id="sylius.cart_provider" />
+ <argument type="service" id="sylius.repository.cart_item" />
<argument type="service" id="form.factory" />
<tag name="twig.extension" />
</service>
View
10 Resources/config/routing.yml
@@ -3,20 +3,20 @@
sylius_cart_summary:
pattern: /
- defaults: { _controller: sylius_cart.controller.cart:summaryAction }
+ defaults: { _controller: sylius.controller.cart:summaryAction }
sylius_cart_save:
pattern: /save
- defaults: { _controller: sylius_cart.controller.cart:saveAction }
+ defaults: { _controller: sylius.controller.cart:saveAction }
sylius_cart_clear:
pattern: /clear
- defaults: { _controller: sylius_cart.controller.cart:clearAction }
+ defaults: { _controller: sylius.controller.cart:clearAction }
sylius_cart_item_add:
pattern: /add
- defaults: { _controller: sylius_cart.controller.item:addAction }
+ defaults: { _controller: sylius.controller.cart_item:addAction }
sylius_cart_item_remove:
pattern: /{id}/remove
- defaults: { _controller: sylius_cart.controller.item:removeAction }
+ defaults: { _controller: sylius.controller.cart_item:removeAction }
View
42 Resources/config/services.xml
@@ -17,59 +17,59 @@
http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
- <parameter key="sylius_cart.provider.default.class">Sylius\Bundle\CartBundle\Provider\CartProvider</parameter>
- <parameter key="sylius_cart.storage.session.class">Sylius\Bundle\CartBundle\Storage\SessionCartStorage</parameter>
+ <parameter key="sylius.cart_provider.default.class">Sylius\Bundle\CartBundle\Provider\CartProvider</parameter>
+ <parameter key="sylius.cart_storage.session.class">Sylius\Bundle\CartBundle\Storage\SessionCartStorage</parameter>
- <parameter key="sylius_cart.cart_listener.class">Sylius\Bundle\CartBundle\EventListener\CartListener</parameter>
- <parameter key="sylius_cart.flash_listener.class">Sylius\Bundle\CartBundle\EventListener\FlashListener</parameter>
+ <parameter key="sylius.cart_listener.class">Sylius\Bundle\CartBundle\EventListener\CartListener</parameter>
+ <parameter key="sylius.cart_flash_listener.class">Sylius\Bundle\CartBundle\EventListener\FlashListener</parameter>
</parameters>
<services>
- <service id="sylius_cart.controller.cart" class="%sylius_cart.controller.cart.class%">
- <argument>sylius_cart</argument>
+ <service id="sylius.controller.cart" class="%sylius.controller.cart.class%">
+ <argument>sylius</argument>
<argument>cart</argument>
<argument>SyliusCartBundle:Cart</argument>
<call method="setContainer">
<argument type="service" id="service_container" />
</call>
</service>
- <service id="sylius_cart.controller.item" class="%sylius_cart.controller.item.class%">
- <argument>sylius_cart</argument>
- <argument>item</argument>
+ <service id="sylius.controller.cart_item" class="%sylius.controller.cart_item.class%">
+ <argument>sylius</argument>
+ <argument>cart_item</argument>
<argument>SyliusCartBundle:CartItem</argument>
<call method="setContainer">
<argument type="service" id="service_container" />
</call>
</service>
- <service id="sylius_cart.form.type.cart" class="%sylius_cart.form.type.cart.class%">
- <argument>%sylius_cart.model.cart.class%</argument>
+ <service id="sylius.form.type.cart" class="%sylius.form.type.cart.class%">
+ <argument>%sylius.model.cart.class%</argument>
<tag name="form.type" alias="sylius_cart" />
</service>
- <service id="sylius_cart.form.type.item" class="%sylius_cart.form.type.item.class%">
- <argument>%sylius_cart.model.item.class%</argument>
+ <service id="sylius.form.type.cart_item" class="%sylius.form.type.cart_item.class%">
+ <argument>%sylius.model.cart_item.class%</argument>
<tag name="form.type" alias="sylius_cart_item" />
</service>
- <service id="sylius_cart.provider.default" class="%sylius_cart.provider.default.class%">
- <argument type="service" id="sylius_cart.storage" />
- <argument type="service" id="sylius_cart.manager.cart" />
- <argument type="service" id="sylius_cart.repository.cart" />
+ <service id="sylius.cart_provider.default" class="%sylius.cart_provider.default.class%">
+ <argument type="service" id="sylius.cart_storage" />
+ <argument type="service" id="sylius.manager.cart" />
+ <argument type="service" id="sylius.repository.cart" />
</service>
- <service id="sylius_cart.storage.session" class="%sylius_cart.storage.session.class%">
+ <service id="sylius.cart_storage.session" class="%sylius.cart_storage.session.class%">
<argument type="service" id="session" />
</service>
- <service id="sylius_cart.cart_listener" class="%sylius_cart.cart_listener.class%">
+ <service id="sylius.cart_listener" class="%sylius.cart_listener.class%">
<tag name="kernel.event_subscriber" />
- <argument type="service" id="sylius_cart.manager.cart" />
+ <argument type="service" id="sylius.manager.cart" />
<argument type="service" id="validator" />
</service>
- <service id="sylius_cart.flash_listener" class="%sylius_cart.flash_listener.class%">
+ <service id="sylius.cart_flash_listener" class="%sylius.cart_flash_listener.class%">
<tag name="kernel.event_subscriber" />
<argument type="service" id="session" />
</service>
View
4 Resources/config/validation.xml
@@ -27,8 +27,8 @@
<constraint name="Type">
<option name="type">integer</option>
</constraint>
- <constraint name="Min">
- <option name="limit">1</option>
+ <constraint name="Range">
+ <option name="min">1</option>
</constraint>
</property>
</class>
View
4 SyliusCartBundle.php
@@ -41,8 +41,8 @@ public static function getSupportedDrivers()
public function build(ContainerBuilder $container)
{
$interfaces = array(
- 'Sylius\Bundle\CartBundle\Model\CartInterface' => 'sylius_cart.model.cart.class',
- 'Sylius\Bundle\CartBundle\Model\CartItemInterface' => 'sylius_cart.model.item.class',
+ 'Sylius\Bundle\CartBundle\Model\CartInterface' => 'sylius.model.cart.class',
+ 'Sylius\Bundle\CartBundle\Model\CartItemInterface' => 'sylius.model.cart_item.class',
);
$container->addCompilerPass(new ResolveDoctrineTargetEntitiesPass('sylius_cart', $interfaces));
View
20 SyliusCartEvents.php
@@ -13,17 +13,17 @@
final class SyliusCartEvents
{
- const CART_CLEAR_INITIALIZE = 'sylius_cart.clear.initialize';
- const CART_CLEAR_COMPLETED = 'sylius_cart.clear.completed';
+ const CART_CLEAR_INITIALIZE = 'sylius.cart_clear.initialize';
+ const CART_CLEAR_COMPLETED = 'sylius.cart_clear.completed';
- const CART_SAVE_INITIALIZE = 'sylius_cart.save.initialize';
- const CART_SAVE_COMPLETED = 'sylius_cart.save.completed';
+ const CART_SAVE_INITIALIZE = 'sylius.cart_save.initialize';
+ const CART_SAVE_COMPLETED = 'sylius.cart_save.completed';
- const ITEM_ADD_INITIALIZE = 'sylius_cart.item.add.initialize';
- const ITEM_ADD_COMPLETED = 'sylius_cart.item.add.completed';
- const ITEM_ADD_ERROR = 'sylius_cart.item.add.error';
+ const ITEM_ADD_INITIALIZE = 'sylius.cart_item.add.initialize';
+ const ITEM_ADD_COMPLETED = 'sylius.cart_item.add.completed';
+ const ITEM_ADD_ERROR = 'sylius.cart_item.add.error';
- const ITEM_REMOVE_INITIALIZE = 'sylius_cart.item.remove.initialize';
- const ITEM_REMOVE_COMPLETED = 'sylius_cart.item.remove.completed';
- const ITEM_REMOVE_ERROR = 'sylius_cart.item.remove.error';
+ const ITEM_REMOVE_INITIALIZE = 'sylius.cart_item.remove.initialize';
+ const ITEM_REMOVE_COMPLETED = 'sylius.cart_item.remove.completed';
+ const ITEM_REMOVE_ERROR = 'sylius.cart_item.remove.error';
}
View
15 Twig/SyliusCartExtension.php
@@ -65,8 +65,9 @@ public function __construct(CartProviderInterface $cartProvider, ObjectRepositor
public function getFunctions()
{
return array(
- 'sylius_cart_get' => new Twig_Function_Method($this, 'getCurrentCart'),
- 'sylius_cart_form' => new Twig_Function_Method($this, 'getItemFormView'),
+ 'sylius_cart_exists' => new Twig_Function_Method($this, 'hasCart'),
+ 'sylius_cart_get' => new Twig_Function_Method($this, 'getCurrentCart'),
+ 'sylius_cart_form' => new Twig_Function_Method($this, 'getItemFormView'),
);
}
@@ -81,6 +82,16 @@ public function getCurrentCart()
}
/**
+ * Check if a cart exists.
+ *
+ * @return boolean
+ */
+ public function hasCart()
+ {
+ return $this->cartProvider->hasCart();
+ }
+
+ /**
* Returns cart item form view.
*
* @param array $options
View
19 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;
@@ -13,25 +22,25 @@ class CartController extends ObjectBehavior
{
function let()
{
- $this->beConstructedWith('sylius_cart', 'cart', 'SyliusCartBundle:Cart');
+ $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');
}
View
18 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;
@@ -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');
}
}
-
View
13 spec/Sylius/Bundle/CartBundle/DependencyInjection/SyliusCartExtension.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\DependencyInjection;
use PHPSpec2\ObjectBehavior;
@@ -11,12 +20,12 @@
*/
class SyliusCartExtension extends ObjectBehavior
{
- function it_should_be_initializable()
+ function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\DependencyInjection\SyliusCartExtension');
}
- function it_should_be_container_extension()
+ function it_is_a_container_extension()
{
$this->shouldHaveType('Symfony\Component\HttpKernel\DependencyInjection\Extension');
}
View
15 spec/Sylius/Bundle/CartBundle/Entity/Cart.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\Entity;
use PHPSpec2\ObjectBehavior;
@@ -11,17 +20,17 @@
*/
class Cart extends ObjectBehavior
{
- function it_should_be_initializable()
+ function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\Entity\Cart');
}
- function it_should_be_Sylius_cart()
+ function it_implements_Sylius_cart_interface()
{
$this->shouldImplement('Sylius\Bundle\CartBundle\Model\CartInterface');
}
- function it_should_extend_Sylius_cart_model()
+ function it_extends_Sylius_cart_model()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\Model\Cart');
}
View
15 spec/Sylius/Bundle/CartBundle/Entity/CartItem.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\Entity;
use PHPSpec2\ObjectBehavior;
@@ -11,17 +20,17 @@
*/
class CartItem extends ObjectBehavior
{
- function it_should_be_initializable()
+ function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\Entity\CartItem');
}
- function it_should_be_Sylius_cart_item()
+ function it_implements_Sylius_cart_item_interface()
{
$this->shouldImplement('Sylius\Bundle\CartBundle\Model\CartItemInterface');
}
- function it_should_extend_Sylius_cart_item_model()
+ function it_extends_Sylius_cart_item_model()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\Model\CartItem');
}
View
15 spec/Sylius/Bundle/CartBundle/Entity/DefaultCart.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\Entity;
use PHPSpec2\ObjectBehavior;
@@ -11,17 +20,17 @@
*/
class DefaultCart extends ObjectBehavior
{
- function it_should_be_initializable()
+ function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\Entity\DefaultCart');
}
- function it_should_be_Sylius_cart()
+ function it_implements_Sylius_cart_interface()
{
$this->shouldImplement('Sylius\Bundle\CartBundle\Model\CartInterface');
}
- function it_should_extend_Sylius_cart_mapped_superclass()
+ function it_extends_Sylius_cart_mapped_superclass()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\Entity\Cart');
}
View
11 spec/Sylius/Bundle/CartBundle/EventListener/CartListener.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\EventListener;
use PHPSpec2\ObjectBehavior;
@@ -20,7 +29,7 @@ function let($manager, $validator)
$this->beConstructedWith($manager, $validator);
}
- function it_should_be_initializable()
+ function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\EventListener\CartListener');
}
View
11 spec/Sylius/Bundle/CartBundle/EventListener/FlashListener.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\EventListener;
use PHPSpec2\ObjectBehavior;
@@ -19,7 +28,7 @@ function let($session)
$this->beConstructedWith($session);
}
- function it_should_be_initializable()
+ function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\EventListener\FlashListener');
}
View
17 spec/Sylius/Bundle/CartBundle/Form/Type/CartItemType.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\Form\Type;
use PHPSpec2\ObjectBehavior;
@@ -16,20 +25,20 @@ function let()
$this->beConstructedWith('CartItem');
}
- function it_should_be_initializable()
+ function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\Form\Type\CartItemType');
}
- function it_should_be_a_form_type()
+ function it_is_a_form_type()
{
$this->shouldImplement('Symfony\Component\Form\FormTypeInterface');
}
/**
* @param Symfony\Component\Form\FormBuilder $builder
*/
- function it_should_build_form_with_quantity_field($builder)
+ function it_builds_form_with_quantity_field($builder)
{
$builder
->add('quantity', 'integer', ANY_ARGUMENT)
@@ -43,7 +52,7 @@ function it_should_build_form_with_quantity_field($builder)
/**
* @param Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver
*/
- function it_should_define_assigned_data_class($resolver)
+ function it_defines_assigned_data_class($resolver)
{
$resolver->setDefaults(array('data_class' => 'CartItem'))->shouldBeCalled();
View
17 spec/Sylius/Bundle/CartBundle/Form/Type/CartType.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\Form\Type;
use PHPSpec2\ObjectBehavior;
@@ -16,20 +25,20 @@ function let()
$this->beConstructedWith('Cart');
}
- function it_should_be_initializable()
+ function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\Form\Type\CartType');
}
- function it_should_be_a_form_type()
+ function it_is_a_form_type()
{
$this->shouldImplement('Symfony\Component\Form\FormTypeInterface');
}
/**
* @param Symfony\Component\Form\FormBuilder $builder
*/
- function it_should_build_form_with_items_collection($builder)
+ function it_builds_form_with_items_collection($builder)
{
$builder
->add('items', 'collection', array('type' => 'sylius_cart_item'))
@@ -43,7 +52,7 @@ function it_should_build_form_with_items_collection($builder)
/**
* @param Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver
*/
- function it_should_define_assigned_data_class($resolver)
+ function it_defines_assigned_data_class($resolver)
{
$resolver->setDefaults(array('data_class' => 'Cart'))->shouldBeCalled();
View
71 spec/Sylius/Bundle/CartBundle/Model/Cart.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\Model;
use PHPSpec2\ObjectBehavior;
@@ -11,37 +20,37 @@
*/
class Cart extends ObjectBehavior
{
- function it_should_be_initializable()
+ function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\Model\Cart');
}
- function it_should_be_Sylius_cart()
+ function it_implements_Sylius_cart_interface()
{
$this->shouldImplement('Sylius\Bundle\CartBundle\Model\CartInterface');
}
- function it_should_intitialize_items_collection_by_default()
+ function it_creates_items_collection_by_default()
{
$this->getItems()->shouldHaveType('Doctrine\\Common\\Collections\\Collection');
}
- function it_should_have_0_total_quantity_by_default()
+ function it_has_0_total_quantity_by_default()
{
$this->getTotalQuantity()->shouldReturn(0);
}
- function it_should_have_0_total_items_by_default()
+ function it_has_0_total_items_by_default()
{
$this->getTotalItems()->shouldReturn(0);
}
- function it_should_have_total_equal_to_0_by_default()
+ function it_has_total_equal_to_0_by_default()
{
$this->getTotal()->shouldReturn(0);
}
- function it_should_be_empty_by_default()
+ function it_is_empty_by_default()
{
$this->countItems()->shouldReturn(0);
$this->shouldBeEmpty();
@@ -52,22 +61,29 @@ function it_should_not_be_locked_by_default()
$this->shouldNotBeLocked();
}
- function it_should_be_not_expired_by_default()
+ function it_can_be_locked()
+ {
+ $this->setLocked(true);
+ $this->shouldBeLocked();
+ }
+
+ function it_is_not_expired_by_default()
{
$this->shouldNotBeExpired();
}
/**
* @param Sylius\Bundle\CartBundle\Model\CartItemInterface $item
*/
- function it_should_have_fluid_interface_for_items_management($item)
+ function it_has_fluent_interface_for_items_management($item)
{
$this->addItem($item)->shouldReturn($this);
$this->removeItem($item)->shouldReturn($this);
$this->clearItems()->shouldReturn($this);
}
+<<<<<<< HEAD
function it_should_complain_when_total_quantity_is_less_than_0()
{
$this
@@ -77,14 +93,17 @@ function it_should_complain_when_total_quantity_is_less_than_0()
}
function it_should_complain_when_total_items_is_less_than_0()
+=======
+ function it_throws_exception_when_total_items_is_less_than_0()
+>>>>>>> d8450c569f0ee1bcacb1f18f799fd7eaa094b47a
{
$this
->shouldThrow(new \OutOfRangeException('Total items must not be less than 0'))
->duringSetTotalItems(-1)
;
}
- function it_should_reset_total_items_to_0_if_change_is_bigger_than_current_amount()
+ function it_sets_total_items_to_0_if_change_is_bigger_than_current_amount()
{
$this->setTotalItems(5);
$this->changeTotalItems(-10);
@@ -97,11 +116,11 @@ function it_should_reset_total_items_to_0_if_change_is_bigger_than_current_amoun
* @param Sylius\Bundle\CartBundle\Model\CartItemInterface $item2
* @param Sylius\Bundle\CartBundle\Model\CartItemInterface $item3
*/
- function it_should_calculate_correct_total($item1, $item2, $item3)
+ function it_calculates_correct_total($item1, $item2, $item3)
{
- $item1->getTotal()->willReturn(299.99);
- $item2->getTotal()->willReturn(450);
- $item3->getTotal()->willReturn(2.50);
+ $item1->getTotal()->willReturn(29999);
+ $item2->getTotal()->willReturn(45000);
+ $item3->getTotal()->willReturn(250);
$item1->equals(ANY_ARGUMENT)->willReturn(false);
$item2->equals(ANY_ARGUMENT)->willReturn(false);
@@ -115,14 +134,14 @@ function it_should_calculate_correct_total($item1, $item2, $item3)
$this->calculateTotal();
- $this->getTotal()->shouldReturn(752.49);
+ $this->getTotal()->shouldReturn(75249);
}
/**
* @param Sylius\Bundle\CartBundle\Model\CartItemInterface $item1
* @param Sylius\Bundle\CartBundle\Model\CartItemInterface $item2
*/
- function it_should_sum_the_quantities_of_equal_items($item1, $item2)
+ function it_sums_the_quantities_of_equal_items($item1, $item2)
{
$item1->getQuantity()->willReturn(3);
$item2->getQuantity()->willReturn(7);
@@ -140,20 +159,34 @@ function it_should_sum_the_quantities_of_equal_items($item1, $item2)
/**
* @param Sylius\Bundle\CartBundle\Model\CartItemInterface $item
*/
- function it_should_add_and_remove_items_properly($item)
+ function it_adds_items($item)
{
$this->hasItem($item)->shouldReturn(false);
-
$this->addItem($item);
$this->hasItem($item)->shouldReturn(true);
+ }
+ /**
+ * @param Sylius\Bundle\CartBundle\Model\CartItemInterface $item
+ */
+ function it_removes_items($item)
+ {
+ $this->addItem($item);
$this->removeItem($item);
$this->hasItem($item)->shouldReturn(false);
$this->shouldBeEmpty();
}
- function it_should_be_expired_if_the_expiration_time_is_in_past()
+ function it_is_not_expired_if_the_expiration_time_is_in_future()
+ {
+ $expiresAt = new \DateTime('tomorrow');
+ $this->setExpiresAt($expiresAt);
+
+ $this->shouldNotBeExpired();
+ }
+
+ function it_is_expired_if_the_expiration_time_is_in_past()
{
$expiresAt = new \DateTime('-1 hour');
$this->setExpiresAt($expiresAt);
View
41 spec/Sylius/Bundle/CartBundle/Model/CartItem.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\Model;
use PHPSpec2\ObjectBehavior;
@@ -11,45 +20,59 @@
*/
class CartItem extends ObjectBehavior
{
- function it_should_be_initializable()
+ function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\Model\CartItem');
}
- function it_should_be_Sylius_cart_item()
+ function it_implements_Sylius_cart_item_interface()
{
$this->shouldImplement('Sylius\Bundle\CartBundle\Model\CartItemInterface');
}
- function it_should_have_quantity_equal_to_1_by_default()
+ function it_has_quantity_equal_to_1_by_default()
{
$this->getQuantity()->shouldReturn(1);
}
- function it_should_have_unit_price_equal_to_0_by_default()
+ function it_accepts_only_integer_as_quantity()
+ {
+ $this->shouldThrow('InvalidArgumentException')->duringSetQuantity('52');
+ $this->shouldThrow('InvalidArgumentException')->duringSetQuantity(45.55);
+ $this->shouldThrow('InvalidArgumentException')->duringSetQuantity(false);
+ }
+
+ function it_has_unit_price_equal_to_0_by_default()
{
$this->getUnitPrice()->shouldReturn(0);
}
- function it_should_have_total_equal_to_0_by_default()
+ function it_accepts_only_integer_as_unit_price()
+ {
+ $this->shouldThrow('InvalidArgumentException')->duringSetUnitPrice('52');
+ $this->shouldThrow('InvalidArgumentException')->duringSetUnitPrice(45.55);
+ $this->shouldThrow('InvalidArgumentException')->duringSetUnitPrice(false);
+ }
+
+ function it_has_total_equal_to_0_by_default()
{
$this->getTotal()->shouldReturn(0);
}
- function it_should_calculate_correct_total()
+ function it_calculates_correct_total()
{
$this->setQuantity(13);
- $this->setUnitPrice(14.99);
+ $this->setUnitPrice(1499);
$this->calculateTotal();
- $this->getTotal()->shouldReturn(194.87);
+ $this->getTotal()->shouldReturn(19487);
}
/**
* @param Sylius\Bundle\CartBundle\Model\CartItemInterface $otherCartItem
*/
- function it_should_not_recognize_items_as_equal_if_they_do_not_have_the_same_id($otherCartItem)
+ function it_does_not_recognize_items_as_equal_if_they_do_not_have_the_same_id($otherCartItem)
{
$otherCartItem->getId()->willReturn(1);
View
23 spec/Sylius/Bundle/CartBundle/Provider/CartProvider.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\Provider;
use PHPSpec2\ObjectBehavior;
@@ -21,20 +30,20 @@ function let($storage, $manager, $repository)
$this->beConstructedWith($storage, $manager, $repository);
}
- function it_should_be_initializable()
+ function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\Provider\CartProvider');
}
- function it_should_be_Sylius_cart_provider()
+ function it_implements_Sylius_cart_provider_interface()
{
$this->shouldImplement('Sylius\Bundle\CartBundle\Provider\CartProviderInterface');
}
/**
* @param Sylius\Bundle\CartBundle\Model\CartInterface $cart
*/
- function it_should_look_for_cart_by_identifier_if_any($storage, $repository, $cart)
+ function it_looks_for_cart_by_identifier_if_any_in_storage($storage, $repository, $cart)
{
$storage->getCurrentCartIdentifier()->willReturn(3);
$repository->find(3)->shouldBeCalled()->willReturn($cart);
@@ -45,7 +54,7 @@ function it_should_look_for_cart_by_identifier_if_any($storage, $repository, $ca
/**
* @param Sylius\Bundle\CartBundle\Model\CartInterface $cart
*/
- function it_should_create_new_cart_if_there_is_no_identifier_in_storage($storage, $repository, $cart)
+ function it_creates_new_cart_if_there_is_no_identifier_in_storage($storage, $repository, $cart)
{
$storage->getCurrentCartIdentifier()->willReturn(null);
$repository->createNew()->willReturn($cart);
@@ -56,7 +65,7 @@ function it_should_create_new_cart_if_there_is_no_identifier_in_storage($storage
/**
* @param Sylius\Bundle\CartBundle\Model\CartInterface $cart
*/
- function it_should_create_new_cart_if_identifier_is_wrong($storage, $repository, $cart)
+ function it_creates_new_cart_if_identifier_is_wrong($storage, $repository, $cart)
{
$storage->getCurrentCartIdentifier()->willReturn(7);
$repository->find(7)->shouldBeCalled()->willReturn(null);
@@ -65,7 +74,7 @@ function it_should_create_new_cart_if_identifier_is_wrong($storage, $repository,
$this->getCart()->shouldReturn($cart);
}
- function it_should_reset_current_cart_identifier_when_abandoning_cart($storage)
+ function it_resets_current_cart_identifier_in_storage_when_abandoning_cart($storage)
{
$storage->resetCurrentCartIdentifier()->shouldBeCalled();
@@ -75,7 +84,7 @@ function it_should_reset_current_cart_identifier_when_abandoning_cart($storage)
/**
* @param Sylius\Bundle\CartBundle\Model\CartInterface $cart
*/
- function it_should_set_current_cart_identifier_when_setting_cart($storage, $cart)
+ function it_sets_current_cart_identifier_when_setting_cart($storage, $cart)
{
$storage->setCurrentCartIdentifier($cart)->shouldBeCalled();
View
19 spec/Sylius/Bundle/CartBundle/Storage/SessionCartStorage.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\Storage;
use PHPSpec2\ObjectBehavior;
@@ -20,17 +29,17 @@ function let($session)
$this->beConstructedWith($session);
}
- function it_should_be_initializable()
+ function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\Storage\SessionCartStorage');
}
- function it_should_be_Sylius_cart_storage()
+ function it_implements_Sylius_cart_storage_interface()
{
$this->shouldImplement('Sylius\Bundle\CartBundle\Storage\CartStorageInterface');
}
- function it_should_retrieve_cart_id_via_session($session)
+ function it_returns_cart_identifier_via_session($session)
{
$session->get(SessionCartStorageClass::KEY)->willReturn(7);
@@ -40,15 +49,15 @@ function it_should_retrieve_cart_id_via_session($session)
/**
* @param Sylius\Bundle\CartBundle\Model\CartInterface $cart
*/
- function it_should_set_cart_id_via_session($session, $cart)
+ function it_sets_cart_identifier_via_session($session, $cart)
{
$cart->getId()->willReturn(3);
$session->set(SessionCartStorageClass::KEY, 3)->shouldBeCalled();
$this->setCurrentCartIdentifier($cart);
}
- function it_should_remove_the_saved_id_from_session_on_reset($session)
+ function it_removes_the_saved_identifier_from_session_on_reset($session)
{
$session->remove(SessionCartStorageClass::KEY)->shouldBeCalled();
View
13 spec/Sylius/Bundle/CartBundle/SyliusCartBundle.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;
use PHPSpec2\ObjectBehavior;
@@ -11,12 +20,12 @@
*/
class SyliusCartBundle extends ObjectBehavior
{
- function it_should_be_initializable()
+ function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\SyliusCartBundle');
}
- function it_should_be_a_bundle()
+ function it_is_a_bundle()
{
$this->shouldHaveType('Symfony\Component\HttpKernel\Bundle\Bundle');
}
View
19 spec/Sylius/Bundle/CartBundle/Twig/SyliusCartExtension.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\Twig;
use PHPSpec2\ObjectBehavior;
@@ -21,20 +30,20 @@ function let($cartProvider, $itemRepository, $formFactory)
$this->beConstructedWith($cartProvider, $itemRepository, $formFactory);
}
- function it_should_be_initializable()
+ function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\CartBundle\Twig\SyliusCartExtension');
}
- function it_should_be_a_twig_extension()
+ function it_is_a_twig_extension()
{
$this->shouldHaveType('Twig_Extension');
}
/**
* @param Sylius\Bundle\CartBundle\Model\CartInterface $cart
*/
- function its_getCurrentCart_should_return_current_cart_via_provider($cartProvider, $cart)
+ function its_getCurrentCart_returns_current_cart_via_provider($cartProvider, $cart)
{
$cartProvider->getCart()->willReturn($cart);
@@ -46,7 +55,7 @@ function its_getCurrentCart_should_return_current_cart_via_provider($cartProvide
* @param Symfony\Component\Form\FormViewInterface $formView
* @param Sylius\Bundle\CartBundle\Model\CartItemInterface $item
*/
- function its_getItemFormView_should_construct_a_form_view_of_cart_item_form(
+ function its_getItemFormView_returns_a_form_view_of_cart_item_form(
$itemRepository, $formFactory, $form, $formView, $item
)
{
@@ -62,7 +71,7 @@ function its_getItemFormView_should_construct_a_form_view_of_cart_item_form(
* @param Symfony\Component\Form\FormViewInterface $formView
* @param Sylius\Bundle\CartBundle\Model\CartItemInterface $item
*/
- function its_getItemFormView_should_use_given_options_when_creating_form(
+ function its_getItemFormView_uses_given_options_when_creating_form(
$itemRepository, $formFactory, $form, $formView, $item
)
{

0 comments on commit ab3b1d3

Please sign in to comment.