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/README.md b/README.md index 733d03b..8152023 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/composer.json b/composer.json index ff0757c..80d0396 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,12 @@ "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.*", - "nesbot/carbon": "^1.26.3" + "nesbot/carbon": "^1.26.3 || ^2.0" }, "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.4" }, "autoload": { "psr-4": { diff --git a/src/Cart.php b/src/Cart.php index 2ffead8..2856606 100644 --- a/src/Cart.php +++ b/src/Cart.php @@ -164,7 +164,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); @@ -210,7 +210,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); @@ -232,7 +232,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); } @@ -599,7 +599,7 @@ class Cart 'updated_at' => date('Y-m-d H:i:s'), ]); - $this->events->fire('cart.stored'); + $this->events->dispatch('cart.stored'); } /** @@ -634,7 +634,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..0717ed7 100644 --- a/src/CartItem.php +++ b/src/CartItem.php @@ -377,7 +377,10 @@ class CartItem implements Arrayable, Jsonable return with(new $this->associatedModel())->find($this->id); } - return; + case 'modelFQCN': + if (isset($this->associatedModel)) { + return $this->associatedModel; + } default: return; diff --git a/tests/CartTest.php b/tests/CartTest.php index 1c01b37..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 { @@ -59,7 +58,7 @@ class CartTest extends TestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -215,11 +214,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 +227,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 +240,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 +253,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 +346,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 +612,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 +626,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 +830,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', ]);