Skip to content

Commit

Permalink
Merge pull request #27 from driftphp/fix/fixed-fulfilled-rejected-pro…
Browse files Browse the repository at this point in the history
…mise

Deleted fulfilled/rejected classes usage
  • Loading branch information
mmoreram authored Nov 16, 2020
2 parents 5024918 + f08e047 commit 72ce30e
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 42 deletions.
10 changes: 0 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ jobs:
steps:
- checkout

- run:
name: Install PHPUnit
command: |
composer require phpunit/phpunit:7.5.17 --no-update
- run:
name: Run tests / Symfony 4^4
command: |
Expand Down Expand Up @@ -50,11 +45,6 @@ jobs:
steps:
- checkout

- run:
name: Install PHPUnit
command: |
composer require phpunit/phpunit:7.5.17 --no-update
- run:
name: Run tests / Symfony 5^0
command: |
Expand Down
10 changes: 5 additions & 5 deletions Async/AsyncAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
use Drift\CommandBus\Exception\MissingHandlerException;
use Drift\Console\OutputPrinter;
use Drift\Console\TimeFormatter;
use React\Promise\FulfilledPromise;
use React\Promise\PromiseInterface;
use function React\Promise\resolve;

/**
* Interface AsyncAdapter.
Expand Down Expand Up @@ -136,13 +136,13 @@ protected function executeCommand(
CommandConsumedLineMessage::CONSUMED
))->print($outputPrinter);

return (new FulfilledPromise())
return resolve()
->then(function () use ($ok) {
return $ok();
})
->then(function () use ($finish) {
if (!$this->canConsumeAnotherOne()) {
return (new FulfilledPromise())
return (resolve())
->then(function () use ($finish) {
return $finish();
});
Expand All @@ -164,11 +164,11 @@ protected function executeCommand(

return (
$ignorable
? (new FulfilledPromise())
? (resolve())
->then(function () use ($ok) {
return $ok();
})
: (new FulfilledPromise())
: (resolve())
->then(function () use ($ko) {
return $ko();
})
Expand Down
12 changes: 6 additions & 6 deletions Async/InMemoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

namespace Drift\CommandBus\Async;

use function Clue\React\Block\await;
use Drift\CommandBus\Bus\CommandBus;
use Drift\CommandBus\Console\CommandBusLineMessage;
use Drift\CommandBus\Exception\InvalidCommandException;
use Drift\Console\OutputPrinter;
use function Clue\React\Block\await;
use React\EventLoop\LoopInterface;
use React\Promise\FulfilledPromise;
use React\Promise\PromiseInterface;
use function React\Promise\resolve;

/**
* Class DummyAdapter.
Expand Down Expand Up @@ -61,7 +61,7 @@ public function createInfrastructure(OutputPrinter $outputPrinter): PromiseInter
$this->queue = [];
(new CommandBusLineMessage('Local queue created properly'))->print($outputPrinter);

return new FulfilledPromise();
return resolve();
}

/**
Expand All @@ -76,7 +76,7 @@ public function dropInfrastructure(OutputPrinter $outputPrinter): PromiseInterfa
$this->queue = null;
(new CommandBusLineMessage('Local queue dropped properly'))->print($outputPrinter);

return new FulfilledPromise();
return resolve();
}

/**
Expand All @@ -92,7 +92,7 @@ public function checkInfrastructure(OutputPrinter $outputPrinter): PromiseInterf
? (new CommandBusLineMessage('Local queue exists'))->print($outputPrinter)
: (new CommandBusLineMessage('Local queue does not exist'))->print($outputPrinter);

return new FulfilledPromise();
return resolve();
}

/**
Expand Down Expand Up @@ -120,7 +120,7 @@ public function enqueue($command): PromiseInterface
{
$this->queue[] = $command;

return new FulfilledPromise();
return resolve();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Async/PostgreSQLAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

namespace Drift\CommandBus\Async;

use function Clue\React\Block\await;
use Drift\CommandBus\Bus\CommandBus;
use Drift\CommandBus\Console\CommandBusHeaderMessage;
use Drift\CommandBus\Console\CommandBusLineMessage;
use Drift\CommandBus\Exception\InvalidCommandException;
use Drift\Console\OutputPrinter;
use Drift\EventLoop\EventLoopUtils;
use function Clue\React\Block\await;
use PgAsync\Client;
use PgAsync\Message\NotificationResponse;
use React\EventLoop\LoopInterface;
Expand Down
8 changes: 4 additions & 4 deletions Async/RedisAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

namespace Drift\CommandBus\Async;

use function Clue\React\Block\await;
use Clue\React\Redis\Client;
use Drift\CommandBus\Bus\CommandBus;
use Drift\CommandBus\Console\CommandBusLineMessage;
use Drift\CommandBus\Exception\InvalidCommandException;
use Drift\Console\OutputPrinter;
use function Clue\React\Block\await;
use React\EventLoop\LoopInterface;
use React\Promise\FulfilledPromise;
use React\Promise\PromiseInterface;
use function React\Promise\resolve;

/**
* Class RedisAdapter.
Expand Down Expand Up @@ -83,7 +83,7 @@ public function createInfrastructure(OutputPrinter $outputPrinter): PromiseInter
{
(new CommandBusLineMessage('List created properly. No need to be created previously'))->print($outputPrinter);

return new FulfilledPromise();
return resolve();
}

/**
Expand Down Expand Up @@ -114,7 +114,7 @@ public function checkInfrastructure(OutputPrinter $outputPrinter): PromiseInterf
$this->key
)))->print($outputPrinter);

return new FulfilledPromise();
return resolve();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/CompilerPass/BusCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function createAsyncMiddleware(ContainerBuilder $container): bool
$this->createPostgreSQLAsyncAdapter($container, $adapter);
break;
default:
throw new Exception('Wrong adapter');
throw new Exception('Wrong adapter. Please use one of this list: amqp, in_memory, redis, postgresql.');
}

$container->setDefinition(AsyncMiddleware::class,
Expand Down
8 changes: 4 additions & 4 deletions Middleware/HandlerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
namespace Drift\CommandBus\Middleware;

use Drift\CommandBus\Exception\MissingHandlerException;
use React\Promise\FulfilledPromise;
use React\Promise\PromiseInterface;
use React\Promise\RejectedPromise;
use function React\Promise\reject;
use function React\Promise\resolve;

/**
* Class HandlerMiddleware.
Expand Down Expand Up @@ -60,15 +60,15 @@ public function execute($command, callable $next)
$commandOrQueryNamespace = get_class($command);

if (!array_key_exists($commandOrQueryNamespace, $this->handlersMap)) {
return new RejectedPromise(new MissingHandlerException());
return reject(new MissingHandlerException());
}

list($handler, $method) = $this->handlersMap[$commandOrQueryNamespace];
$result = $handler->$method($command);

return ($result instanceof PromiseInterface)
? $result
: new FulfilledPromise($result);
: resolve($result);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Middleware/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
namespace Drift\CommandBus\Middleware;

use Drift\CommandBus\Exception\InvalidMiddlewareException;
use React\Promise\FulfilledPromise;
use React\Promise\PromiseInterface;
use function React\Promise\resolve;

/**
* Class Middleware.
Expand Down Expand Up @@ -80,7 +80,7 @@ public function execute($command, callable $next): PromiseInterface

return ($result instanceof PromiseInterface)
? $result
: new FulfilledPromise($result);
: resolve($result);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Tests/Async/AsyncAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

namespace Drift\CommandBus\Tests\Async;

use function Clue\React\Block\await;
use function Clue\React\Block\awaitAll;
use Drift\CommandBus\Tests\BusFunctionalTest;
use Drift\CommandBus\Tests\Command\ChangeAnotherThing;
use Drift\CommandBus\Tests\Command\ChangeAThing;
Expand All @@ -25,8 +27,6 @@
use Drift\CommandBus\Tests\CommandHandler\ChangeYetAnotherThingHandler;
use Drift\CommandBus\Tests\Context;
use Drift\CommandBus\Tests\Middleware\Middleware1;
use function Clue\React\Block\await;
use function Clue\React\Block\awaitAll;

/**
* Class AsyncAdapterTest.
Expand Down
2 changes: 1 addition & 1 deletion Tests/Async/AsyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

namespace Drift\CommandBus\Tests\Async;

use function Clue\React\Block\await;
use Drift\CommandBus\Middleware\AsyncMiddleware;
use Drift\CommandBus\Tests\BusFunctionalTest;
use Drift\CommandBus\Tests\Command\ChangeAThing;
use Drift\CommandBus\Tests\CommandHandler\ChangeAThingHandler;
use Drift\CommandBus\Tests\Context;
use Drift\CommandBus\Tests\Middleware\Middleware1;
use Drift\CommandBus\Tests\Middleware\Middleware3;
use function Clue\React\Block\await;

/**
* Class AsyncTest.
Expand Down
2 changes: 1 addition & 1 deletion Tests/Bus/CommandHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

namespace Drift\CommandBus\Tests\Bus;

use function Clue\React\Block\await;
use Drift\CommandBus\Bus\Bus;
use Drift\CommandBus\Middleware\HandlerMiddleware;
use Drift\CommandBus\Tests\BusFunctionalTest;
use Drift\CommandBus\Tests\Command\ChangeAThing;
use Drift\CommandBus\Tests\CommandHandler\ChangeAThingHandler;
use Drift\CommandBus\Tests\Context;
use function Clue\React\Block\await;

/**
* Class CommandHandlerTest.
Expand Down
2 changes: 1 addition & 1 deletion Tests/Bus/DiscriminableBusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

namespace Drift\CommandBus\Tests\Bus;

use function Clue\React\Block\awaitAll;
use Drift\CommandBus\Tests\BusFunctionalTest;
use Drift\CommandBus\Tests\Command\ChangeAnotherThing;
use Drift\CommandBus\Tests\Command\ChangeAThing;
use Drift\CommandBus\Tests\CommandHandler\ChangeAnotherThingHandler;
use Drift\CommandBus\Tests\CommandHandler\ChangeAThingHandler;
use Drift\CommandBus\Tests\Context;
use Drift\CommandBus\Tests\Middleware\DiscriminableMiddleware1;
use function Clue\React\Block\awaitAll;

/**
* Class DiscriminableBusTest.
Expand Down
2 changes: 1 addition & 1 deletion Tests/Bus/QueryHandlerNotExistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

namespace Drift\CommandBus\Tests\Bus;

use function Clue\React\Block\await;
use Drift\CommandBus\Exception\MissingHandlerException;
use Drift\CommandBus\Tests\BusFunctionalTest;
use Drift\CommandBus\Tests\Command\ChangeAThing;
use Drift\CommandBus\Tests\Context;
use Drift\CommandBus\Tests\QueryHandler\GetAThingHandler;
use function Clue\React\Block\await;

/**
* Class QueryHandlerNotExistsTest.
Expand Down
2 changes: 1 addition & 1 deletion Tests/Bus/QueryHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

namespace Drift\CommandBus\Tests\Bus;

use function Clue\React\Block\await;
use Drift\CommandBus\Bus\Bus;
use Drift\CommandBus\Exception\InvalidCommandException;
use Drift\CommandBus\Tests\BusFunctionalTest;
use Drift\CommandBus\Tests\Context;
use Drift\CommandBus\Tests\Query\GetAThing;
use Drift\CommandBus\Tests\QueryHandler\GetAThingHandler;
use function Clue\React\Block\await;

/**
* Class QueryHandlerTest.
Expand Down
2 changes: 1 addition & 1 deletion Tests/Bus/QueryHandlerWithMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Drift\CommandBus\Tests\Bus;

use function Clue\React\Block\await;
use Drift\CommandBus\Middleware\HandlerMiddleware;
use Drift\CommandBus\Tests\BusFunctionalTest;
use Drift\CommandBus\Tests\Command\ChangeAThing;
Expand All @@ -26,7 +27,6 @@
use Drift\CommandBus\Tests\Query\GetAThing;
use Drift\CommandBus\Tests\QueryHandler\GetAnotherThingHandler;
use Drift\CommandBus\Tests\QueryHandler\GetAThingHandler;
use function Clue\React\Block\await;

/**
* Class QueryHandlerWithMiddleware.
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"drift/redis-bundle": "0.1.*, >=0.1.4",
"drift/amqp-bundle": "0.1.*, >=0.1.2",
"drift/postgresql-bundle": "0.1.*, >=0.1.2",
"symfony/process": "^5.0.0"
"symfony/process": "^5.0.0",
"phpunit/phpunit": "7.5.17"
},
"suggest": {
"drift/redis-bundle": "Install this bundle to use Redis as a queue system",
Expand Down

0 comments on commit 72ce30e

Please sign in to comment.