diff --git a/.gitignore b/.gitignore index 51be8740..31aa811b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ composer.lock Thumbs.db phpunit.xml /.idea +.phpunit.result.cache diff --git a/.travis.yml b/.travis.yml index 8ffaa93b..22abe59e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,15 +14,18 @@ env: matrix: - LARAVEL=5.7.* - LARAVEL=5.8.* - - LARAVEL=dev-master + - LARAVEL=^6.0 + - LARAVEL=^7.0 matrix: fast_finish: true exclude: - php: 7.1 - env: LARAVEL=dev-master + env: LARAVEL=^6.0 + - php: 7.1 + env: LARAVEL=^7.0 allow_failures: - - env: LARAVEL=dev-master + - env: LARAVEL=^7.0 before_install: - phpenv config-rm xdebug.ini || true diff --git a/composer.json b/composer.json index 02b0ec13..0e373fe0 100644 --- a/composer.json +++ b/composer.json @@ -15,9 +15,9 @@ "ext-pcntl": "*", "ext-posix": "*", "cakephp/chronos": "^1.0", - "illuminate/contracts": "~5.7.0|~5.8.0|^6.0", - "illuminate/queue": "~5.7.0|~5.8.0|^6.0", - "illuminate/support": "~5.7.0|~5.8.0|^6.0", + "illuminate/contracts": "~5.7.0|~5.8.0|^6.0|^7.0", + "illuminate/queue": "~5.7.0|~5.8.0|^6.0|^7.0", + "illuminate/support": "~5.7.0|~5.8.0|^6.0|^7.0", "predis/predis": "^1.1", "ramsey/uuid": "^3.5", "symfony/process": "^4.2", @@ -25,8 +25,8 @@ }, "require-dev": { "mockery/mockery": "^1.0", - "orchestra/testbench": "^3.7", - "phpunit/phpunit": "^7.0" + "orchestra/testbench": "^3.7|^4.0|^5.0", + "phpunit/phpunit": "^7.0|^8.0" }, "autoload": { "psr-4": { diff --git a/src/HorizonServiceProvider.php b/src/HorizonServiceProvider.php index 73b2fda1..e4380fc3 100644 --- a/src/HorizonServiceProvider.php +++ b/src/HorizonServiceProvider.php @@ -105,6 +105,10 @@ public function register() define('HORIZON_PATH', realpath(__DIR__.'/../')); } + $this->app->bind(Console\WorkCommand::class, function ($app) { + return new Console\WorkCommand($app['queue.worker'], $app['cache.store']); + }); + $this->configure(); $this->offerPublishing(); $this->registerServices(); diff --git a/tests/Feature/AuthTest.php b/tests/Feature/AuthTest.php index c42e883e..5a49aac7 100644 --- a/tests/Feature/AuthTest.php +++ b/tests/Feature/AuthTest.php @@ -5,6 +5,7 @@ use Laravel\Horizon\Horizon; use Laravel\Horizon\Tests\IntegrationTest; use Laravel\Horizon\Http\Middleware\Authenticate; +use Symfony\Component\HttpKernel\Exception\HttpException; class AuthTest extends IntegrationTest { @@ -40,11 +41,10 @@ function ($value) { $this->assertSame('response', $response); } - /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException - */ public function test_authentication_middleware_responds_with_403_on_failure() { + $this->expectException(HttpException::class); + Horizon::auth(function () { return false; }); diff --git a/tests/Feature/MasterSupervisorTest.php b/tests/Feature/MasterSupervisorTest.php index dfcefe24..f03362d9 100644 --- a/tests/Feature/MasterSupervisorTest.php +++ b/tests/Feature/MasterSupervisorTest.php @@ -3,6 +3,7 @@ namespace Laravel\Horizon\Tests\Feature; use Mockery; +use Exception; use Laravel\Horizon\PhpBinary; use Illuminate\Support\Facades\Redis; use Laravel\Horizon\MasterSupervisor; @@ -166,11 +167,10 @@ public function test_master_process_information_is_persisted() $this->assertSame('paused', $masterRecord->status); } - /** - * @expectedException \Exception - */ public function test_master_process_should_not_allow_duplicate_master_process_on_same_machine() { + $this->expectException(Exception::class); + $master = new MasterSupervisor; $master->working = true; $master2 = new MasterSupervisor; diff --git a/tests/Feature/RedisJobRepositoryTest.php b/tests/Feature/RedisJobRepositoryTest.php index c0479d16..a3bbe93b 100644 --- a/tests/Feature/RedisJobRepositoryTest.php +++ b/tests/Feature/RedisJobRepositoryTest.php @@ -41,6 +41,6 @@ public function test_it_saves_microseconds_as_a_float_and_disregards_the_locale( $result = $repository->getRecent()[0]; - $this->assertNotContains(',', $result->reserved_at); + $this->assertStringNotContainsString(',', $result->reserved_at); } } diff --git a/tests/Feature/SupervisorTest.php b/tests/Feature/SupervisorTest.php index 94f1c6ea..e96096e7 100644 --- a/tests/Feature/SupervisorTest.php +++ b/tests/Feature/SupervisorTest.php @@ -3,6 +3,7 @@ namespace Laravel\Horizon\Tests\Feature; use Mockery; +use Exception; use Cake\Chronos\Chronos; use Laravel\Horizon\PhpBinary; use Laravel\Horizon\AutoScaler; @@ -420,11 +421,10 @@ public function test_auto_scaler_is_called_on_loop_when_auto_scaling() $supervisor->loop(); } - /** - * @expectedException \Exception - */ public function test_supervisor_with_duplicate_name_cant_be_started() { + $this->expectException(Exception::class); + $options = $this->options(); $this->supervisor = $supervisor = new Supervisor($options); $supervisor->persist(); diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 0e59050a..0de6fafb 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -32,12 +32,12 @@ protected function setUp(): void */ protected function tearDown(): void { + parent::tearDown(); + Redis::flushall(); WorkerCommandString::reset(); SupervisorCommandString::reset(); Horizon::$authUsing = null; - - parent::tearDown(); } /** diff --git a/tests/UnitTest.php b/tests/UnitTest.php index ebd5c7d7..7585cdb1 100644 --- a/tests/UnitTest.php +++ b/tests/UnitTest.php @@ -7,7 +7,7 @@ abstract class UnitTest extends TestCase { - public function tearDown() + protected function tearDown(): void { Mockery::close(); } diff --git a/tests/worker.php b/tests/worker.php index a598dc0d..e62fe85e 100644 --- a/tests/worker.php +++ b/tests/worker.php @@ -3,8 +3,11 @@ require __DIR__.'/../vendor/autoload.php'; use Illuminate\Queue\Worker; +use Illuminate\Queue\QueueManager; use Illuminate\Queue\WorkerOptions; -use Orchestra\Testbench\Traits\CreatesApplication; +use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Contracts\Debug\ExceptionHandler; +use Orchestra\Testbench\Concerns\CreatesApplication; $appLoader = new class { use CreatesApplication; @@ -25,10 +28,16 @@ protected function getEnvironmentSetUp($app) // Configure the application... $app = $appLoader->createApplication(); $app->register(Laravel\Horizon\HorizonServiceProvider::class); -$app['config']->set('queue.default', 'redis'); - -// Create the worker... -$worker = app(Worker::class); +$app->make('config')->set('queue.default', 'redis'); + +$worker = new Worker( + $app->make(QueueManager::class), + $app->make(Dispatcher::class), + $app->make(ExceptionHandler::class), + function () use ($app) { + return $app->isDownForMaintenance(); + } +); // Pause the worker if needed... if (in_array('--paused', $_SERVER['argv'])) {