From 09e1d5a11d3d481b7204468f5980be83bbab8bc2 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Thu, 2 Feb 2017 16:48:42 -0500 Subject: [PATCH] 68 - Removing the Browser Kit Dependency --- composer.json | 3 +- composer.lock | 163 ++++++++-------------- tests/BrowserKitTestCase.php | 39 ------ tests/features/PurchaseTicketsTest.php | 19 ++- tests/features/ViewConcertListingTest.php | 27 ++-- 5 files changed, 90 insertions(+), 161 deletions(-) delete mode 100644 tests/BrowserKitTestCase.php diff --git a/composer.json b/composer.json index 2a2d6f2..94261b2 100644 --- a/composer.json +++ b/composer.json @@ -9,8 +9,7 @@ "laravel/framework": "5.4.*", "zondicons/blade-bridge": "^0.1.0", "stripe/stripe-php": "^4.3", - "guzzlehttp/guzzle": "^6.2", - "laravel/browser-kit-testing": "^1.0" + "guzzlehttp/guzzle": "^6.2" }, "require-dev": { "fzaninotto/faker": "~1.4", diff --git a/composer.lock b/composer.lock index d6ecce3..5a24218 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "1a295f4015af6d87c280a4b5724dffdf", - "content-hash": "dc21df0223e675f996fc46355c30b69c", + "hash": "828692e34e61c07c42dabf44fb20ac21", + "content-hash": "e657ab8d9ccb9253049b2ef80ba123f6", "packages": [ { "name": "doctrine/inflector", @@ -287,53 +287,6 @@ ], "time": "2016-06-24 23:00:38" }, - { - "name": "laravel/browser-kit-testing", - "version": "v1.0.2", - "source": { - "type": "git", - "url": "https://github.com/laravel/browser-kit-testing.git", - "reference": "60e038e3dcfef2977347f9610c14b48721802278" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/laravel/browser-kit-testing/zipball/60e038e3dcfef2977347f9610c14b48721802278", - "reference": "60e038e3dcfef2977347f9610c14b48721802278", - "shasum": "" - }, - "require": { - "php": ">=5.5.9", - "symfony/css-selector": "3.1.*", - "symfony/dom-crawler": "3.1.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-4": { - "Laravel\\BrowserKitTesting\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Taylor Otwell", - "email": "taylor@laravel.com" - } - ], - "description": "Provides backwards compatibility for BrowserKit testing in Laravel 5.4.", - "keywords": [ - "laravel", - "testing" - ], - "time": "2017-01-25 13:07:25" - }, { "name": "laravel/framework", "version": "v5.4.8", @@ -1273,62 +1226,6 @@ "homepage": "https://symfony.com", "time": "2017-01-02 20:32:22" }, - { - "name": "symfony/dom-crawler", - "version": "v3.1.10", - "source": { - "type": "git", - "url": "https://github.com/symfony/dom-crawler.git", - "reference": "7eede2a901a19928494194f7d1815a77b9a473a0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/7eede2a901a19928494194f7d1815a77b9a473a0", - "reference": "7eede2a901a19928494194f7d1815a77b9a473a0", - "shasum": "" - }, - "require": { - "php": ">=5.5.9", - "symfony/polyfill-mbstring": "~1.0" - }, - "require-dev": { - "symfony/css-selector": "~2.8|~3.0" - }, - "suggest": { - "symfony/css-selector": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.1-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\DomCrawler\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony DomCrawler Component", - "homepage": "https://symfony.com", - "time": "2017-01-21 17:13:55" - }, { "name": "symfony/event-dispatcher", "version": "v3.2.2", @@ -3383,6 +3280,62 @@ "homepage": "https://github.com/sebastianbergmann/version", "time": "2016-10-03 07:35:21" }, + { + "name": "symfony/dom-crawler", + "version": "v3.1.10", + "source": { + "type": "git", + "url": "https://github.com/symfony/dom-crawler.git", + "reference": "7eede2a901a19928494194f7d1815a77b9a473a0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/7eede2a901a19928494194f7d1815a77b9a473a0", + "reference": "7eede2a901a19928494194f7d1815a77b9a473a0", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/polyfill-mbstring": "~1.0" + }, + "require-dev": { + "symfony/css-selector": "~2.8|~3.0" + }, + "suggest": { + "symfony/css-selector": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\DomCrawler\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony DomCrawler Component", + "homepage": "https://symfony.com", + "time": "2017-01-21 17:13:55" + }, { "name": "symfony/yaml", "version": "v3.2.2", diff --git a/tests/BrowserKitTestCase.php b/tests/BrowserKitTestCase.php deleted file mode 100644 index 48fc714..0000000 --- a/tests/BrowserKitTestCase.php +++ /dev/null @@ -1,39 +0,0 @@ -make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); - - return $app; - } - - protected function disableExceptionHandling() - { - $this->app->instance(ExceptionHandler::class, new class extends Handler { - public function __construct() {} - public function report(Exception $e) {} - public function render($request, Exception $e) { - throw $e; - } - }); - } -} diff --git a/tests/features/PurchaseTicketsTest.php b/tests/features/PurchaseTicketsTest.php index 22b8e17..3072746 100644 --- a/tests/features/PurchaseTicketsTest.php +++ b/tests/features/PurchaseTicketsTest.php @@ -7,7 +7,7 @@ use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseTransactions; -class PurchaseTicketsTest extends BrowserKitTestCase +class PurchaseTicketsTest extends TestCase { use DatabaseMigrations; @@ -21,10 +21,25 @@ class PurchaseTicketsTest extends BrowserKitTestCase private function orderTickets($concert, $params) { $savedRequest = $this->app['request']; - $this->json('POST', "/concerts/{$concert->id}/orders", $params); + $this->response = $this->json('POST', "/concerts/{$concert->id}/orders", $params); $this->app['request'] = $savedRequest; } + private function assertResponseStatus($status) + { + $this->response->assertStatus($status); + } + + private function seeJsonSubset($data) + { + $this->response->assertJson($data); + } + + private function decodeResponseJson() + { + return $this->response->decodeResponseJson(); + } + private function assertValidationError($field) { $this->assertResponseStatus(422); diff --git a/tests/features/ViewConcertListingTest.php b/tests/features/ViewConcertListingTest.php index 6d1f460..bfca3cd 100644 --- a/tests/features/ViewConcertListingTest.php +++ b/tests/features/ViewConcertListingTest.php @@ -6,7 +6,7 @@ use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseTransactions; -class ViewConcertListingTest extends BrowserKitTestCase +class ViewConcertListingTest extends TestCase { use DatabaseMigrations; @@ -26,17 +26,18 @@ class ViewConcertListingTest extends BrowserKitTestCase 'additional_information' => 'For tickets, call (555) 555-5555.', ]); - $this->visit('/concerts/'.$concert->id); + $response = $this->get('/concerts/'.$concert->id); - $this->see('The Red Chord'); - $this->see('with Animosity and Lethargy'); - $this->see('December 13, 2016'); - $this->see('8:00pm'); - $this->see('32.50'); - $this->see('The Mosh Pit'); - $this->see('123 Example Lane'); - $this->see('Laraville, ON 17916'); - $this->see('For tickets, call (555) 555-5555.'); + $response->assertStatus(200); + $response->assertSee('The Red Chord'); + $response->assertSee('with Animosity and Lethargy'); + $response->assertSee('December 13, 2016'); + $response->assertSee('8:00pm'); + $response->assertSee('32.50'); + $response->assertSee('The Mosh Pit'); + $response->assertSee('123 Example Lane'); + $response->assertSee('Laraville, ON 17916'); + $response->assertSee('For tickets, call (555) 555-5555.'); } /** @test */ @@ -44,8 +45,8 @@ class ViewConcertListingTest extends BrowserKitTestCase { $concert = factory(Concert::class)->states('unpublished')->create(); - $this->get('/concerts/'.$concert->id); + $response = $this->get('/concerts/'.$concert->id); - $this->assertResponseStatus(404); + $response->assertStatus(404); } }