From 83a07b225ee399c48b045719f697ea53b1bf6f6c Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Wed, 22 Nov 2017 11:57:25 +0200 Subject: [PATCH] Added new tests, updated composer.json and added auto-discovery --- composer.json | 5 ++ composer.lock | 174 +++++++++++++++++++++------------------- src/Commands/Reload.php | 67 +++++++++++----- tests/PackageTest.php | 24 ++++++ tests/ReloadTest.php | 71 ++++++++++++++-- 5 files changed, 232 insertions(+), 109 deletions(-) create mode 100644 tests/PackageTest.php diff --git a/composer.json b/composer.json index 24afb8c..c18f211 100644 --- a/composer.json +++ b/composer.json @@ -41,6 +41,11 @@ "extra": { "branch-alias": { "dev-master": "1.0-dev" + }, + "laravel": { + "providers": [ + "Superhelio\\Commands\\ServiceProvider" + ] } } } diff --git a/composer.lock b/composer.lock index 645c8ff..67ba82b 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": "3a4c5b69bb8e4ef40da3582cbb31bf0f", + "content-hash": "f9ec5a56eb04bb6d1b0ee5f698cf1138", "packages": [ { "name": "doctrine/annotations", @@ -478,21 +478,24 @@ }, { "name": "erusev/parsedown", - "version": "1.6.3", + "version": "1.6.4", "source": { "type": "git", "url": "https://github.com/erusev/parsedown.git", - "reference": "728952b90a333b5c6f77f06ea9422b94b585878d" + "reference": "fbe3fe878f4fe69048bb8a52783a09802004f548" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/erusev/parsedown/zipball/728952b90a333b5c6f77f06ea9422b94b585878d", - "reference": "728952b90a333b5c6f77f06ea9422b94b585878d", + "url": "https://api.github.com/repos/erusev/parsedown/zipball/fbe3fe878f4fe69048bb8a52783a09802004f548", + "reference": "fbe3fe878f4fe69048bb8a52783a09802004f548", "shasum": "" }, "require": { "php": ">=5.3.0" }, + "require-dev": { + "phpunit/phpunit": "^4.8.35" + }, "type": "library", "autoload": { "psr-0": { @@ -516,7 +519,7 @@ "markdown", "parser" ], - "time": "2017-05-14T14:47:48+00:00" + "time": "2017-11-14T20:44:03+00:00" }, { "name": "laravel/framework", @@ -810,7 +813,7 @@ }, { "name": "mtdowling/cron-expression", - "version": "v1.2.0", + "version": "v1.2.1", "source": { "type": "git", "url": "https://github.com/mtdowling/cron-expression.git", @@ -1138,16 +1141,16 @@ }, { "name": "symfony/console", - "version": "v3.3.10", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "116bc56e45a8e5572e51eb43ab58c769a352366c" + "reference": "63cd7960a0a522c3537f6326706d7f3b8de65805" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/116bc56e45a8e5572e51eb43ab58c769a352366c", - "reference": "116bc56e45a8e5572e51eb43ab58c769a352366c", + "url": "https://api.github.com/repos/symfony/console/zipball/63cd7960a0a522c3537f6326706d7f3b8de65805", + "reference": "63cd7960a0a522c3537f6326706d7f3b8de65805", "shasum": "" }, "require": { @@ -1202,20 +1205,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2017-10-02T06:42:24+00:00" + "time": "2017-11-16T15:24:32+00:00" }, { "name": "symfony/css-selector", - "version": "v3.3.10", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", - "reference": "07447650225ca9223bd5c97180fe7c8267f7d332" + "reference": "66e6e046032ebdf1f562c26928549f613d428bd1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/css-selector/zipball/07447650225ca9223bd5c97180fe7c8267f7d332", - "reference": "07447650225ca9223bd5c97180fe7c8267f7d332", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/66e6e046032ebdf1f562c26928549f613d428bd1", + "reference": "66e6e046032ebdf1f562c26928549f613d428bd1", "shasum": "" }, "require": { @@ -1255,20 +1258,20 @@ ], "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", - "time": "2017-10-02T06:42:24+00:00" + "time": "2017-11-05T15:47:03+00:00" }, { "name": "symfony/debug", - "version": "v3.3.10", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "eb95d9ce8f18dcc1b3dfff00cb624c402be78ffd" + "reference": "74557880e2846b5c84029faa96b834da37e29810" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/eb95d9ce8f18dcc1b3dfff00cb624c402be78ffd", - "reference": "eb95d9ce8f18dcc1b3dfff00cb624c402be78ffd", + "url": "https://api.github.com/repos/symfony/debug/zipball/74557880e2846b5c84029faa96b834da37e29810", + "reference": "74557880e2846b5c84029faa96b834da37e29810", "shasum": "" }, "require": { @@ -1311,20 +1314,20 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2017-10-02T06:42:24+00:00" + "time": "2017-11-10T16:38:39+00:00" }, { "name": "symfony/event-dispatcher", - "version": "v3.3.10", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "d7ba037e4b8221956ab1e221c73c9e27e05dd423" + "reference": "271d8c27c3ec5ecee6e2ac06016232e249d638d9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/d7ba037e4b8221956ab1e221c73c9e27e05dd423", - "reference": "d7ba037e4b8221956ab1e221c73c9e27e05dd423", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/271d8c27c3ec5ecee6e2ac06016232e249d638d9", + "reference": "271d8c27c3ec5ecee6e2ac06016232e249d638d9", "shasum": "" }, "require": { @@ -1374,20 +1377,20 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2017-10-02T06:42:24+00:00" + "time": "2017-11-05T15:47:03+00:00" }, { "name": "symfony/finder", - "version": "v3.3.10", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "773e19a491d97926f236942484cb541560ce862d" + "reference": "138af5ec075d4b1d1bd19de08c38a34bb2d7d880" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/773e19a491d97926f236942484cb541560ce862d", - "reference": "773e19a491d97926f236942484cb541560ce862d", + "url": "https://api.github.com/repos/symfony/finder/zipball/138af5ec075d4b1d1bd19de08c38a34bb2d7d880", + "reference": "138af5ec075d4b1d1bd19de08c38a34bb2d7d880", "shasum": "" }, "require": { @@ -1423,20 +1426,20 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2017-10-02T06:42:24+00:00" + "time": "2017-11-05T15:47:03+00:00" }, { "name": "symfony/http-foundation", - "version": "v3.3.10", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "22cf9c2b1d9f67cc8e75ae7f4eaa60e4c1eff1f8" + "reference": "5943f0f19817a7e05992d20a90729b0dc93faf36" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/22cf9c2b1d9f67cc8e75ae7f4eaa60e4c1eff1f8", - "reference": "22cf9c2b1d9f67cc8e75ae7f4eaa60e4c1eff1f8", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/5943f0f19817a7e05992d20a90729b0dc93faf36", + "reference": "5943f0f19817a7e05992d20a90729b0dc93faf36", "shasum": "" }, "require": { @@ -1476,20 +1479,20 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "https://symfony.com", - "time": "2017-10-05T23:10:23+00:00" + "time": "2017-11-13T18:13:16+00:00" }, { "name": "symfony/http-kernel", - "version": "v3.3.10", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "654f047a78756964bf91b619554f956517394018" + "reference": "a2a942172b742217ab2ccd9399494af2aa17c766" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/654f047a78756964bf91b619554f956517394018", - "reference": "654f047a78756964bf91b619554f956517394018", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/a2a942172b742217ab2ccd9399494af2aa17c766", + "reference": "a2a942172b742217ab2ccd9399494af2aa17c766", "shasum": "" }, "require": { @@ -1497,7 +1500,7 @@ "psr/log": "~1.0", "symfony/debug": "~2.8|~3.0", "symfony/event-dispatcher": "~2.8|~3.0", - "symfony/http-foundation": "~3.3" + "symfony/http-foundation": "^3.3.11" }, "conflict": { "symfony/config": "<2.8", @@ -1562,7 +1565,7 @@ ], "description": "Symfony HttpKernel Component", "homepage": "https://symfony.com", - "time": "2017-10-05T23:40:19+00:00" + "time": "2017-11-16T18:14:43+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -1625,16 +1628,16 @@ }, { "name": "symfony/process", - "version": "v3.3.10", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "fdf89e57a723a29baf536e288d6e232c059697b1" + "reference": "a56a3989fb762d7b19a0cf8e7693ee99a6ffb78d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/fdf89e57a723a29baf536e288d6e232c059697b1", - "reference": "fdf89e57a723a29baf536e288d6e232c059697b1", + "url": "https://api.github.com/repos/symfony/process/zipball/a56a3989fb762d7b19a0cf8e7693ee99a6ffb78d", + "reference": "a56a3989fb762d7b19a0cf8e7693ee99a6ffb78d", "shasum": "" }, "require": { @@ -1670,20 +1673,20 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2017-10-02T06:42:24+00:00" + "time": "2017-11-13T15:31:11+00:00" }, { "name": "symfony/routing", - "version": "v3.3.10", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/routing.git", - "reference": "2e26fa63da029dab49bf9377b3b4f60a8fecb009" + "reference": "cf7fa1dfcfee2c96969bfa1c0341e5627ecb1e95" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/routing/zipball/2e26fa63da029dab49bf9377b3b4f60a8fecb009", - "reference": "2e26fa63da029dab49bf9377b3b4f60a8fecb009", + "url": "https://api.github.com/repos/symfony/routing/zipball/cf7fa1dfcfee2c96969bfa1c0341e5627ecb1e95", + "reference": "cf7fa1dfcfee2c96969bfa1c0341e5627ecb1e95", "shasum": "" }, "require": { @@ -1748,20 +1751,20 @@ "uri", "url" ], - "time": "2017-10-02T07:25:00+00:00" + "time": "2017-11-07T14:16:22+00:00" }, { "name": "symfony/translation", - "version": "v3.3.10", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "409bf229cd552bf7e3faa8ab7e3980b07672073f" + "reference": "373e553477e55cd08f8b86b74db766c75b987fdb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/409bf229cd552bf7e3faa8ab7e3980b07672073f", - "reference": "409bf229cd552bf7e3faa8ab7e3980b07672073f", + "url": "https://api.github.com/repos/symfony/translation/zipball/373e553477e55cd08f8b86b74db766c75b987fdb", + "reference": "373e553477e55cd08f8b86b74db766c75b987fdb", "shasum": "" }, "require": { @@ -1813,20 +1816,20 @@ ], "description": "Symfony Translation Component", "homepage": "https://symfony.com", - "time": "2017-10-02T06:42:24+00:00" + "time": "2017-11-07T14:12:55+00:00" }, { "name": "symfony/var-dumper", - "version": "v3.3.10", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "03e3693a36701f1c581dd24a6d6eea2eba2113f6" + "reference": "805de6bd6869073e60610df1b14ab7d969c61b01" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/03e3693a36701f1c581dd24a6d6eea2eba2113f6", - "reference": "03e3693a36701f1c581dd24a6d6eea2eba2113f6", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/805de6bd6869073e60610df1b14ab7d969c61b01", + "reference": "805de6bd6869073e60610df1b14ab7d969c61b01", "shasum": "" }, "require": { @@ -1881,7 +1884,7 @@ "debug", "dump" ], - "time": "2017-10-02T06:42:24+00:00" + "time": "2017-11-07T14:16:22+00:00" }, { "name": "tijsverkoyen/css-to-inline-styles", @@ -2088,37 +2091,40 @@ }, { "name": "myclabs/deep-copy", - "version": "1.6.1", + "version": "1.7.0", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "8e6e04167378abf1ddb4d3522d8755c5fd90d102" + "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/8e6e04167378abf1ddb4d3522d8755c5fd90d102", - "reference": "8e6e04167378abf1ddb4d3522d8755c5fd90d102", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", + "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", "shasum": "" }, "require": { - "php": ">=5.4.0" + "php": "^5.6 || ^7.0" }, "require-dev": { - "doctrine/collections": "1.*", - "phpunit/phpunit": "~4.1" + "doctrine/collections": "^1.0", + "doctrine/common": "^2.6", + "phpunit/phpunit": "^4.1" }, "type": "library", "autoload": { "psr-4": { "DeepCopy\\": "src/DeepCopy/" - } + }, + "files": [ + "src/DeepCopy/deep_copy.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "description": "Create deep copies (clones) of your objects", - "homepage": "https://github.com/myclabs/DeepCopy", "keywords": [ "clone", "copy", @@ -2126,7 +2132,7 @@ "object", "object graph" ], - "time": "2017-04-12T18:52:22+00:00" + "time": "2017-10-19T19:58:43+00:00" }, { "name": "orchestra/testbench", @@ -2713,16 +2719,16 @@ }, { "name": "phpunit/phpunit", - "version": "5.7.23", + "version": "5.7.25", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "78532d5269d984660080d8e0f4c99c5c2ea65ffe" + "reference": "4b1c822a68ae6577df38a59eb49b046712ec0f6a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/78532d5269d984660080d8e0f4c99c5c2ea65ffe", - "reference": "78532d5269d984660080d8e0f4c99c5c2ea65ffe", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/4b1c822a68ae6577df38a59eb49b046712ec0f6a", + "reference": "4b1c822a68ae6577df38a59eb49b046712ec0f6a", "shasum": "" }, "require": { @@ -2747,7 +2753,7 @@ "sebastian/object-enumerator": "~2.0", "sebastian/resource-operations": "~1.0", "sebastian/version": "~1.0.3|~2.0", - "symfony/yaml": "~2.1|~3.0" + "symfony/yaml": "~2.1|~3.0|~4.0" }, "conflict": { "phpdocumentor/reflection-docblock": "3.0.2" @@ -2791,7 +2797,7 @@ "testing", "xunit" ], - "time": "2017-10-15T06:13:55+00:00" + "time": "2017-11-14T14:50:51+00:00" }, { "name": "phpunit/phpunit-mock-objects", @@ -3367,16 +3373,16 @@ }, { "name": "symfony/yaml", - "version": "v3.3.10", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "8c7bf1e7d5d6b05a690b715729cb4cd0c0a99c46" + "reference": "0938408c4faa518d95230deabb5f595bf0de31b9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/8c7bf1e7d5d6b05a690b715729cb4cd0c0a99c46", - "reference": "8c7bf1e7d5d6b05a690b715729cb4cd0c0a99c46", + "url": "https://api.github.com/repos/symfony/yaml/zipball/0938408c4faa518d95230deabb5f595bf0de31b9", + "reference": "0938408c4faa518d95230deabb5f595bf0de31b9", "shasum": "" }, "require": { @@ -3418,7 +3424,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2017-10-05T14:43:42+00:00" + "time": "2017-11-10T18:26:04+00:00" }, { "name": "webmozart/assert", diff --git a/src/Commands/Reload.php b/src/Commands/Reload.php index ec8c450..a26ae57 100644 --- a/src/Commands/Reload.php +++ b/src/Commands/Reload.php @@ -11,7 +11,9 @@ class Reload extends Command * * @var string */ - protected $signature = 'superhelio:reload'; + protected $signature = 'superhelio:reload + {--automate=false : Should run without questions?} + {--loud=true : Should output reset and migrate outputs?}'; /** * The console command description. @@ -27,26 +29,51 @@ class Reload extends Command */ public function handle() { - if ($this->confirm('Rollback all your database tables, recreate them and seed?')) { - $this->call( - 'migrate:reset', - [ - '--no-interaction' => true, - '--env' => 'development', - '--verbose' => 3 - ] - ); - $this->call( - 'migrate', - [ - '--seed' => true, - '--no-interaction' => true, - '--env' => 'development', - '--verbose' => 3 - ] - ); + $automated = $this->automate(); - return true; + if ($automated && $this->confirm('Rollback all your database tables, recreate them and seed?')) { + return $this->runReload(); + } + if (!$automated) { + return $this->runReload(); } } + + public function automate() + { + $automate = $this->option('automate'); + + return !($automate === '1' || $automate === 1 || $automate === 'yes' || $automate === 'true'); + } + + public function outputVerbosity() + { + $output = $this->option('loud'); + + return ($output === '1' || $output === 1 || $output == 'yes' || $output == 'true'); + } + + public function runReload() + { + $verbose = ($this->outputVerbosity() ? 3 : 0); + $this->call( + 'migrate:reset', + [ + '--no-interaction' => true, + '--env' => 'development', + '--verbose' => $verbose + ] + ); + $this->call( + 'migrate', + [ + '--seed' => true, + '--no-interaction' => true, + '--env' => 'development', + '--verbose' => $verbose + ] + ); + + return true; + } } diff --git a/tests/PackageTest.php b/tests/PackageTest.php new file mode 100644 index 0000000..864ed41 --- /dev/null +++ b/tests/PackageTest.php @@ -0,0 +1,24 @@ +assertTrue($facade->hasMethod('getFacadeAccessor')); + $this->assertTrue($facade->getMethod('getFacadeAccessor')->isProtected()); + $this->assertTrue($facade->getMethod('getFacadeAccessor')->isStatic()); + } + + public function test_service_provider() + { + $sp = new ReflectionClass(\Superhelio\Commands\ServiceProvider::class); + $this->assertTrue($sp->hasMethod('register')); + $this->assertTrue($sp->hasMethod('registerReloader')); + $this->assertTrue($sp->hasMethod('registerGozer')); + } +} diff --git a/tests/ReloadTest.php b/tests/ReloadTest.php index 23d97e0..a154260 100644 --- a/tests/ReloadTest.php +++ b/tests/ReloadTest.php @@ -1,14 +1,75 @@ assertTrue(true); + parent::setUp(); + $this->artisan('migrate', ['--database' => 'testbench']); + } + + /** + * Define environment setup. + * + * @param \Illuminate\Foundation\Application $app + * + * @return void + */ + protected function getEnvironmentSetUp($app) + { + // Setup default database to use sqlite :memory: + $app['config']->set('database.default', 'testbench'); + $app['config']->set('database.connections.testbench', [ + 'driver' => 'sqlite', + 'database' => ':memory:', + 'prefix' => 'reloadTest__', + ]); + } + + /** + * Get package providers. + * At a minimum this is the package being tested, but also + * would include packages upon which our package depends. + * In a normal app environment these would be added to + * the 'providers' array in the config/app.php file. + * + * @param \Illuminate\Foundation\Application $app + * + * @return array + */ + protected function getPackageProviders($app) + { + return [ + '\Superhelio\Commands\Tests\Stubs\ServiceProvider', + '\Superhelio\Commands\ServiceProvider' + ]; + } + + public function test_reload_exists() + { + $this->assertTrue(class_exists(Reload::class)); + $reload = new Reload(); + + $this->assertInstanceOf(Reload::class, $reload); + } + + public function test_reload_has_required_methods_and_properties() + { + $reload = new Reload(); + $this->assertTrue(method_exists($reload, 'handle'), 'handle'); + $this->assertTrue(method_exists($reload, 'runReload'), 'runReload'); + $this->assertTrue(method_exists($reload, 'automate'), 'automate'); + + $reload = new ReflectionClass(Reload::class); + $this->assertTrue($reload->hasProperty('signature'), 'signature'); + $this->assertTrue($reload->hasProperty('description'), 'description'); } }