diff --git a/composer.json b/composer.json index 0da4505..e8edad6 100644 --- a/composer.json +++ b/composer.json @@ -15,15 +15,20 @@ "illuminate/events": "5.1.*|5.2.*|5.3.*|5.4.*" }, "require-dev": { - "phpunit/phpunit": "~4.0", + "phpunit/phpunit": "~5.0", "mockery/mockery": "~0.9.0", - "orchestra/testbench": "~3.0" + "orchestra/testbench": "~3.1" }, "autoload": { "psr-4": { "Gloudemans\\Shoppingcart\\": "src/" } }, + "autoload-dev": { + "psr-4": { + "Gloudemans\\Tests\\Shoppingcart\\": "tests/" + } + }, "suggest": { "gloudemans/notify": "Simple flash notifications for Laravel" }, diff --git a/tests/CartAssertions.php b/tests/CartAssertions.php index 69b0211..6186860 100644 --- a/tests/CartAssertions.php +++ b/tests/CartAssertions.php @@ -1,11 +1,12 @@ content(), "Expected the cart to contain {$rows} rows, but got {$actual}."); } - -} \ No newline at end of file +} diff --git a/tests/CartTest.php b/tests/CartTest.php index 33504b5..4813fb4 100644 --- a/tests/CartTest.php +++ b/tests/CartTest.php @@ -1,10 +1,21 @@ '', ]); } - + + protected function setUp() + { + parent::setUp(); + + $this->app->afterResolving('migrator', function ($migrator) { + $migrator->path(realpath(__DIR__.'/../database/migrations')); + }); + } + + /** @test */ public function it_has_a_default_instance() { @@ -89,7 +110,7 @@ class CartTest extends Orchestra\Testbench\TestCase $cartItem = $cart->add($item); - $this->assertInstanceOf(\Gloudemans\Shoppingcart\CartItem::class, $cartItem); + $this->assertInstanceOf(CartItem::class, $cartItem); $this->assertEquals('027c91341fd5cf4d2579b49c4b6a90da', $cartItem->rowId); } @@ -122,7 +143,7 @@ class CartTest extends Orchestra\Testbench\TestCase $this->assertTrue(is_array($cartItems)); $this->assertCount(2, $cartItems); - $this->assertContainsOnlyInstancesOf(\Gloudemans\Shoppingcart\CartItem::class, $cartItems); + $this->assertContainsOnlyInstancesOf(CartItem::class, $cartItems); } /** @test */ @@ -179,7 +200,7 @@ class CartTest extends Orchestra\Testbench\TestCase $cartItem = $cart->get('07d5da5550494c62daf9993cf954303f'); - $this->assertInstanceOf(\Gloudemans\Shoppingcart\CartItem::class, $cartItem); + $this->assertInstanceOf(CartItem::class, $cartItem); $this->assertEquals('XL', $cartItem->options->size); $this->assertEquals('red', $cartItem->options->color); } @@ -426,7 +447,7 @@ class CartTest extends Orchestra\Testbench\TestCase $cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da'); - $this->assertInstanceOf(\Gloudemans\Shoppingcart\CartItem::class, $cartItem); + $this->assertInstanceOf(CartItem::class, $cartItem); } /** @test */ @@ -442,7 +463,7 @@ class CartTest extends Orchestra\Testbench\TestCase $content = $cart->content(); - $this->assertInstanceOf(\Illuminate\Support\Collection::class, $content); + $this->assertInstanceOf(Collection::class, $content); $this->assertCount(2, $content); } @@ -453,7 +474,7 @@ class CartTest extends Orchestra\Testbench\TestCase $content = $cart->content(); - $this->assertInstanceOf(\Illuminate\Support\Collection::class, $content); + $this->assertInstanceOf(Collection::class, $content); $this->assertCount(0, $content); } @@ -470,7 +491,7 @@ class CartTest extends Orchestra\Testbench\TestCase $content = $cart->content(); - $this->assertInstanceOf(\Illuminate\Support\Collection::class, $content); + $this->assertInstanceOf(Collection::class, $content); $this->assertEquals([ '027c91341fd5cf4d2579b49c4b6a90da' => [ 'rowId' => '027c91341fd5cf4d2579b49c4b6a90da', @@ -480,7 +501,7 @@ class CartTest extends Orchestra\Testbench\TestCase 'price' => 10.00, 'tax' => 2.10, 'subtotal' => 10.0, - 'options' => new \Gloudemans\Shoppingcart\CartItemOptions, + 'options' => new CartItemOptions, ], '370d08585360f5c568b18d1f2e4ca1df' => [ 'rowId' => '370d08585360f5c568b18d1f2e4ca1df', @@ -490,7 +511,7 @@ class CartTest extends Orchestra\Testbench\TestCase 'price' => 10.00, 'tax' => 2.10, 'subtotal' => 10.0, - 'options' => new \Gloudemans\Shoppingcart\CartItemOptions, + 'options' => new CartItemOptions, ] ], $content->toArray()); } @@ -556,9 +577,9 @@ class CartTest extends Orchestra\Testbench\TestCase return $cartItem->name == 'Some item'; }); - $this->assertInstanceOf(\Illuminate\Support\Collection::class, $cartItem); + $this->assertInstanceOf(Collection::class, $cartItem); $this->assertCount(1, $cartItem); - $this->assertInstanceOf(\Gloudemans\Shoppingcart\CartItem::class, $cartItem->first()); + $this->assertInstanceOf(CartItem::class, $cartItem->first()); $this->assertEquals(1, $cartItem->first()->id); } @@ -579,7 +600,7 @@ class CartTest extends Orchestra\Testbench\TestCase return $cartItem->name == 'Some item'; }); - $this->assertInstanceOf(\Illuminate\Support\Collection::class, $cartItem); + $this->assertInstanceOf(Collection::class, $cartItem); } /** @test */ @@ -597,9 +618,9 @@ class CartTest extends Orchestra\Testbench\TestCase return $cartItem->options->color == 'red'; }); - $this->assertInstanceOf(\Illuminate\Support\Collection::class, $cartItem); + $this->assertInstanceOf(Collection::class, $cartItem); $this->assertCount(1, $cartItem); - $this->assertInstanceOf(\Gloudemans\Shoppingcart\CartItem::class, $cartItem->first()); + $this->assertInstanceOf(CartItem::class, $cartItem->first()); $this->assertEquals(1, $cartItem->first()->id); } @@ -614,7 +635,7 @@ class CartTest extends Orchestra\Testbench\TestCase $cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da'); - $this->assertContains('Gloudemans_Shoppingcart_Contracts_Buyable', PHPUnit_Framework_Assert::readAttribute($cartItem, 'associatedModel')); + $this->assertContains('Gloudemans_Shoppingcart_Contracts_Buyable', Assert::readAttribute($cartItem, 'associatedModel')); } /** @test */ @@ -630,7 +651,7 @@ class CartTest extends Orchestra\Testbench\TestCase $cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da'); - $this->assertEquals(get_class($model), PHPUnit_Framework_Assert::readAttribute($cartItem, 'associatedModel')); + $this->assertEquals(get_class($model), Assert::readAttribute($cartItem, 'associatedModel')); } /** @@ -839,7 +860,6 @@ class CartTest extends Orchestra\Testbench\TestCase { $this->artisan('migrate', [ '--database' => 'testing', - '--realpath' => realpath(__DIR__.'/../database/migrations'), ]); $this->expectsEvents('cart.stored'); @@ -854,7 +874,7 @@ class CartTest extends Orchestra\Testbench\TestCase $serialized = serialize($cart->content()); - $this->seeInDatabase('shoppingcart', ['identifier' => $identifier, 'instance' => 'default', 'content' => $serialized]); + $this->assertDatabaseHas('shoppingcart', ['identifier' => $identifier, 'instance' => 'default', 'content' => $serialized]); } /** @@ -866,7 +886,6 @@ class CartTest extends Orchestra\Testbench\TestCase { $this->artisan('migrate', [ '--database' => 'testing', - '--realpath' => realpath(__DIR__.'/../database/migrations'), ]); $this->expectsEvents('cart.stored'); @@ -887,7 +906,6 @@ class CartTest extends Orchestra\Testbench\TestCase { $this->artisan('migrate', [ '--database' => 'testing', - '--realpath' => realpath(__DIR__.'/../database/migrations'), ]); $this->expectsEvents('cart.restored'); @@ -908,7 +926,7 @@ class CartTest extends Orchestra\Testbench\TestCase $this->assertItemsInCart(1, $cart); - $this->dontSeeInDatabase('shoppingcart', ['identifier' => $identifier, 'instance' => 'default']); + $this->assertDatabaseMissing('shoppingcart', ['identifier' => $identifier, 'instance' => 'default']); } /** @test */ @@ -916,7 +934,6 @@ class CartTest extends Orchestra\Testbench\TestCase { $this->artisan('migrate', [ '--database' => 'testing', - '--realpath' => realpath(__DIR__.'/../database/migrations'), ]); $cart = $this->getCart(); @@ -956,15 +973,15 @@ class CartTest extends Orchestra\Testbench\TestCase { $this->app['config']->set('cart.destroy_on_logout', true); - $session = Mockery::mock(\Illuminate\Session\SessionManager::class); + $session = Mockery::mock(SessionManager::class); $session->shouldReceive('forget')->once()->with('cart'); - $this->app->instance(\Illuminate\Session\SessionManager::class, $session); + $this->app->instance(SessionManager::class, $session); - $user = Mockery::mock(\Illuminate\Contracts\Auth\Authenticatable::class); + $user = Mockery::mock(Authenticatable::class); - event(new \Illuminate\Auth\Events\Logout($user)); + event(new Logout($user)); } /** @@ -1019,4 +1036,4 @@ class CartTest extends Orchestra\Testbench\TestCase class ModelStub { public $someValue = 'Some value'; public function find($id) { return $this; } -} \ No newline at end of file +}