From f08e047357e6c4af6047a8a9d73b3506523fda8d Mon Sep 17 00:00:00 2001 From: Marc Morera Date: Mon, 16 Nov 2020 12:38:24 +0100 Subject: [PATCH] Deleted fulfilled/rejected classes usage - They went internal --- .circleci/config.yml | 10 ---------- Async/AsyncAdapter.php | 10 +++++----- Async/InMemoryAdapter.php | 12 ++++++------ Async/PostgreSQLAdapter.php | 2 +- Async/RedisAdapter.php | 8 ++++---- DependencyInjection/CompilerPass/BusCompilerPass.php | 2 +- Middleware/HandlerMiddleware.php | 8 ++++---- Middleware/Middleware.php | 4 ++-- Tests/Async/AsyncAdapterTest.php | 4 ++-- Tests/Async/AsyncTest.php | 2 +- Tests/Bus/CommandHandlerTest.php | 2 +- Tests/Bus/DiscriminableBusTest.php | 2 +- Tests/Bus/QueryHandlerNotExistsTest.php | 2 +- Tests/Bus/QueryHandlerTest.php | 2 +- Tests/Bus/QueryHandlerWithMiddlewareTest.php | 2 +- composer.json | 3 ++- 16 files changed, 33 insertions(+), 42 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a91a9fa..ee385a6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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: | @@ -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: | diff --git a/Async/AsyncAdapter.php b/Async/AsyncAdapter.php index 170d26e..32e016b 100644 --- a/Async/AsyncAdapter.php +++ b/Async/AsyncAdapter.php @@ -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. @@ -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(); }); @@ -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(); }) diff --git a/Async/InMemoryAdapter.php b/Async/InMemoryAdapter.php index 0183f77..9eca1a9 100644 --- a/Async/InMemoryAdapter.php +++ b/Async/InMemoryAdapter.php @@ -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. @@ -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(); } /** @@ -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(); } /** @@ -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(); } /** @@ -120,7 +120,7 @@ public function enqueue($command): PromiseInterface { $this->queue[] = $command; - return new FulfilledPromise(); + return resolve(); } /** diff --git a/Async/PostgreSQLAdapter.php b/Async/PostgreSQLAdapter.php index 2f725ff..b0f5d6f 100644 --- a/Async/PostgreSQLAdapter.php +++ b/Async/PostgreSQLAdapter.php @@ -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; diff --git a/Async/RedisAdapter.php b/Async/RedisAdapter.php index e672cec..d874f39 100644 --- a/Async/RedisAdapter.php +++ b/Async/RedisAdapter.php @@ -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. @@ -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(); } /** @@ -114,7 +114,7 @@ public function checkInfrastructure(OutputPrinter $outputPrinter): PromiseInterf $this->key )))->print($outputPrinter); - return new FulfilledPromise(); + return resolve(); } /** diff --git a/DependencyInjection/CompilerPass/BusCompilerPass.php b/DependencyInjection/CompilerPass/BusCompilerPass.php index bbbfa2c..279d130 100644 --- a/DependencyInjection/CompilerPass/BusCompilerPass.php +++ b/DependencyInjection/CompilerPass/BusCompilerPass.php @@ -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, diff --git a/Middleware/HandlerMiddleware.php b/Middleware/HandlerMiddleware.php index 98aa3ea..81ce1e8 100644 --- a/Middleware/HandlerMiddleware.php +++ b/Middleware/HandlerMiddleware.php @@ -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. @@ -60,7 +60,7 @@ 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]; @@ -68,7 +68,7 @@ public function execute($command, callable $next) return ($result instanceof PromiseInterface) ? $result - : new FulfilledPromise($result); + : resolve($result); } /** diff --git a/Middleware/Middleware.php b/Middleware/Middleware.php index 0f6a860..1004aaa 100644 --- a/Middleware/Middleware.php +++ b/Middleware/Middleware.php @@ -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. @@ -80,7 +80,7 @@ public function execute($command, callable $next): PromiseInterface return ($result instanceof PromiseInterface) ? $result - : new FulfilledPromise($result); + : resolve($result); } /** diff --git a/Tests/Async/AsyncAdapterTest.php b/Tests/Async/AsyncAdapterTest.php index 7c282c7..59ba803 100644 --- a/Tests/Async/AsyncAdapterTest.php +++ b/Tests/Async/AsyncAdapterTest.php @@ -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; @@ -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. diff --git a/Tests/Async/AsyncTest.php b/Tests/Async/AsyncTest.php index 235d080..2e21433 100644 --- a/Tests/Async/AsyncTest.php +++ b/Tests/Async/AsyncTest.php @@ -15,6 +15,7 @@ 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; @@ -22,7 +23,6 @@ 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. diff --git a/Tests/Bus/CommandHandlerTest.php b/Tests/Bus/CommandHandlerTest.php index 424ee7c..9652581 100644 --- a/Tests/Bus/CommandHandlerTest.php +++ b/Tests/Bus/CommandHandlerTest.php @@ -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. diff --git a/Tests/Bus/DiscriminableBusTest.php b/Tests/Bus/DiscriminableBusTest.php index 8bb6207..6069077 100644 --- a/Tests/Bus/DiscriminableBusTest.php +++ b/Tests/Bus/DiscriminableBusTest.php @@ -15,6 +15,7 @@ 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; @@ -22,7 +23,6 @@ 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. diff --git a/Tests/Bus/QueryHandlerNotExistsTest.php b/Tests/Bus/QueryHandlerNotExistsTest.php index be4469f..c3021d6 100644 --- a/Tests/Bus/QueryHandlerNotExistsTest.php +++ b/Tests/Bus/QueryHandlerNotExistsTest.php @@ -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. diff --git a/Tests/Bus/QueryHandlerTest.php b/Tests/Bus/QueryHandlerTest.php index d38de87..7e29a46 100644 --- a/Tests/Bus/QueryHandlerTest.php +++ b/Tests/Bus/QueryHandlerTest.php @@ -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. diff --git a/Tests/Bus/QueryHandlerWithMiddlewareTest.php b/Tests/Bus/QueryHandlerWithMiddlewareTest.php index 42a87aa..93907ed 100644 --- a/Tests/Bus/QueryHandlerWithMiddlewareTest.php +++ b/Tests/Bus/QueryHandlerWithMiddlewareTest.php @@ -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; @@ -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. diff --git a/composer.json b/composer.json index 2ff9adf..40ae6e2 100644 --- a/composer.json +++ b/composer.json @@ -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",