Merge pull request #4 from bumbummen99/5.8

Laravel 5.8
This commit is contained in:
Patrick
2019-03-01 15:15:39 +01:00
committed by GitHub
6 changed files with 41 additions and 31 deletions

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@ composer.phar
composer.lock composer.lock
.DS_Store .DS_Store
coverage.xml coverage.xml
.phpunit.result.cache

View File

@@ -7,7 +7,7 @@
[![Latest Unstable Version](https://poser.pugx.org/bumbummen99/shoppingcart/v/unstable)](https://packagist.org/packages/bumbummen99/shoppingcart) [![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) [![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 ## Installation

View File

@@ -14,14 +14,14 @@
} }
], ],
"require": { "require": {
"illuminate/support": "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.*", "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.*" "illuminate/events": "5.1.*||5.2.*||5.3.*||5.4.*||5.5.*||5.6.*||5.7.*||5.8.*"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~5.0|~6.0|~7.0", "phpunit/phpunit": "~5.0||~6.0||~7.0||~8.0",
"mockery/mockery": "~0.9.0", "mockery/mockery": "^1.0",
"orchestra/testbench": "~3.1" "orchestra/testbench": "^3.1"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

View File

@@ -149,7 +149,7 @@ class Cart
$content->put($item->rowId, $item); $content->put($item->rowId, $item);
$this->events->fire('cart.added', $item); $this->events->dispatch('cart.added', $item);
$this->session->put($this->instance, $content); $this->session->put($this->instance, $content);
@@ -195,7 +195,7 @@ class Cart
$content->put($cartItem->rowId, $cartItem); $content->put($cartItem->rowId, $cartItem);
} }
$this->events->fire('cart.updated', $cartItem); $this->events->dispatch('cart.updated', $cartItem);
$this->session->put($this->instance, $content); $this->session->put($this->instance, $content);
@@ -217,7 +217,7 @@ class Cart
$content->pull($cartItem->rowId); $content->pull($cartItem->rowId);
$this->events->fire('cart.removed', $cartItem); $this->events->dispatch('cart.removed', $cartItem);
$this->session->put($this->instance, $content); $this->session->put($this->instance, $content);
} }
@@ -582,7 +582,7 @@ class Cart
'content' => serialize($content), 'content' => serialize($content),
]); ]);
$this->events->fire('cart.stored'); $this->events->dispatch('cart.stored');
} }
/** /**
@@ -617,7 +617,7 @@ class Cart
$content->put($cartItem->rowId, $cartItem); $content->put($cartItem->rowId, $cartItem);
} }
$this->events->fire('cart.restored'); $this->events->dispatch('cart.restored');
$this->session->put($this->instance, $content); $this->session->put($this->instance, $content);

View File

@@ -377,7 +377,10 @@ class CartItem implements Arrayable, Jsonable
return with(new $this->associatedModel())->find($this->id); return with(new $this->associatedModel())->find($this->id);
} }
return; case 'modelFQCN':
if (isset($this->associatedModel)) {
return $this->associatedModel;
}
default: default:
return; return;

View File

@@ -15,7 +15,6 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Mockery; use Mockery;
use Orchestra\Testbench\TestCase; use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Assert;
class CartTest extends TestCase class CartTest extends TestCase
{ {
@@ -59,7 +58,7 @@ class CartTest extends TestCase
* *
* @return void * @return void
*/ */
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@@ -215,11 +214,12 @@ class CartTest extends TestCase
/** /**
* @test * @test
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Please supply a valid identifier.
*/ */
public function it_will_validate_the_identifier() public function it_will_validate_the_identifier()
{ {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Please supply a valid identifier.');
$cart = $this->getCart(); $cart = $this->getCart();
$cart->add(null, 'Some title', 1, 10.00); $cart->add(null, 'Some title', 1, 10.00);
@@ -227,11 +227,12 @@ class CartTest extends TestCase
/** /**
* @test * @test
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Please supply a valid name.
*/ */
public function it_will_validate_the_name() public function it_will_validate_the_name()
{ {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Please supply a valid name.');
$cart = $this->getCart(); $cart = $this->getCart();
$cart->add(1, null, 1, 10.00); $cart->add(1, null, 1, 10.00);
@@ -239,11 +240,12 @@ class CartTest extends TestCase
/** /**
* @test * @test
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Please supply a valid quantity.
*/ */
public function it_will_validate_the_quantity() public function it_will_validate_the_quantity()
{ {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Please supply a valid quantity.');
$cart = $this->getCart(); $cart = $this->getCart();
$cart->add(1, 'Some title', 'invalid', 10.00); $cart->add(1, 'Some title', 'invalid', 10.00);
@@ -251,11 +253,12 @@ class CartTest extends TestCase
/** /**
* @test * @test
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Please supply a valid price.
*/ */
public function it_will_validate_the_price() public function it_will_validate_the_price()
{ {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Please supply a valid price.');
$cart = $this->getCart(); $cart = $this->getCart();
$cart->add(1, 'Some title', 1, 'invalid'); $cart->add(1, 'Some title', 1, 'invalid');
@@ -343,10 +346,11 @@ class CartTest extends TestCase
/** /**
* @test * @test
* @expectedException \Gloudemans\Shoppingcart\Exceptions\InvalidRowIDException
*/ */
public function it_will_throw_an_exception_if_a_rowid_was_not_found() public function it_will_throw_an_exception_if_a_rowid_was_not_found()
{ {
$this->expectException(\Gloudemans\Shoppingcart\Exceptions\InvalidRowIDException::class);
$cart = $this->getCart(); $cart = $this->getCart();
$cart->add(new BuyableProduct()); $cart->add(new BuyableProduct());
@@ -608,7 +612,7 @@ class CartTest extends TestCase
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da'); $cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
$this->assertContains(BuyableProduct::class, Assert::readAttribute($cartItem, 'associatedModel')); $this->assertEquals(BuyableProduct::class, $cartItem->modelFQCN);
} }
/** @test */ /** @test */
@@ -622,16 +626,17 @@ class CartTest extends TestCase
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da'); $cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
$this->assertEquals(ProductModel::class, Assert::readAttribute($cartItem, 'associatedModel')); $this->assertEquals(ProductModel::class, $cartItem->modelFQCN);
} }
/** /**
* @test * @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() 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 = $this->getCart();
$cart->add(1, 'Test item', 1, 10.00); $cart->add(1, 'Test item', 1, 10.00);
@@ -825,11 +830,12 @@ class CartTest extends TestCase
/** /**
* @test * @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() 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', [ $this->artisan('migrate', [
'--database' => 'testing', '--database' => 'testing',
]); ]);