From 74316218bc1ab124e1f7a68cf0b953e2409fff99 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Fri, 22 Dec 2017 12:00:57 -0600 Subject: [PATCH] Add some event listeners and experiment with browser testing --- app/Listeners/EmailEventListener.php | 34 ++++ app/Providers/EventServiceProvider.php | 8 +- app/Services/UserService.php | 1 - composer.json | 6 +- composer.lock | 234 ++++++++++++++++++------- tests/Browser/Pages/HomePage.php | 41 +++++ tests/Browser/Pages/Page.php | 20 +++ tests/Browser/RegistrationTest.php | 21 +++ tests/Browser/console/.gitignore | 2 + tests/Browser/screenshots/.gitignore | 2 + tests/CreatesApplication.php | 22 +++ tests/DuskTestCase.php | 43 +++++ 12 files changed, 369 insertions(+), 65 deletions(-) create mode 100644 app/Listeners/EmailEventListener.php create mode 100644 tests/Browser/Pages/HomePage.php create mode 100644 tests/Browser/Pages/Page.php create mode 100644 tests/Browser/RegistrationTest.php create mode 100644 tests/Browser/console/.gitignore create mode 100644 tests/Browser/screenshots/.gitignore create mode 100644 tests/CreatesApplication.php create mode 100644 tests/DuskTestCase.php diff --git a/app/Listeners/EmailEventListener.php b/app/Listeners/EmailEventListener.php new file mode 100644 index 00000000..47116a46 --- /dev/null +++ b/app/Listeners/EmailEventListener.php @@ -0,0 +1,34 @@ +listen( + UserRegistered::class, + 'App\Listeners\EmailEventListener@onUserRegister' + ); + } + + public function onUserRegister(UserRegistered $event) + { + Log::info($event->user->toArray()); + } + +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 87517454..d37720b3 100755 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -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(); - - // } } diff --git a/app/Services/UserService.php b/app/Services/UserService.php index 4361cb5d..36a165d9 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -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; diff --git a/composer.json b/composer.json index 16ba8b4a..9970cf9d 100755 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/composer.lock b/composer.lock index 17fb4923..78e65862 100644 --- a/composer.lock +++ b/composer.lock @@ -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" ], diff --git a/tests/Browser/Pages/HomePage.php b/tests/Browser/Pages/HomePage.php new file mode 100644 index 00000000..4f5a87f4 --- /dev/null +++ b/tests/Browser/Pages/HomePage.php @@ -0,0 +1,41 @@ + '#selector', + ]; + } +} diff --git a/tests/Browser/Pages/Page.php b/tests/Browser/Pages/Page.php new file mode 100644 index 00000000..f8d76222 --- /dev/null +++ b/tests/Browser/Pages/Page.php @@ -0,0 +1,20 @@ + '#selector', + ]; + } +} diff --git a/tests/Browser/RegistrationTest.php b/tests/Browser/RegistrationTest.php new file mode 100644 index 00000000..c586bc52 --- /dev/null +++ b/tests/Browser/RegistrationTest.php @@ -0,0 +1,21 @@ +browse(function (Browser $browser) { + $browser->visit('/register') + ->assertSee('Register'); + });*/ + } +} diff --git a/tests/Browser/console/.gitignore b/tests/Browser/console/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/tests/Browser/console/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tests/Browser/screenshots/.gitignore b/tests/Browser/screenshots/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/tests/Browser/screenshots/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php new file mode 100644 index 00000000..689c09ab --- /dev/null +++ b/tests/CreatesApplication.php @@ -0,0 +1,22 @@ +make(Kernel::class)->bootstrap(); + //Hash::driver('bcrypt')->setRounds(4); + return $app; + } +} diff --git a/tests/DuskTestCase.php b/tests/DuskTestCase.php new file mode 100644 index 00000000..1261c7a6 --- /dev/null +++ b/tests/DuskTestCase.php @@ -0,0 +1,43 @@ +addArguments([ + '--disable-gpu', + '--headless' + ]); + + return RemoteWebDriver::create( + 'http://localhost:9515', DesiredCapabilities::chrome()->setCapability( + ChromeOptions::CAPABILITY, $options + ) + ); + } +}