From 149947566397ce1efc7bd19fdba57dcf1bacf325 Mon Sep 17 00:00:00 2001 From: Patrick Henninger Date: Fri, 1 Mar 2019 14:59:44 +0100 Subject: [PATCH 1/4] Replaced deprecated OR operator https://getcomposer.org/doc/articles/versions.md#version-range Added 5.8.* compatibility Updated dependency versions Added phpunit result cache to gitignore --- .gitignore | 3 ++- composer.json | 12 ++++++------ src/Cart.php | 10 +++++----- src/CartItem.php | 7 +++++++ tests/CartTest.php | 39 +++++++++++++++++++++++---------------- 5 files changed, 43 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index ab0a298..b9eaa7d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ composer.phar composer.lock .DS_Store -coverage.xml \ No newline at end of file +coverage.xml +.phpunit.result.cache \ No newline at end of file diff --git a/composer.json b/composer.json index d2b0ad4..5875edd 100644 --- a/composer.json +++ b/composer.json @@ -14,14 +14,14 @@ } ], "require": { - "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*", - "illuminate/session": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*", - "illuminate/events": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*" + "illuminate/support": "5.1.*||5.2.*||5.3.*||5.4.*||5.5.*||5.6.*||5.7.*||5.8.*", + "illuminate/session": "5.1.*||5.2.*||5.3.*||5.4.*||5.5.*||5.6.*||5.7.*||5.8.*", + "illuminate/events": "5.1.*||5.2.*||5.3.*||5.4.*||5.5.*||5.6.*||5.7.*||5.8.*" }, "require-dev": { - "phpunit/phpunit": "~5.0|~6.0|~7.0", - "mockery/mockery": "~0.9.0", - "orchestra/testbench": "~3.1" + "phpunit/phpunit": "~5.0||~6.0||~7.0||~8.0", + "mockery/mockery": "^1.0", + "orchestra/testbench": "^3.1" }, "autoload": { "psr-4": { diff --git a/src/Cart.php b/src/Cart.php index 7e7e6b3..cbb2699 100644 --- a/src/Cart.php +++ b/src/Cart.php @@ -149,7 +149,7 @@ class Cart $content->put($item->rowId, $item); - $this->events->fire('cart.added', $item); + $this->events->dispatch('cart.added', $item); $this->session->put($this->instance, $content); @@ -195,7 +195,7 @@ class Cart $content->put($cartItem->rowId, $cartItem); } - $this->events->fire('cart.updated', $cartItem); + $this->events->dispatch('cart.updated', $cartItem); $this->session->put($this->instance, $content); @@ -217,7 +217,7 @@ class Cart $content->pull($cartItem->rowId); - $this->events->fire('cart.removed', $cartItem); + $this->events->dispatch('cart.removed', $cartItem); $this->session->put($this->instance, $content); } @@ -582,7 +582,7 @@ class Cart 'content' => serialize($content), ]); - $this->events->fire('cart.stored'); + $this->events->dispatch('cart.stored'); } /** @@ -617,7 +617,7 @@ class Cart $content->put($cartItem->rowId, $cartItem); } - $this->events->fire('cart.restored'); + $this->events->dispatch('cart.restored'); $this->session->put($this->instance, $content); diff --git a/src/CartItem.php b/src/CartItem.php index ffafaf9..c0d058e 100644 --- a/src/CartItem.php +++ b/src/CartItem.php @@ -379,6 +379,13 @@ class CartItem implements Arrayable, Jsonable return; + case 'modelFQCN': + if (isset($this->associatedModel)) { + return $this->associatedModel; + } + + return; + default: return; } diff --git a/tests/CartTest.php b/tests/CartTest.php index 1c01b37..d965e41 100644 --- a/tests/CartTest.php +++ b/tests/CartTest.php @@ -59,7 +59,7 @@ class CartTest extends TestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -215,11 +215,12 @@ class CartTest extends TestCase /** * @test - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Please supply a valid identifier. */ public function it_will_validate_the_identifier() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Please supply a valid identifier.'); + $cart = $this->getCart(); $cart->add(null, 'Some title', 1, 10.00); @@ -227,11 +228,12 @@ class CartTest extends TestCase /** * @test - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Please supply a valid name. */ public function it_will_validate_the_name() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Please supply a valid name.'); + $cart = $this->getCart(); $cart->add(1, null, 1, 10.00); @@ -239,11 +241,12 @@ class CartTest extends TestCase /** * @test - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Please supply a valid quantity. */ public function it_will_validate_the_quantity() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Please supply a valid quantity.'); + $cart = $this->getCart(); $cart->add(1, 'Some title', 'invalid', 10.00); @@ -251,11 +254,12 @@ class CartTest extends TestCase /** * @test - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Please supply a valid price. */ public function it_will_validate_the_price() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Please supply a valid price.'); + $cart = $this->getCart(); $cart->add(1, 'Some title', 1, 'invalid'); @@ -343,10 +347,11 @@ class CartTest extends TestCase /** * @test - * @expectedException \Gloudemans\Shoppingcart\Exceptions\InvalidRowIDException */ public function it_will_throw_an_exception_if_a_rowid_was_not_found() { + $this->expectException(\Gloudemans\Shoppingcart\Exceptions\InvalidRowIDException::class); + $cart = $this->getCart(); $cart->add(new BuyableProduct()); @@ -608,7 +613,7 @@ class CartTest extends TestCase $cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da'); - $this->assertContains(BuyableProduct::class, Assert::readAttribute($cartItem, 'associatedModel')); + $this->assertEquals(BuyableProduct::class, $cartItem->modelFQCN); } /** @test */ @@ -622,16 +627,17 @@ class CartTest extends TestCase $cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da'); - $this->assertEquals(ProductModel::class, Assert::readAttribute($cartItem, 'associatedModel')); + $this->assertEquals(ProductModel::class, $cartItem->modelFQCN); } /** * @test - * @expectedException \Gloudemans\Shoppingcart\Exceptions\UnknownModelException - * @expectedExceptionMessage The supplied model SomeModel does not exist. */ public function it_will_throw_an_exception_when_a_non_existing_model_is_being_associated() { + $this->expectException(\Gloudemans\Shoppingcart\Exceptions\UnknownModelException::class); + $this->expectExceptionMessage('The supplied model SomeModel does not exist.'); + $cart = $this->getCart(); $cart->add(1, 'Test item', 1, 10.00); @@ -825,11 +831,12 @@ class CartTest extends TestCase /** * @test - * @expectedException \Gloudemans\Shoppingcart\Exceptions\CartAlreadyStoredException - * @expectedExceptionMessage A cart with identifier 123 was already stored. */ public function it_will_throw_an_exception_when_a_cart_was_already_stored_using_the_specified_identifier() { + $this->expectException(\Gloudemans\Shoppingcart\Exceptions\CartAlreadyStoredException::class); + $this->expectExceptionMessage('A cart with identifier 123 was already stored.'); + $this->artisan('migrate', [ '--database' => 'testing', ]); From c0cc008c85ad57146bc713014444e52279ced162 Mon Sep 17 00:00:00 2001 From: Patrick Henninger Date: Fri, 1 Mar 2019 15:03:24 +0100 Subject: [PATCH 2/4] Codestyle Update version in readme --- README.md | 2 +- tests/CartTest.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index d1819ed..c227e1c 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Latest Unstable Version](https://poser.pugx.org/bumbummen99/shoppingcart/v/unstable)](https://packagist.org/packages/bumbummen99/shoppingcart) [![License](https://poser.pugx.org/bumbummen99/shoppingcart/license)](https://packagist.org/packages/bumbummen99/shoppingcart) -This is a fork of [Crisane's LaravelShoppingcart](https://github.com/Crinsane/LaravelShoppingcart) extended with minor features compatible with Laravel 5.7. +This is a fork of [Crisane's LaravelShoppingcart](https://github.com/Crinsane/LaravelShoppingcart) extended with minor features compatible with Laravel 5.8. ## Installation diff --git a/tests/CartTest.php b/tests/CartTest.php index d965e41..b51863d 100644 --- a/tests/CartTest.php +++ b/tests/CartTest.php @@ -15,7 +15,6 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\Event; use Mockery; use Orchestra\Testbench\TestCase; -use PHPUnit\Framework\Assert; class CartTest extends TestCase { From e83371d5429be751ad92e1a30a12d121a20f030a Mon Sep 17 00:00:00 2001 From: Patrick Henninger Date: Fri, 1 Mar 2019 15:11:31 +0100 Subject: [PATCH 3/4] Removed unneccessary return statements --- src/CartItem.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/CartItem.php b/src/CartItem.php index c0d058e..0717ed7 100644 --- a/src/CartItem.php +++ b/src/CartItem.php @@ -377,15 +377,11 @@ class CartItem implements Arrayable, Jsonable return with(new $this->associatedModel())->find($this->id); } - return; - case 'modelFQCN': if (isset($this->associatedModel)) { return $this->associatedModel; } - return; - default: return; } From 7b9b47039be85fc921c54e667d09c0c72497b69e Mon Sep 17 00:00:00 2001 From: Patrick Henninger Date: Fri, 1 Mar 2019 15:19:35 +0100 Subject: [PATCH 4/4] Remove incompatible versions composer.json --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 5875edd..daac79e 100644 --- a/composer.json +++ b/composer.json @@ -14,14 +14,14 @@ } ], "require": { - "illuminate/support": "5.1.*||5.2.*||5.3.*||5.4.*||5.5.*||5.6.*||5.7.*||5.8.*", - "illuminate/session": "5.1.*||5.2.*||5.3.*||5.4.*||5.5.*||5.6.*||5.7.*||5.8.*", - "illuminate/events": "5.1.*||5.2.*||5.3.*||5.4.*||5.5.*||5.6.*||5.7.*||5.8.*" + "illuminate/support": "5.4.*||5.5.*||5.6.*||5.7.*||5.8.*", + "illuminate/session": "5.4.*||5.5.*||5.6.*||5.7.*||5.8.*", + "illuminate/events": "5.4.*||5.5.*||5.6.*||5.7.*||5.8.*" }, "require-dev": { "phpunit/phpunit": "~5.0||~6.0||~7.0||~8.0", "mockery/mockery": "^1.0", - "orchestra/testbench": "^3.1" + "orchestra/testbench": "^3.4" }, "autoload": { "psr-4": {