Add some event listeners and experiment with browser testing

This commit is contained in:
Nabeel Shahzad 2017-12-22 12:00:57 -06:00
parent 7fbe2f5e30
commit 74316218bc
12 changed files with 369 additions and 65 deletions

View File

@ -0,0 +1,34 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: nabeelshahzad
* Date: 12/22/17
* Time: 11:44 AM
*/
namespace App\Listeners;
use Log;
use \App\Events\UserRegistered;
/**
* Handle sending emails on different events
* @package App\Listeners
*/
class EmailEventListener
{
public function subscribe($events)
{
$events->listen(
UserRegistered::class,
'App\Listeners\EmailEventListener@onUserRegister'
);
}
public function onUserRegister(UserRegistered $event)
{
Log::info($event->user->toArray());
}
}

View File

@ -2,9 +2,9 @@
namespace App\Providers;
use Illuminate\Support\Facades\Event;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
@ -18,6 +18,10 @@ class EventServiceProvider extends ServiceProvider
],*/
];
protected $subscribe = [
'App\Listeners\EmailEventListener',
];
/**
* Register any events for your application.
*
@ -26,7 +30,5 @@ class EventServiceProvider extends ServiceProvider
public function boot()
{
parent::boot();
//
}
}

View File

@ -49,7 +49,6 @@ class UserService extends BaseService
# Let's check their rank
$this->calculatePilotRank($user);
# TODO: Send out an email
event(new UserRegistered($user));
return $user;

View File

@ -56,7 +56,8 @@
"mockery/mockery": "0.9.*",
"filp/whoops": "~2.0",
"orchestra/testbench": "v3.5.2",
"bpocallaghan/generators": "5.0.1"
"bpocallaghan/generators": "5.0.1",
"laravel/dusk": "^2.0"
},
"autoload": {
"classmap": [
@ -67,7 +68,8 @@
],
"psr-4": {
"App\\": "app/",
"Modules\\": "modules/"
"Modules\\": "modules/",
"Tests\\": "tests/"
}
},
"autoload-dev": {

234
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "00894dc47f33576663d8967f821685e3",
"content-hash": "99850757675507f6225a5bbbe35734aa",
"packages": [
{
"name": "composer/semver",
@ -427,7 +427,7 @@
"Doctrine\\DBAL\\": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -750,7 +750,7 @@
"Egulias\\EmailValidator\\": "EmailValidator"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -796,7 +796,7 @@
"Parsedown": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -856,7 +856,7 @@
"GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -914,7 +914,7 @@
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -969,7 +969,7 @@
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -1031,7 +1031,7 @@
"Hashids\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -1138,7 +1138,7 @@
"InfyOm\\AdminLTETemplates\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -1157,7 +1157,7 @@
"laravel",
"templates"
],
"time": "2017-11-25T04:43:54+00:00"
"time": "2017-11-25 04:43:54"
},
{
"name": "infyomlabs/laravel-generator",
@ -1199,7 +1199,7 @@
"src/helpers.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -1223,7 +1223,7 @@
"test",
"view"
],
"time": "2017-11-25T05:18:22+00:00"
"time": "2017-11-25 05:18:22"
},
{
"name": "jackiedo/timezonelist",
@ -1249,7 +1249,7 @@
"Jackiedo\\Timezonelist\\": "src/Jackiedo/Timezonelist"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -1360,7 +1360,7 @@
"stubs/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -1406,7 +1406,7 @@
"Traitor\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -1594,7 +1594,7 @@
"Illuminate\\": "src/Illuminate/"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -2017,7 +2017,7 @@
}
],
"description": "Bloom filter implementation",
"time": "2017-11-30T17:51:14+00:00"
"time": "2017-11-30 17:51:14"
},
{
"name": "monolog/monolog",
@ -2123,7 +2123,7 @@
"Cron\\": "src/Cron/"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -2172,7 +2172,7 @@
"src/DeepCopy/deep_copy.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -2217,11 +2217,11 @@
"VaCentral\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
"time": "2017-12-08T04:00:06+00:00"
"time": "2017-12-08 04:00:06"
},
{
"name": "nesbot/carbon",
@ -2311,7 +2311,7 @@
"PhpParser\\": "lib/PhpParser"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
@ -2744,7 +2744,7 @@
]
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -2897,7 +2897,7 @@
"Prophecy\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -3015,7 +3015,7 @@
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
@ -3156,7 +3156,7 @@
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
@ -3237,7 +3237,7 @@
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
@ -3358,7 +3358,7 @@
"PragmaRX\\Version\\Tests\\": "tests/"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -3418,7 +3418,7 @@
"PragmaRX\\Yaml\\Tests\\": "tests/"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -3481,7 +3481,7 @@
"Prettus\\Repository\\": "src/Prettus/Repository/"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -3950,7 +3950,7 @@
"Laratrust\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -4153,7 +4153,7 @@
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
@ -4728,7 +4728,7 @@
"src/helpers.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -4911,7 +4911,7 @@
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -4960,7 +4960,7 @@
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5020,7 +5020,7 @@
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5076,7 +5076,7 @@
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5139,7 +5139,7 @@
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5188,7 +5188,7 @@
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5242,7 +5242,7 @@
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5330,7 +5330,7 @@
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5379,7 +5379,7 @@
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5531,7 +5531,7 @@
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5588,7 +5588,7 @@
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5647,7 +5647,7 @@
"Resources/stubs"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5699,7 +5699,7 @@
"Symfony\\Polyfill\\Util\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5754,7 +5754,7 @@
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5811,7 +5811,7 @@
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5894,7 +5894,7 @@
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5978,7 +5978,7 @@
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -6046,7 +6046,7 @@
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -6111,7 +6111,7 @@
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -6173,7 +6173,7 @@
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -6304,7 +6304,7 @@
"Tivie\\OS\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"APACHE 2.0"
],
@ -6525,7 +6525,7 @@
"Webpatser\\Uuid": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -6654,7 +6654,7 @@
"src/helper.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -6711,7 +6711,7 @@
"Zend\\Diactoros\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"BSD-2-Clause"
],
@ -6899,6 +6899,61 @@
],
"time": "2017-11-16T12:28:04+00:00"
},
{
"name": "facebook/webdriver",
"version": "1.5.0",
"source": {
"type": "git",
"url": "https://github.com/facebook/php-webdriver.git",
"reference": "86b5ca2f67173c9d34340845dd690149c886a605"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/facebook/php-webdriver/zipball/86b5ca2f67173c9d34340845dd690149c886a605",
"reference": "86b5ca2f67173c9d34340845dd690149c886a605",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-zip": "*",
"php": "^5.6 || ~7.0",
"symfony/process": "^2.8 || ^3.1 || ^4.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.0",
"guzzle/guzzle": "^3.4.1",
"php-coveralls/php-coveralls": "^1.0.2",
"php-mock/php-mock-phpunit": "^1.1",
"phpunit/phpunit": "^5.7",
"sebastian/environment": "^1.3.4 || ^2.0 || ^3.0",
"squizlabs/php_codesniffer": "^2.6",
"symfony/var-dumper": "^3.3 || ^4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-community": "1.5-dev"
}
},
"autoload": {
"psr-4": {
"Facebook\\WebDriver\\": "lib/"
}
},
"notification-url": "http://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"description": "A PHP client for Selenium WebDriver",
"homepage": "https://github.com/facebook/php-webdriver",
"keywords": [
"facebook",
"php",
"selenium",
"webdriver"
],
"time": "2017-11-15T11:08:09+00:00"
},
{
"name": "filp/whoops",
"version": "2.1.14",
@ -6937,7 +6992,7 @@
"Whoops\\": "src/Whoops/"
}
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@ -7055,6 +7110,67 @@
],
"time": "2015-05-11T14:41:42+00:00"
},
{
"name": "laravel/dusk",
"version": "v2.0.8",
"source": {
"type": "git",
"url": "https://github.com/laravel/dusk.git",
"reference": "a7529e19592879d3a6408728080ba657499890bc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/dusk/zipball/a7529e19592879d3a6408728080ba657499890bc",
"reference": "a7529e19592879d3a6408728080ba657499890bc",
"shasum": ""
},
"require": {
"facebook/webdriver": "~1.0",
"illuminate/console": "~5.5",
"illuminate/support": "~5.5",
"nesbot/carbon": "~1.20",
"php": ">=5.6.4",
"symfony/console": "~3.2",
"symfony/process": "~3.2"
},
"require-dev": {
"mockery/mockery": "~1.0",
"phpunit/phpunit": "~6.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
},
"laravel": {
"providers": [
"Laravel\\Dusk\\DuskServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Laravel\\Dusk\\": "src/"
}
},
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"description": "Laravel Dusk provides simple end-to-end testing and browser automation.",
"keywords": [
"laravel",
"testing",
"webdriver"
],
"time": "2017-12-08T14:18:11+00:00"
},
{
"name": "mockery/mockery",
"version": "0.9.9",
@ -7279,7 +7395,7 @@
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],

View File

@ -0,0 +1,41 @@
<?php
namespace Tests\Browser\Pages;
use Laravel\Dusk\Browser;
class HomePage extends Page
{
/**
* Get the URL for the page.
*
* @return string
*/
public function url()
{
return '/';
}
/**
* Assert that the browser is on the page.
*
* @param Browser $browser
* @return void
*/
public function assert(Browser $browser)
{
//
}
/**
* Get the element shortcuts for the page.
*
* @return array
*/
public function elements()
{
return [
'@element' => '#selector',
];
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Tests\Browser\Pages;
use Laravel\Dusk\Page as BasePage;
abstract class Page extends BasePage
{
/**
* Get the global element shortcuts for the site.
*
* @return array
*/
public static function siteElements()
{
return [
'@element' => '#selector',
];
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace Tests\Browser;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class RegistrationTest extends DuskTestCase
{
/**
* Test the registration
*/
public function testBasicExample()
{
/*$this->browse(function (Browser $browser) {
$browser->visit('/register')
->assertSee('Register');
});*/
}
}

2
tests/Browser/console/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

2
tests/Browser/screenshots/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -0,0 +1,22 @@
<?php
namespace Tests;
use Illuminate\Support\Facades\Hash;
use Illuminate\Contracts\Console\Kernel;
trait CreatesApplication
{
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__ . '/../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
//Hash::driver('bcrypt')->setRounds(4);
return $app;
}
}

43
tests/DuskTestCase.php Normal file
View File

@ -0,0 +1,43 @@
<?php
namespace Tests;
use Laravel\Dusk\TestCase as BaseTestCase;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
abstract class DuskTestCase extends BaseTestCase
{
use CreatesApplication;
/**
* Prepare for Dusk test execution.
*
* @beforeClass
* @return void
*/
public static function prepare()
{
static::startChromeDriver();
}
/**
* Create the RemoteWebDriver instance.
*
* @return \Facebook\WebDriver\Remote\RemoteWebDriver
*/
protected function driver()
{
$options = (new ChromeOptions)->addArguments([
'--disable-gpu',
'--headless'
]);
return RemoteWebDriver::create(
'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options
)
);
}
}