Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdb committed Jan 7, 2016
1 parent e53f9da commit 53f3878
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
11 changes: 4 additions & 7 deletions src/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use jamesdb\Cart\CartItem;
use jamesdb\Cart\Event as CartEvent;
use jamesdb\Cart\Exception as CartException;
use jamesdb\Cart\Identifier\IdentifierInterface;
use jamesdb\Cart\Storage\StorageInterface;
use League\Event\Emitter;
use SebastianBergmann\Money\Currency;
Expand Down Expand Up @@ -335,29 +334,27 @@ public function restore()
if (! empty($data)) {
$data = unserialize($data);

$start = 'Storage data';

if (! is_array($data)) {
throw new CartException\CartRestoreException(
sprintf('%s must be an array', $start)
'Data must be an array'
);
}

if (! isset($data['id']) || (! isset($data['items']))) {
throw new CartException\CartRestoreException(
sprintf('%s must have an id and items key', $start)
'Storage data must have an id and items key'
);
}

if (! is_string($data['id'])) {
throw new CartException\CartRestoreException(
sprintf('Invalid %s type, ensure id is a string', strtolower($start))
'Invalid storage data type, ensure id is a string'
);
}

if (! is_array($data['items'])) {
throw new CartException\CartRestoreException(
sprintf('Invalid %s type, ensure items is an array', strtolower($start))
'Invalid storage data type, ensure items are an array'
);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/CartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ public function testCartCanBeRestored()
*/
public function testCartRestoreThrowsNotArrayException()
{
$this->setExpectedException('jamesdb\Cart\Exception\CartRestoreException', 'Storage data must be an array');
$this->setExpectedException('jamesdb\Cart\Exception\CartRestoreException', 'Data must be an array');

$storageMock = $this->getMock('jamesdb\Cart\Storage\StorageInterface');

Expand Down Expand Up @@ -564,7 +564,7 @@ public function testRestoreThrowsDataTypeExceptionWhenInvalidIdSupplied()
*/
public function testRestoreThrowsDataTypeExceptionWhenInvalidItemsSupplied()
{
$this->setExpectedException('jamesdb\Cart\Exception\CartRestoreException', 'Invalid storage data type, ensure items is an array');
$this->setExpectedException('jamesdb\Cart\Exception\CartRestoreException', 'Invalid storage data type, ensure items are an array');

$storageMock = $this->getMock('jamesdb\Cart\Storage\StorageInterface');

Expand Down

0 comments on commit 53f3878

Please sign in to comment.