Skip to content

Commit

Permalink
Feat test dusk (barryvdh#1092)
Browse files Browse the repository at this point in the history
* 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 <laravel-debugbar@users.noreply.github.com>
  • Loading branch information
barryvdh and laravel-debugbar authored Aug 20, 2020
1 parent 4fe9d74 commit 37dc7a3
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 9 deletions.
19 changes: 13 additions & 6 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand All @@ -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/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.phar
composer.lock
.DS_Store
.phpunit.result.cache
/tests/Browser
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
},
Expand Down
36 changes: 36 additions & 0 deletions tests/BrowserTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Barryvdh\Debugbar\Tests;

use Barryvdh\Debugbar\Facade;
use Barryvdh\Debugbar\ServiceProvider;

class BrowserTestCase extends \Orchestra\Testbench\Dusk\TestCase
{
protected static $baseServeHost = '127.0.0.1';
protected static $baseServePort = 9292;

/**
* Get package providers.
*
* @param \Illuminate\Foundation\Application $app
*
* @return array
*/
protected function getPackageProviders($app)
{
return [ServiceProvider::class];
}

/**
* Get package aliases.
*
* @param \Illuminate\Foundation\Application $app
*
* @return array
*/
protected function getPackageAliases($app)
{
return ['Debugbar' => Facade::class];
}
}
91 changes: 91 additions & 0 deletions tests/DebugbarBrowserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace Barryvdh\Debugbar\Tests;

use Illuminate\Routing\Router;

class DebugbarBrowserTest extends BrowserTestCase
{

/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
*
* @return void
*/
protected function getEnvironmentSetUp($app)
{
$app['env'] = 'local';

// $app['config']->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 '<html><head></head><body>HTMLPONG</body></html>';
}
]);
}

/**
* @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');
});
}
}
2 changes: 0 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

class TestCase extends Orchestra
{
/** @var \Barryvdh\Debugbar\LaravelDebugbar */
private $debugbar;

/**
* Get package providers.
Expand Down

0 comments on commit 37dc7a3

Please sign in to comment.