Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Commit

Permalink
Fixes for Laravel 8
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Jul 25, 2020
1 parent 24042bf commit 21d1623
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 56 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
"AltThree\\Bus\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"AltThree\\Tests\\Bus\\": "tests/"
}
},
"config": {
"preferred-install": "dist"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function hasCommandHandler($command)

$callback = $this->mapper;

if (!$callback || method_exists($command, 'handle')) {
if ($callback === null || method_exists($command, 'handle') || (method_exists($this, 'dispatchSync') && method_exists($command, '__invoke'))) {
return false;
}

Expand Down
70 changes: 15 additions & 55 deletions tests/BusDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
namespace AltThree\Tests\Bus;

use AltThree\Bus\Dispatcher;
use AltThree\Tests\Bus\Stubs\BusDispatcherBasicCommand;
use AltThree\Tests\Bus\Stubs\BusDispatcherTestBasicCommand;
use AltThree\Tests\Bus\Stubs\BusDispatcherTestCustomQueueCommand;
use AltThree\Tests\Bus\Stubs\BusInjectionStub;
use AltThree\Tests\Bus\Stubs\BusDispatcherTestSpecificQueueAndDelayCommand;
use AltThree\Tests\Bus\Stubs\Handlers\BusDispatcherTestBasicCommandHandler;
use AltThree\Tests\Bus\Stubs\StandAloneCommand;
use AltThree\Tests\Bus\Stubs\StandAloneHandler;
use GrahamCampbell\TestBenchCore\MockeryTrait;
use Illuminate\Container\Container;
use Illuminate\Contracts\Queue\Queue;
Expand All @@ -35,19 +43,20 @@ class BusDispatcherTest extends TestCase
public function testBasicDispatchingOfCommandsToHandlers()
{
$container = new Container();
$handler = Mockery::mock('StdClass');
$handler->shouldReceive('handle')->twice()->andReturn('foo');
$container->instance('AltThree\Foo\BusDispatcherTestBasicCommandHandler', $handler);
$handler = new BusDispatcherTestBasicCommandHandler();
$container->instance(BusDispatcherTestBasicCommandHandler::class, $handler);
$dispatcher = new Dispatcher($container);
$dispatcher->mapUsing(function ($command) {
return Dispatcher::simpleMapping($command, 'AltThree\Tests\Bus', 'AltThree\Foo');
return Dispatcher::simpleMapping($command, 'AltThree\Tests\Bus\Stubs', 'AltThree\Tests\Bus\Stubs\Handlers');
});

$result = $dispatcher->dispatch(new BusDispatcherTestBasicCommand());
$this->assertEquals('foo', $result);
$this->assertSame('foo', $result);

$result = $dispatcher->dispatch(new BusDispatcherTestBasicCommand());
$this->assertEquals('foo', $result);
$this->assertSame('foo', $result);

$this->assertSame(2, $handler->count);
}

public function testCommandsThatShouldQueueIsQueued()
Expand Down Expand Up @@ -120,52 +129,3 @@ public function testDispatcherCanDispatchStandAloneHandler()
$this->assertInstanceOf(StandAloneCommand::class, $response);
}
}

class BusInjectionStub
{
}

class BusDispatcherTestBasicCommand
{
}

class BusDispatcherBasicCommand
{
public $name;

public function __construct($name = null)
{
$this->name = $name;
}

public function handle(BusInjectionStub $stub)
{
//
}
}

class BusDispatcherTestCustomQueueCommand implements ShouldQueue
{
public function queue($queue, $command)
{
$queue->push($command);
}
}

class BusDispatcherTestSpecificQueueAndDelayCommand implements ShouldQueue
{
public $queue = 'foo';
public $delay = 10;
}

class StandAloneCommand
{
}

class StandAloneHandler
{
public function handle(StandAloneCommand $command)
{
return $command;
}
}
30 changes: 30 additions & 0 deletions tests/Stubs/BusDispatcherBasicCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

/*
* This file is part of Alt Three Bus.
*
* (c) Alt Three Services Limited
* (c) Taylor Otwell
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace AltThree\Tests\Bus\Stubs;

class BusDispatcherBasicCommand
{
public $name;

public function __construct($name = null)
{
$this->name = $name;
}

public function handle(BusInjectionStub $stub)
{
//
}
}
19 changes: 19 additions & 0 deletions tests/Stubs/BusDispatcherTestBasicCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

/*
* This file is part of Alt Three Bus.
*
* (c) Alt Three Services Limited
* (c) Taylor Otwell
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace AltThree\Tests\Bus\Stubs;

class BusDispatcherTestBasicCommand
{
}
25 changes: 25 additions & 0 deletions tests/Stubs/BusDispatcherTestCustomQueueCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

/*
* This file is part of Alt Three Bus.
*
* (c) Alt Three Services Limited
* (c) Taylor Otwell
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace AltThree\Tests\Bus\Stubs;

use Illuminate\Contracts\Queue\ShouldQueue;

class BusDispatcherTestCustomQueueCommand implements ShouldQueue
{
public function queue($queue, $command)
{
$queue->push($command);
}
}
23 changes: 23 additions & 0 deletions tests/Stubs/BusDispatcherTestSpecificQueueAndDelayCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

/*
* This file is part of Alt Three Bus.
*
* (c) Alt Three Services Limited
* (c) Taylor Otwell
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace AltThree\Tests\Bus\Stubs;

use Illuminate\Contracts\Queue\ShouldQueue;

class BusDispatcherTestSpecificQueueAndDelayCommand implements ShouldQueue
{
public $queue = 'foo';
public $delay = 10;
}
19 changes: 19 additions & 0 deletions tests/Stubs/BusInjectionStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

/*
* This file is part of Alt Three Bus.
*
* (c) Alt Three Services Limited
* (c) Taylor Otwell
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace AltThree\Tests\Bus\Stubs;

class BusInjectionStub
{
}
27 changes: 27 additions & 0 deletions tests/Stubs/Handlers/BusDispatcherTestBasicCommandHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

/*
* This file is part of Alt Three Bus.
*
* (c) Alt Three Services Limited
* (c) Taylor Otwell
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace AltThree\Tests\Bus\Stubs\Handlers;

class BusDispatcherTestBasicCommandHandler
{
public $count = 0;

public function handle()
{
$this->count++;

return 'foo';
}
}
19 changes: 19 additions & 0 deletions tests/Stubs/StandAloneCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

/*
* This file is part of Alt Three Bus.
*
* (c) Alt Three Services Limited
* (c) Taylor Otwell
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace AltThree\Tests\Bus\Stubs;

class StandAloneCommand
{
}
23 changes: 23 additions & 0 deletions tests/Stubs/StandAloneHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

/*
* This file is part of Alt Three Bus.
*
* (c) Alt Three Services Limited
* (c) Taylor Otwell
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace AltThree\Tests\Bus\Stubs;

class StandAloneHandler
{
public function handle(StandAloneCommand $command)
{
return $command;
}
}

0 comments on commit 21d1623

Please sign in to comment.