Compare commits

..
5 Commits
Author SHA1 Message Date
Joel Male 4a312a37e2 1.0.7 2024-08-30 09:44:40 +10:00
github-actions[bot] 274a8504af Merge pull request #10 from wearepixel/dependabot/composer/master/pestphp/pest-2.35.1
Bump pestphp/pest from 2.35.0 to 2.35.1
2024-08-26 12:56:01 +00:00
dependabot[bot] 4f22672ca5 Bump pestphp/pest from 2.35.0 to 2.35.1
Bumps [pestphp/pest](https://github.com/pestphp/pest) from 2.35.0 to 2.35.1.
- [Release notes](https://github.com/pestphp/pest/releases)
- [Changelog](https://github.com/pestphp/pest/blob/2.x/RELEASE.md)
- [Commits](https://github.com/pestphp/pest/compare/v2.35.0...v2.35.1)

---
updated-dependencies:
- dependency-name: pestphp/pest
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-26 12:55:45 +00:00
Joel Male 61475a7060 1.0.6 2024-08-26 10:58:14 +10:00
Joel Male 6604cf984d fix tests & validation errors 2024-08-26 10:57:02 +10:00
26 changed files with 126 additions and 117 deletions
+8 -8
View File
@@ -33,14 +33,14 @@ ## Installing
Install the package through [Composer](http://getcomposer.org/). Install the package through [Composer](http://getcomposer.org/).
`composer require "wearepixel/laravel-cart"` `composer require "pixeldigital/laravel-cart"`
## Configuration ## Configuration
You can publish the configuration file to customize various options. You can publish the configuration file to customize various options.
```php ```php
php artisan vendor:publish --provider="Wearepixel\Cart\CartServiceProvider" --tag="config" php artisan vendor:publish --provider="Pixeldigital\Cart\CartServiceProvider" --tag="config"
``` ```
### Formatting Numbers ### Formatting Numbers
@@ -302,7 +302,7 @@ #### Adding a condition to the cart: **Cart::condition()**
```php ```php
// Add a single condition to the cart // Add a single condition to the cart
$condition = new \Wearepixel\Cart\CartCondition([ $condition = new \Pixeldigital\Cart\CartCondition([
'name' => 'Tax: 10%', 'name' => 'Tax: 10%',
'type' => 'tax', 'type' => 'tax',
'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called. 'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called.
@@ -315,7 +315,7 @@ #### Adding a condition to the cart: **Cart::condition()**
Cart::condition($condition); Cart::condition($condition);
// Add multiple conditions // Add multiple conditions
$tax = new \Wearepixel\Cart\CartCondition([ $tax = new \Pixeldigital\Cart\CartCondition([
'name' => 'Tax: 10%', 'name' => 'Tax: 10%',
'type' => 'tax', 'type' => 'tax',
'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called. 'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called.
@@ -323,7 +323,7 @@ #### Adding a condition to the cart: **Cart::condition()**
'order' => 2 'order' => 2
]); ]);
$shipping = new \Wearepixel\Cart\CartCondition([ $shipping = new \Pixeldigital\Cart\CartCondition([
'name' => 'Shipping: $15', 'name' => 'Shipping: $15',
'type' => 'shipping', 'type' => 'shipping',
'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called. 'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called.
@@ -338,7 +338,7 @@ #### Adding a condition to the cart: **Cart::condition()**
Cart::condition([$tax, $shipping]); Cart::condition([$tax, $shipping]);
// add condition to only apply on totals, not in subtotal // add condition to only apply on totals, not in subtotal
$shipping = new \Wearepixel\Cart\CartCondition([ $shipping = new \Pixeldigital\Cart\CartCondition([
'name' => 'Express Shipping $15', 'name' => 'Express Shipping $15',
'type' => 'shipping', 'type' => 'shipping',
'target' => 'total', 'target' => 'total',
@@ -429,7 +429,7 @@ ### Condition on items
```php ```php
// lets create first our condition instance // lets create first our condition instance
$saleCondition = new \Wearepixel\Cart\CartCondition([ $saleCondition = new \Pixeldigital\Cart\CartCondition([
'name' => '50% Off', 'name' => '50% Off',
'type' => 'tax', 'type' => 'tax',
'value' => '-50%', 'value' => '-50%',
@@ -449,7 +449,7 @@ ### Condition on items
Cart::add($product); Cart::add($product);
// You can of course also do multiple conditions on an item // You can of course also do multiple conditions on an item
$saleCondition = new \Wearepixel\Cart\CartCondition([ $saleCondition = new \Pixeldigital\Cart\CartCondition([
'name' => 'SALE 5%', 'name' => 'SALE 5%',
'type' => 'sale', 'type' => 'sale',
'value' => '-5%', 'value' => '-5%',
+6 -6
View File
@@ -1,6 +1,6 @@
{ {
"name": "wearepixel/laravel-cart", "name": "pixeldigital/laravel-cart",
"version": "1.0.5", "version": "1.0.7",
"description": "A cart implementation for Laravel", "description": "A cart implementation for Laravel",
"keywords": [ "keywords": [
"laravel", "laravel",
@@ -27,22 +27,22 @@
"require-dev": { "require-dev": {
"mockery/mockery": "^1.4.2", "mockery/mockery": "^1.4.2",
"laravel/pint": "dev-main", "laravel/pint": "dev-main",
"pestphp/pest": "2.35.0", "pestphp/pest": "2.35.1",
"larapack/dd": "dev-master" "larapack/dd": "dev-master"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Wearepixel\\Cart\\": "src/" "Pixeldigital\\Cart\\": "src/"
} }
}, },
"minimum-stability": "dev", "minimum-stability": "dev",
"extra": { "extra": {
"laravel": { "laravel": {
"providers": [ "providers": [
"Wearepixel\\Cart\\CartServiceProvider" "Pixeldigital\\Cart\\CartServiceProvider"
], ],
"aliases": { "aliases": {
"Cart": "Wearepixel\\Cart\\Facades\\CartFacade" "Cart": "Pixeldigital\\Cart\\Facades\\CartFacade"
} }
} }
}, },
Generated
+28 -28
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "f22ad76e04818683f42bf13aa7a5e4ef", "content-hash": "726c11e0474359fea45e3d6790b14426",
"packages": [ "packages": [
{ {
"name": "brick/math", "name": "brick/math",
@@ -2963,21 +2963,21 @@
}, },
{ {
"name": "pestphp/pest", "name": "pestphp/pest",
"version": "v2.35.0", "version": "v2.35.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/pestphp/pest.git", "url": "https://github.com/pestphp/pest.git",
"reference": "d0ff2c8ec294b7aa7fcb0f3ddc4fdec864234646" "reference": "b13acb630df52c06123588d321823c31fc685545"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/pestphp/pest/zipball/d0ff2c8ec294b7aa7fcb0f3ddc4fdec864234646", "url": "https://api.github.com/repos/pestphp/pest/zipball/b13acb630df52c06123588d321823c31fc685545",
"reference": "d0ff2c8ec294b7aa7fcb0f3ddc4fdec864234646", "reference": "b13acb630df52c06123588d321823c31fc685545",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"brianium/paratest": "^7.3.1", "brianium/paratest": "^7.3.1",
"nunomaduro/collision": "^7.10.0|^8.3.0", "nunomaduro/collision": "^7.10.0|^8.4.0",
"nunomaduro/termwind": "^1.15.1|^2.0.1", "nunomaduro/termwind": "^1.15.1|^2.0.1",
"pestphp/pest-plugin": "^2.1.1", "pestphp/pest-plugin": "^2.1.1",
"pestphp/pest-plugin-arch": "^2.7.0", "pestphp/pest-plugin-arch": "^2.7.0",
@@ -3055,7 +3055,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/pestphp/pest/issues", "issues": "https://github.com/pestphp/pest/issues",
"source": "https://github.com/pestphp/pest/tree/v2.35.0" "source": "https://github.com/pestphp/pest/tree/v2.35.1"
}, },
"funding": [ "funding": [
{ {
@@ -3067,7 +3067,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2024-08-02T10:57:29+00:00" "time": "2024-08-20T21:41:50+00:00"
}, },
{ {
"name": "pestphp/pest-plugin", "name": "pestphp/pest-plugin",
@@ -3561,28 +3561,28 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "09d5f55e54c20f2353a790d09772db3ad577b9ac" "reference": "7e308268858ed6baedc8704a304727d20bc07c77"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/09d5f55e54c20f2353a790d09772db3ad577b9ac", "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/7e308268858ed6baedc8704a304727d20bc07c77",
"reference": "09d5f55e54c20f2353a790d09772db3ad577b9ac", "reference": "7e308268858ed6baedc8704a304727d20bc07c77",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"ext-dom": "*", "ext-dom": "*",
"ext-libxml": "*", "ext-libxml": "*",
"ext-xmlwriter": "*", "ext-xmlwriter": "*",
"nikic/php-parser": "^4.18 || ^5.0", "nikic/php-parser": "^4.19.1 || ^5.1.0",
"php": ">=8.1", "php": ">=8.1",
"phpunit/php-file-iterator": "^4.0", "phpunit/php-file-iterator": "^4.1.0",
"phpunit/php-text-template": "^3.0", "phpunit/php-text-template": "^3.0.1",
"sebastian/code-unit-reverse-lookup": "^3.0", "sebastian/code-unit-reverse-lookup": "^3.0.0",
"sebastian/complexity": "^3.0", "sebastian/complexity": "^3.2.0",
"sebastian/environment": "^6.0", "sebastian/environment": "^6.1.0",
"sebastian/lines-of-code": "^2.0", "sebastian/lines-of-code": "^2.0.2",
"sebastian/version": "^4.0", "sebastian/version": "^4.0.1",
"theseer/tokenizer": "^1.2.0" "theseer/tokenizer": "^1.2.3"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^10.1" "phpunit/phpunit": "^10.1"
@@ -3623,7 +3623,7 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
"security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy",
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1" "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.16"
}, },
"funding": [ "funding": [
{ {
@@ -3631,7 +3631,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2024-07-17T05:15:22+00:00" "time": "2024-08-22T04:31:57+00:00"
}, },
{ {
"name": "phpunit/php-file-iterator", "name": "phpunit/php-file-iterator",
@@ -3985,12 +3985,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/php-fig/log.git", "url": "https://github.com/php-fig/log.git",
"reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001" "reference": "79dff0b268932c640297f5208d6298f71855c03e"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/fe5ea303b0887d5caefd3d431c3e61ad47037001", "url": "https://api.github.com/repos/php-fig/log/zipball/79dff0b268932c640297f5208d6298f71855c03e",
"reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001", "reference": "79dff0b268932c640297f5208d6298f71855c03e",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -4026,9 +4026,9 @@
"psr-3" "psr-3"
], ],
"support": { "support": {
"source": "https://github.com/php-fig/log/tree/3.0.0" "source": "https://github.com/php-fig/log/tree/3.0.1"
}, },
"time": "2021-07-14T16:46:02+00:00" "time": "2024-08-21T13:31:24+00:00"
}, },
{ {
"name": "sebastian/cli-parser", "name": "sebastian/cli-parser",
@@ -5765,7 +5765,7 @@
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {
"php": ">=8.0" "php": ">=8.1"
}, },
"platform-dev": [], "platform-dev": [],
"plugin-api-version": "2.6.0" "plugin-api-version": "2.6.0"
+22 -16
View File
@@ -1,12 +1,12 @@
<?php <?php
namespace Wearepixel\Cart; namespace Pixeldigital\Cart;
use Wearepixel\Cart\Helpers\Helpers; use Pixeldigital\Cart\Helpers\Helpers;
use Wearepixel\Cart\Validators\CartItemValidator; use Pixeldigital\Cart\Validators\CartItemValidator;
use Wearepixel\Cart\Exceptions\InvalidItemException; use Pixeldigital\Cart\Exceptions\InvalidItemException;
use Wearepixel\Cart\Exceptions\UnknownModelException; use Pixeldigital\Cart\Exceptions\UnknownModelException;
use Wearepixel\Cart\Exceptions\InvalidConditionException; use Pixeldigital\Cart\Exceptions\InvalidConditionException;
class Cart class Cart
{ {
@@ -153,7 +153,7 @@ public function add(
$this->add( $this->add(
$item['id'], $item['id'],
$item['name'], $item['name'],
$item['price'], isset($item['price']) ? $item['price'] : null,
$item['quantity'], $item['quantity'],
Helpers::issetAndHasValueOrAssignDefault($item['attributes'], []), Helpers::issetAndHasValueOrAssignDefault($item['attributes'], []),
Helpers::issetAndHasValueOrAssignDefault($item['conditions'], []), Helpers::issetAndHasValueOrAssignDefault($item['conditions'], []),
@@ -164,8 +164,7 @@ public function add(
$this->add( $this->add(
$id['id'], $id['id'],
$id['name'], $id['name'],
// isset($id['price']) ? $id['price'] : null, isset($id['price']) ? $id['price'] : null,
$id['price'],
$id['quantity'], $id['quantity'],
Helpers::issetAndHasValueOrAssignDefault($id['attributes'], []), Helpers::issetAndHasValueOrAssignDefault($id['attributes'], []),
Helpers::issetAndHasValueOrAssignDefault($id['conditions'], []), Helpers::issetAndHasValueOrAssignDefault($id['conditions'], []),
@@ -271,11 +270,11 @@ public function setConfig($config)
public function addItemCondition($productId, $itemCondition) public function addItemCondition($productId, $itemCondition)
{ {
if ($product = $this->get($productId)) { if ($product = $this->get($productId)) {
$conditionInstance = '\\Wearepixel\\Cart\\CartCondition'; $conditionInstance = '\\Pixeldigital\\Cart\\CartCondition';
if ($itemCondition instanceof $conditionInstance) { if ($itemCondition instanceof $conditionInstance) {
// we need to copy first to a temporary variable to hold the conditions // we need to copy first to a temporary variable to hold the conditions
// to avoid hitting this error "Indirect modification of overloaded element of Wearepixel\Cart\ItemCollection has no effect" // to avoid hitting this error "Indirect modification of overloaded element of Pixeldigital\Cart\ItemCollection has no effect"
// this is due to laravel Collection instance that implements Array Access // this is due to laravel Collection instance that implements Array Access
// // see link for more info: http://stackoverflow.com/questions/20053269/indirect-modification-of-overloaded-element-of-splfixedarray-has-no-effect // // see link for more info: http://stackoverflow.com/questions/20053269/indirect-modification-of-overloaded-element-of-splfixedarray-has-no-effect
$itemConditionTempHolder = $product['conditions']; $itemConditionTempHolder = $product['conditions'];
@@ -354,7 +353,7 @@ public function condition(array|CartCondition $condition): self
} }
if (! $condition instanceof CartCondition) { if (! $condition instanceof CartCondition) {
throw new InvalidConditionException('Argument 1 must be an instance of \'Wearepixel\Cart\CartCondition\''); throw new InvalidConditionException('Argument 1 must be an instance of \'Pixeldigital\Cart\CartCondition\'');
} }
$conditions = $this->getConditions(); $conditions = $this->getConditions();
@@ -480,7 +479,7 @@ public function removeItemCondition($itemId, $conditionName)
// on the given condition name the user wants to remove, if so, // on the given condition name the user wants to remove, if so,
// lets just make $item['conditions'] an empty array as there's just 1 condition on it anyway // lets just make $item['conditions'] an empty array as there's just 1 condition on it anyway
else { else {
$conditionInstance = 'Wearepixel\\Cart\\CartCondition'; $conditionInstance = 'Pixeldigital\\Cart\\CartCondition';
if ($item['conditions'] instanceof $conditionInstance) { if ($item['conditions'] instanceof $conditionInstance) {
if ($tempConditionsHolder->getName() == $conditionName) { if ($tempConditionsHolder->getName() == $conditionName) {
@@ -706,8 +705,15 @@ protected function validate($item)
$validator = CartItemValidator::make($item, $rules); $validator = CartItemValidator::make($item, $rules);
if ($validator->fails()) { if ($validator->fails()) {
// if the error is due to quantity if ($validator->errors()->first('id') === 'validation.required') {
if ($validator->errors()->first('quantity') === 'The quantity must be at least 0.1.') { throw new InvalidItemException('The id field is required.');
}
if ($validator->errors()->first('name') === 'validation.required') {
throw new InvalidItemException('The name field is required.');
}
if ($validator->errors()->first('quantity') === 'validation.min.numeric') {
throw new InvalidItemException('The quantity must be at least 0.1.'); throw new InvalidItemException('The quantity must be at least 0.1.');
} }
} }
@@ -770,7 +776,7 @@ protected function itemHasConditions($item)
return count($item['conditions']) > 0; return count($item['conditions']) > 0;
} }
$conditionInstance = 'Wearepixel\\Cart\\CartCondition'; $conditionInstance = 'Pixeldigital\\Cart\\CartCondition';
if ($item['conditions'] instanceof $conditionInstance) { if ($item['conditions'] instanceof $conditionInstance) {
return true; return true;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Wearepixel\Cart; namespace Pixeldigital\Cart;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
+4 -4
View File
@@ -1,10 +1,10 @@
<?php <?php
namespace Wearepixel\Cart; namespace Pixeldigital\Cart;
use Wearepixel\Cart\Helpers\Helpers; use Pixeldigital\Cart\Helpers\Helpers;
use Wearepixel\Cart\Validators\CartConditionValidator; use Pixeldigital\Cart\Validators\CartConditionValidator;
use Wearepixel\Cart\Exceptions\InvalidConditionException; use Pixeldigital\Cart\Exceptions\InvalidConditionException;
class CartCondition class CartCondition
{ {
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Wearepixel\Cart; namespace Pixeldigital\Cart;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Wearepixel\Cart; namespace Pixeldigital\Cart;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
namespace Wearepixel\Cart\Exceptions; namespace Pixeldigital\Cart\Exceptions;
class InvalidConditionException extends \Exception {} class InvalidConditionException extends \Exception {}
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
namespace Wearepixel\Cart\Exceptions; namespace Pixeldigital\Cart\Exceptions;
class InvalidItemException extends \Exception {} class InvalidItemException extends \Exception {}
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
namespace Wearepixel\Cart\Exceptions; namespace Pixeldigital\Cart\Exceptions;
class UnknownModelException extends \Exception {} class UnknownModelException extends \Exception {}
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Wearepixel\Cart\Facades; namespace Pixeldigital\Cart\Facades;
use Illuminate\Support\Facades\Facade; use Illuminate\Support\Facades\Facade;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Wearepixel\Cart\Helpers; namespace Pixeldigital\Cart\Helpers;
class Helpers class Helpers
{ {
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Wearepixel\Cart; namespace Pixeldigital\Cart;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
+3 -3
View File
@@ -1,9 +1,9 @@
<?php <?php
namespace Wearepixel\Cart; namespace Pixeldigital\Cart;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Wearepixel\Cart\Helpers\Helpers; use Pixeldigital\Cart\Helpers\Helpers;
class ItemCollection extends Collection class ItemCollection extends Collection
{ {
@@ -72,7 +72,7 @@ public function hasConditions()
if (is_array($this['conditions'])) { if (is_array($this['conditions'])) {
return count($this['conditions']) > 0; return count($this['conditions']) > 0;
} }
$conditionInstance = 'Wearepixel\\Cart\\CartCondition'; $conditionInstance = 'Pixeldigital\\Cart\\CartCondition';
if ($this['conditions'] instanceof $conditionInstance) { if ($this['conditions'] instanceof $conditionInstance) {
return true; return true;
} }
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
namespace Wearepixel\Cart\Validators; namespace Pixeldigital\Cart\Validators;
class CartConditionValidator extends Validator {} class CartConditionValidator extends Validator {}
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
namespace Wearepixel\Cart\Validators; namespace Pixeldigital\Cart\Validators;
class CartItemValidator extends Validator {} class CartItemValidator extends Validator {}
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Wearepixel\Cart\Validators; namespace Pixeldigital\Cart\Validators;
use Illuminate\Validation\Factory; use Illuminate\Validation\Factory;
use Illuminate\Filesystem\Filesystem; use Illuminate\Filesystem\Filesystem;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Wearepixel\Cart\Tests\Helpers; namespace Pixeldigital\Cart\Tests\Helpers;
use Illuminate\Contracts\Database\ModelIdentifier; use Illuminate\Contracts\Database\ModelIdentifier;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Wearepixel\Cart\Tests\Helpers; namespace Pixeldigital\Cart\Tests\Helpers;
class SessionMock class SessionMock
{ {
+3 -3
View File
@@ -1,8 +1,8 @@
<?php <?php
use Wearepixel\Cart\Cart; use Pixeldigital\Cart\Cart;
use Wearepixel\Cart\CartCondition; use Pixeldigital\Cart\CartCondition;
use Wearepixel\Cart\Tests\Helpers\SessionMock; use Pixeldigital\Cart\Tests\Helpers\SessionMock;
beforeEach(function () { beforeEach(function () {
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher'); $events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
+26 -23
View File
@@ -1,8 +1,8 @@
<?php <?php
use Wearepixel\Cart\Cart; use Pixeldigital\Cart\Cart;
use Wearepixel\Cart\Tests\Helpers\MockProduct; use Pixeldigital\Cart\Tests\Helpers\MockProduct;
use Wearepixel\Cart\Tests\Helpers\SessionMock; use Pixeldigital\Cart\Tests\Helpers\SessionMock;
beforeEach(function () { beforeEach(function () {
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher'); $events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
@@ -60,7 +60,7 @@
expect($this->cart->getContent()->count())->toEqual(1, 'Cart content should be 1'); expect($this->cart->getContent()->count())->toEqual(1, 'Cart content should be 1');
expect($this->cart->getContent()->first()['id'])->toEqual(455, 'Item added has ID of 455 so first content ID should be 455'); expect($this->cart->getContent()->first()['id'])->toEqual(455, 'Item added has ID of 455 so first content ID should be 455');
expect($this->cart->getTotal())->toEqual(0, 'Total should be 0'); expect($this->cart->getTotal())->toEqual(0, 'Total should be 0');
})->only(); });
test('can add an item without attributes', function () { test('can add an item without attributes', function () {
$item = [ $item = [
@@ -149,7 +149,7 @@
$item = $this->cart->get(1); $item = $this->cart->get(1);
expect($item->attributes)->toBeInstanceOf('Wearepixel\\Cart\\ItemAttributeCollection'); expect($item->attributes)->toBeInstanceOf('Pixeldigital\\Cart\\ItemAttributeCollection');
// now lets update the item with its new attributes // now lets update the item with its new attributes
// when we get that item from cart, it should still be an instance of ItemAttributeCollection // when we get that item from cart, it should still be an instance of ItemAttributeCollection
@@ -162,7 +162,7 @@
$this->cart->update(1, $updatedItem); $this->cart->update(1, $updatedItem);
expect($item->attributes)->toBeInstanceOf('Wearepixel\\Cart\\ItemAttributeCollection'); expect($item->attributes)->toBeInstanceOf('Pixeldigital\\Cart\\ItemAttributeCollection');
}); });
test('item orders are preserved by the order they are added', function () { test('item orders are preserved by the order they are added', function () {
@@ -296,6 +296,24 @@
expect($item['quantity'])->toEqual(9.9, 'Item quantity should be 9.9'); expect($item['quantity'])->toEqual(9.9, 'Item quantity should be 9.9');
}); });
test('should throw an exception when no quantity is provided', function () {
$this->expectException('Pixeldigital\Cart\Exceptions\InvalidItemException');
$this->expectExceptionMessage('The quantity must be at least 0.1.');
$this->cart->add(455, 'Sample Item', 100.99, 0, []);
});
test('should throw an exception when no id is provided', function () {
$this->expectException('Pixeldigital\Cart\Exceptions\InvalidItemException');
$this->expectExceptionMessage('The id field is required.');
$this->cart->add('', 'Sample Item', 100.99, 2, []);
});
test('should throw an exception when no name is provided', function () {
$this->expectException('Pixeldigital\Cart\Exceptions\InvalidItemException');
$this->expectExceptionMessage('The name field is required.');
$this->cart->add(523, '', 100.99, 2, []);
});
}); });
test('cart items attributes', function () { test('cart items attributes', function () {
@@ -555,21 +573,6 @@
expect($item['quantity'])->toEqual(3, 'Item quantity of with item ID of 456 should now be reduced to 2'); expect($item['quantity'])->toEqual(3, 'Item quantity of with item ID of 456 should now be reduced to 2');
}); });
test('should throw exception when provided invalid values scenario one', function () {
$this->expectException('Wearepixel\Cart\Exceptions\InvalidItemException');
$this->cart->add(455, 'Sample Item', 100.99, 0, []);
});
test('should throw exception when provided invalid values scenario two', function () {
$this->expectException('Wearepixel\Cart\Exceptions\InvalidItemException');
$this->cart->add('', 'Sample Item', 100.99, 2, []);
});
test('should throw exception when provided invalid values scenario three', function () {
$this->expectException('Wearepixel\Cart\Exceptions\InvalidItemException');
$this->cart->add(523, '', 100.99, 2, []);
});
test('clearing cart', function () { test('clearing cart', function () {
$items = [ $items = [
[ [
@@ -643,7 +646,7 @@
expect($this->cart->getContent()->count())->toEqual(1, 'Cart should have 1 item on it'); expect($this->cart->getContent()->count())->toEqual(1, 'Cart should have 1 item on it');
expect($this->cart->getContent()->first()['id'])->toEqual(456, 'The first content must have ID of 456'); expect($this->cart->getContent()->first()['id'])->toEqual(456, 'The first content must have ID of 456');
expect($this->cart->getContent()->first()['name'])->toEqual('Sample Item', 'The first content must have name of "Sample Item"'); expect($this->cart->getContent()->first()['name'])->toEqual('Sample Item', 'The first content must have name of "Sample Item"');
expect($addedItem->model)->toBeInstanceOf('Wearepixel\Cart\Tests\Helpers\MockProduct'); expect($addedItem->model)->toBeInstanceOf('Pixeldigital\Cart\Tests\Helpers\MockProduct');
}); });
test('cart can add items with multidimensional array with associated model', function () { test('cart can add items with multidimensional array with associated model', function () {
@@ -678,7 +681,7 @@
$content = $this->cart->getContent(); $content = $this->cart->getContent();
foreach ($content as $item) { foreach ($content as $item) {
expect($item->model)->toBeInstanceOf('Wearepixel\Cart\Tests\Helpers\MockProduct'); expect($item->model)->toBeInstanceOf('Pixeldigital\Cart\Tests\Helpers\MockProduct');
} }
expect($this->cart->isEmpty())->toBeFalse('Cart should not be empty'); expect($this->cart->isEmpty())->toBeFalse('Cart should not be empty');
+2 -2
View File
@@ -1,7 +1,7 @@
<?php <?php
use Wearepixel\Cart\Cart; use Pixeldigital\Cart\Cart;
use Wearepixel\Cart\Tests\Helpers\SessionMock; use Pixeldigital\Cart\Tests\Helpers\SessionMock;
beforeEach(function () {}); beforeEach(function () {});
+2 -2
View File
@@ -1,7 +1,7 @@
<?php <?php
use Wearepixel\Cart\Cart; use Pixeldigital\Cart\Cart;
use Wearepixel\Cart\Tests\Helpers\SessionMock; use Pixeldigital\Cart\Tests\Helpers\SessionMock;
beforeEach(function () { beforeEach(function () {
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher'); $events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
+6 -6
View File
@@ -1,9 +1,9 @@
<?php <?php
use Wearepixel\Cart\Cart; use Pixeldigital\Cart\Cart;
use Wearepixel\Cart\CartCondition; use Pixeldigital\Cart\CartCondition;
use Wearepixel\Cart\Tests\Helpers\MockProduct; use Pixeldigital\Cart\Tests\Helpers\MockProduct;
use Wearepixel\Cart\Tests\Helpers\SessionMock; use Pixeldigital\Cart\Tests\Helpers\SessionMock;
beforeEach(function () { beforeEach(function () {
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher'); $events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
@@ -47,7 +47,7 @@
}); });
test('item get conditions with conditions', function () { test('item get conditions with conditions', function () {
$itemCondition1 = new \Wearepixel\Cart\CartCondition([ $itemCondition1 = new \Pixeldigital\Cart\CartCondition([
'name' => 'SALE 5%', 'name' => 'SALE 5%',
'type' => 'sale', 'type' => 'sale',
'target' => 'item', 'target' => 'item',
@@ -77,7 +77,7 @@
}); });
test('it will throw an exception when a non existing model is being associated', function () { test('it will throw an exception when a non existing model is being associated', function () {
$this->expectException(\Wearepixel\Cart\Exceptions\UnknownModelException::class); $this->expectException(\Pixeldigital\Cart\Exceptions\UnknownModelException::class);
$this->expectExceptionMessage('The supplied model SomeModel does not exist.'); $this->expectExceptionMessage('The supplied model SomeModel does not exist.');
$this->cart->add(1, 'Test item', 1, 10.00)->associate('SomeModel'); $this->cart->add(1, 'Test item', 1, 10.00)->associate('SomeModel');
+2 -2
View File
@@ -1,7 +1,7 @@
<?php <?php
use Wearepixel\Cart\Cart; use Pixeldigital\Cart\Cart;
use Wearepixel\Cart\Tests\Helpers\SessionMock; use Pixeldigital\Cart\Tests\Helpers\SessionMock;
beforeEach(function () { beforeEach(function () {
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher'); $events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');