Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat test dusk #1092

Merged
merged 8 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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