From 37dc7a30da0df03b320e6af46abbfebac34026ef Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Thu, 20 Aug 2020 12:09:26 +0200 Subject: [PATCH] Feat test dusk (#1092) * Test with Dusk * No UI * composer fix-style * Update BrowserTestCase.php * Update matrix * Update run-tests.yml * Update composer.json * Start with 6.x Co-authored-by: laravel-debugbar --- .github/workflows/run-tests.yml | 19 ++++--- .gitignore | 1 + composer.json | 4 +- tests/BrowserTestCase.php | 36 +++++++++++++ tests/DebugbarBrowserTest.php | 91 +++++++++++++++++++++++++++++++++ tests/TestCase.php | 2 - 6 files changed, 144 insertions(+), 9 deletions(-) create mode 100644 tests/BrowserTestCase.php create mode 100644 tests/DebugbarBrowserTest.php diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index c0b9235c..f9a4f94b 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,11 +12,8 @@ jobs: strategy: matrix: php: [7.4, 7.3, 7.2] - laravel: [7.*, 6.*, 5.5.*] + laravel: [6.*, 7.*] dependency-version: [prefer-lowest, prefer-stable] - exclude: - - laravel: 5.5.* - php: 7.4 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} @@ -33,8 +30,18 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" --no-update --no-progress - composer update --${{ matrix.dependency-version }} --prefer-dist --no-suggest --no-progress + composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update + composer update --${{ matrix.dependency-version }} --prefer-dist --no-progress + + - name: Update Dusk Chromedriver + run: vendor/bin/dusk-updater detect --auto-update - name: Execute Unit Tests run: composer test + + - name: Upload Failed Screenshots + uses: actions/upload-artifact@v2-preview + if: failure() + with: + name: screenshots + path: tests/Browser/screenshots/* diff --git a/.gitignore b/.gitignore index 08dc6ae9..7639d5a9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ composer.phar composer.lock .DS_Store .phpunit.result.cache +/tests/Browser \ No newline at end of file diff --git a/composer.json b/composer.json index 6576f8ba..d7fa826d 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": ">=7.0", + "php": ">=7.1", "maximebf/debugbar": "^1.16.3", "illuminate/routing": "^5.5|^6|^7", "illuminate/session": "^5.5|^6|^7", @@ -20,6 +20,8 @@ }, "require-dev": { "orchestra/testbench": "^3.5.11|^4.0|^5.0", + "orchestra/testbench-dusk": "^3.5.11|^4.0|^5.0", + "orchestra/dusk-updater": "^1", "phpunit/phpunit": "^6.0|^7.0|^8.5|^9.0", "squizlabs/php_codesniffer": "^3.5" }, diff --git a/tests/BrowserTestCase.php b/tests/BrowserTestCase.php new file mode 100644 index 00000000..cdeae841 --- /dev/null +++ b/tests/BrowserTestCase.php @@ -0,0 +1,36 @@ + Facade::class]; + } +} diff --git a/tests/DebugbarBrowserTest.php b/tests/DebugbarBrowserTest.php new file mode 100644 index 00000000..b23c0423 --- /dev/null +++ b/tests/DebugbarBrowserTest.php @@ -0,0 +1,91 @@ +set('app.debug', true); + + /** @var Router $router */ + $router = $app['router']; + + $this->addWebRoutes($router); + $this->addApiRoutes($router); + + \Orchestra\Testbench\Dusk\Options::withoutUI(); + } + + /** + * @param Router $router + */ + protected function addWebRoutes(Router $router) + { + $router->get('web/plain', [ + 'uses' => function () { + return 'PONG'; + } + ]); + + $router->get('web/html', [ + 'uses' => function () { + return ' HTMLPONG'; + } + ]); + } + + /** + * @param Router $router + */ + protected function addApiRoutes(Router $router) + { + $router->get('api/ping', [ + 'uses' => function () { + return response()->json(['status' => 'pong']); + } + ]); + } + + public function testItInjectsOnPlainText() + { + $this->browse(function ($browser) { + $browser->visit('web/plain') + ->assertSee('PONG') + ->waitFor('.phpdebugbar') + ->assertSee('GET web/plain'); + }); + } + + public function testItInjectsOnHtml() + { + $this->browse(function ($browser) { + $browser->visit('web/html') + ->assertSee('HTMLPONG') + ->waitFor('.phpdebugbar') + ->assertSee('GET web/html'); + }); + } + + public function testItDoesntInjectOnJson() + { + $this->browse(function ($browser) { + $browser->visit('api/ping') + ->assertSee('pong') + ->assertSourceMissing('debugbar') + ->assertDontSee('GET api/ping'); + }); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 3c81598f..207bc78f 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -9,8 +9,6 @@ class TestCase extends Orchestra { - /** @var \Barryvdh\Debugbar\LaravelDebugbar */ - private $debugbar; /** * Get package providers.