Skip to content

Commit

Permalink
Merge pull request #13 from umpirsky/stockable-model
Browse files Browse the repository at this point in the history
Added default Stockable model
  • Loading branch information
Paweł Jędrzejewski committed Jan 12, 2013
2 parents a641832 + 48f2225 commit c866458
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/Sylius/Bundle/InventoryBundle/Entity/Stockable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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 Sylius\Bundle\InventoryBundle\Entity;

use Sylius\Bundle\InventoryBundle\Model\Stockable as BaseStockable;

/**
* Stocakble entity.
*
* @author Саша Стаменковић <[email protected]>
*/
class Stockable extends BaseStockable
{
}
129 changes: 129 additions & 0 deletions src/Sylius/Bundle/InventoryBundle/Model/Stockable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?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 Sylius\Bundle\InventoryBundle\Model;

/**
* Stockable model.
*
* @author Саша Стаменковић <[email protected]>
*/
class Stockable implements StockableInterface
{
/**
* Stockable id.
*
* @var mixed
*/
protected $id;

/**
* Stockable SKU.
*
* @var string
*/
protected $sku;

/**
* Inventory displayed name.
*
* @var string
*/
protected $inventoryName;

/**
* Current stock level.
*
* @var int
*/
protected $onHand;

/**
* Is stock available on demand?
*
* @var Boolean
*/
protected $availableOnDemand;

public function __construct()
{
$this->onHand = 1;
$this->availableOnDemand = true;
}

public function getId()
{
return $this->id;
}

/**
* {@inheritdoc}
*/
public function getSku()
{
return $this->sku;
}

public function setSku($sku)
{
$this->sku = $sku;
}

/**
* {@inheritdoc}
*/
public function getInventoryName()
{
return $this->inventoryName;
}

public function setInventoryName($inventoryName)
{
$this->inventoryName = $inventoryName;
}

/**
* {@inheritdoc}
*/
public function isInStock()
{
return 0 < $this->onHand;
}

/**
* {@inheritdoc}
*/
public function isAvailableOnDemand()
{
return $this->availableOnDemand;
}

public function setAvailableOnDemand($availableOnDemand)
{
$this->availableOnDemand = (Boolean) $availableOnDemand;
}

/**
* {@inheritdoc}
*/
public function getOnHand()
{
return $this->onHand;
}

/**
* {@inheritdoc}
*/
public function setOnHand($onHand)
{
$this->onHand = $onHand;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
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.
-->

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping">
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<mapped-superclass name="Sylius\Bundle\InventoryBundle\Entity\Stockable">
<field name="sku" column="sku" type="string" />
<field name="inventoryName" column="inventory_name" type="string" />
<field name="onHand" column="on_hand" type="integer" />
<field name="availableOnDemand" column="available_on_demand" type="boolean"/>
</mapped-superclass>

</doctrine-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use PHPSpec2\ObjectBehavior;

/**
* Shipment item mapped superclass spec.
* Inventory unit entity spec.
*
* @author Pawęł Jędrzejewski <[email protected]>
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace spec\Sylius\Bundle\InventoryBundle\Entity;

use PHPSpec2\ObjectBehavior;

/**
* Stockable entity spec.
*
* @author Саша Стаменковић <[email protected]>
*/
class Stockable extends ObjectBehavior
{
function it_should_be_initializable()
{
$this->shouldHaveType('Sylius\Bundle\InventoryBundle\Entity\Stockable');
}

function it_should_be_a_Sylius_stockable()
{
$this->shouldImplement('Sylius\Bundle\InventoryBundle\Model\StockableInterface');
}

function it_should_extend_Sylius_stockable_model()
{
$this->shouldHaveType('Sylius\Bundle\InventoryBundle\Model\Stockable');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Sylius\Bundle\InventoryBundle\Model\InventoryUnitInterface;

/**
* Stockable item model spec.
* Inventory unit model spec.
*
* @author Paweł Jędrzejewski <[email protected]>
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace spec\Sylius\Bundle\InventoryBundle\Model;

use PHPSpec2\ObjectBehavior;

/**
* Stockable model spec.
*
* @author Саша Стаменковић <[email protected]>
*/
class Stockable extends ObjectBehavior
{
function it_should_be_initializable()
{
$this->shouldHaveType('Sylius\Bundle\InventoryBundle\Model\Stockable');
}

function it_should_be_a_Sylius_stockable()
{
$this->shouldImplement('Sylius\Bundle\InventoryBundle\Model\StockableInterface');
}

function it_should_not_have_id_by_default()
{
$this->getId()->shouldReturn(null);
}

function it_should_not_have_defined_sku_by_default()
{
$this->getSku()->shouldReturn(null);
}

function its_sku_should_be_mutable()
{
$this->setSku('1234R');
$this->getSku()->shouldReturn('1234R');
}

function it_should_not_have_defined_inventory_name_by_default()
{
$this->getInventoryName()->shouldReturn(null);
}

function its_inventory_name_should_be_mutable()
{
$this->setInventoryName('Lorem Ipsum');
$this->getInventoryName()->shouldReturn('Lorem Ipsum');
}

function it_should_be_in_stock_by_default()
{
$this->isInStock()->shouldReturn(true);
}

function it_should_be_available_on_demand_by_default()
{
$this->isAvailableOnDemand()->shouldReturn(true);
}

function its_available_on_demand_should_be_mutable()
{
$this->setAvailableOnDemand(false);
$this->isAvailableOnDemand()->shouldReturn(false);
}

function it_should_have_1_on_hand_by_default()
{
$this->getOnHand()->shouldReturn(1);
}


function its_on_hand_should_be_mutable()
{
$this->setOnHand(5);
$this->getOnHand()->shouldReturn(5);
}
}

0 comments on commit c866458

Please sign in to comment.