Skip to content

Commit 72ce30e

Browse files
authored
Merge pull request #27 from driftphp/fix/fixed-fulfilled-rejected-promise
Deleted fulfilled/rejected classes usage
2 parents 5024918 + f08e047 commit 72ce30e

16 files changed

+33
-42
lines changed

.circleci/config.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ jobs:
1515
steps:
1616
- checkout
1717

18-
- run:
19-
name: Install PHPUnit
20-
command: |
21-
composer require phpunit/phpunit:7.5.17 --no-update
22-
2318
- run:
2419
name: Run tests / Symfony 4^4
2520
command: |
@@ -50,11 +45,6 @@ jobs:
5045
steps:
5146
- checkout
5247

53-
- run:
54-
name: Install PHPUnit
55-
command: |
56-
composer require phpunit/phpunit:7.5.17 --no-update
57-
5848
- run:
5949
name: Run tests / Symfony 5^0
6050
command: |

Async/AsyncAdapter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
use Drift\CommandBus\Exception\MissingHandlerException;
2222
use Drift\Console\OutputPrinter;
2323
use Drift\Console\TimeFormatter;
24-
use React\Promise\FulfilledPromise;
2524
use React\Promise\PromiseInterface;
25+
use function React\Promise\resolve;
2626

2727
/**
2828
* Interface AsyncAdapter.
@@ -136,13 +136,13 @@ protected function executeCommand(
136136
CommandConsumedLineMessage::CONSUMED
137137
))->print($outputPrinter);
138138

139-
return (new FulfilledPromise())
139+
return resolve()
140140
->then(function () use ($ok) {
141141
return $ok();
142142
})
143143
->then(function () use ($finish) {
144144
if (!$this->canConsumeAnotherOne()) {
145-
return (new FulfilledPromise())
145+
return (resolve())
146146
->then(function () use ($finish) {
147147
return $finish();
148148
});
@@ -164,11 +164,11 @@ protected function executeCommand(
164164

165165
return (
166166
$ignorable
167-
? (new FulfilledPromise())
167+
? (resolve())
168168
->then(function () use ($ok) {
169169
return $ok();
170170
})
171-
: (new FulfilledPromise())
171+
: (resolve())
172172
->then(function () use ($ko) {
173173
return $ko();
174174
})

Async/InMemoryAdapter.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515

1616
namespace Drift\CommandBus\Async;
1717

18+
use function Clue\React\Block\await;
1819
use Drift\CommandBus\Bus\CommandBus;
1920
use Drift\CommandBus\Console\CommandBusLineMessage;
2021
use Drift\CommandBus\Exception\InvalidCommandException;
2122
use Drift\Console\OutputPrinter;
22-
use function Clue\React\Block\await;
2323
use React\EventLoop\LoopInterface;
24-
use React\Promise\FulfilledPromise;
2524
use React\Promise\PromiseInterface;
25+
use function React\Promise\resolve;
2626

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

64-
return new FulfilledPromise();
64+
return resolve();
6565
}
6666

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

79-
return new FulfilledPromise();
79+
return resolve();
8080
}
8181

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

95-
return new FulfilledPromise();
95+
return resolve();
9696
}
9797

9898
/**
@@ -120,7 +120,7 @@ public function enqueue($command): PromiseInterface
120120
{
121121
$this->queue[] = $command;
122122

123-
return new FulfilledPromise();
123+
return resolve();
124124
}
125125

126126
/**

Async/PostgreSQLAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515

1616
namespace Drift\CommandBus\Async;
1717

18+
use function Clue\React\Block\await;
1819
use Drift\CommandBus\Bus\CommandBus;
1920
use Drift\CommandBus\Console\CommandBusHeaderMessage;
2021
use Drift\CommandBus\Console\CommandBusLineMessage;
2122
use Drift\CommandBus\Exception\InvalidCommandException;
2223
use Drift\Console\OutputPrinter;
2324
use Drift\EventLoop\EventLoopUtils;
24-
use function Clue\React\Block\await;
2525
use PgAsync\Client;
2626
use PgAsync\Message\NotificationResponse;
2727
use React\EventLoop\LoopInterface;

Async/RedisAdapter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616
namespace Drift\CommandBus\Async;
1717

18+
use function Clue\React\Block\await;
1819
use Clue\React\Redis\Client;
1920
use Drift\CommandBus\Bus\CommandBus;
2021
use Drift\CommandBus\Console\CommandBusLineMessage;
2122
use Drift\CommandBus\Exception\InvalidCommandException;
2223
use Drift\Console\OutputPrinter;
23-
use function Clue\React\Block\await;
2424
use React\EventLoop\LoopInterface;
25-
use React\Promise\FulfilledPromise;
2625
use React\Promise\PromiseInterface;
26+
use function React\Promise\resolve;
2727

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

86-
return new FulfilledPromise();
86+
return resolve();
8787
}
8888

8989
/**
@@ -114,7 +114,7 @@ public function checkInfrastructure(OutputPrinter $outputPrinter): PromiseInterf
114114
$this->key
115115
)))->print($outputPrinter);
116116

117-
return new FulfilledPromise();
117+
return resolve();
118118
}
119119

120120
/**

DependencyInjection/CompilerPass/BusCompilerPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function createAsyncMiddleware(ContainerBuilder $container): bool
110110
$this->createPostgreSQLAsyncAdapter($container, $adapter);
111111
break;
112112
default:
113-
throw new Exception('Wrong adapter');
113+
throw new Exception('Wrong adapter. Please use one of this list: amqp, in_memory, redis, postgresql.');
114114
}
115115

116116
$container->setDefinition(AsyncMiddleware::class,

Middleware/HandlerMiddleware.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
namespace Drift\CommandBus\Middleware;
1717

1818
use Drift\CommandBus\Exception\MissingHandlerException;
19-
use React\Promise\FulfilledPromise;
2019
use React\Promise\PromiseInterface;
21-
use React\Promise\RejectedPromise;
20+
use function React\Promise\reject;
21+
use function React\Promise\resolve;
2222

2323
/**
2424
* Class HandlerMiddleware.
@@ -60,15 +60,15 @@ public function execute($command, callable $next)
6060
$commandOrQueryNamespace = get_class($command);
6161

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

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

6969
return ($result instanceof PromiseInterface)
7070
? $result
71-
: new FulfilledPromise($result);
71+
: resolve($result);
7272
}
7373

7474
/**

Middleware/Middleware.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
namespace Drift\CommandBus\Middleware;
1717

1818
use Drift\CommandBus\Exception\InvalidMiddlewareException;
19-
use React\Promise\FulfilledPromise;
2019
use React\Promise\PromiseInterface;
20+
use function React\Promise\resolve;
2121

2222
/**
2323
* Class Middleware.
@@ -80,7 +80,7 @@ public function execute($command, callable $next): PromiseInterface
8080

8181
return ($result instanceof PromiseInterface)
8282
? $result
83-
: new FulfilledPromise($result);
83+
: resolve($result);
8484
}
8585

8686
/**

Tests/Async/AsyncAdapterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
namespace Drift\CommandBus\Tests\Async;
1717

18+
use function Clue\React\Block\await;
19+
use function Clue\React\Block\awaitAll;
1820
use Drift\CommandBus\Tests\BusFunctionalTest;
1921
use Drift\CommandBus\Tests\Command\ChangeAnotherThing;
2022
use Drift\CommandBus\Tests\Command\ChangeAThing;
@@ -25,8 +27,6 @@
2527
use Drift\CommandBus\Tests\CommandHandler\ChangeYetAnotherThingHandler;
2628
use Drift\CommandBus\Tests\Context;
2729
use Drift\CommandBus\Tests\Middleware\Middleware1;
28-
use function Clue\React\Block\await;
29-
use function Clue\React\Block\awaitAll;
3030

3131
/**
3232
* Class AsyncAdapterTest.

Tests/Async/AsyncTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515

1616
namespace Drift\CommandBus\Tests\Async;
1717

18+
use function Clue\React\Block\await;
1819
use Drift\CommandBus\Middleware\AsyncMiddleware;
1920
use Drift\CommandBus\Tests\BusFunctionalTest;
2021
use Drift\CommandBus\Tests\Command\ChangeAThing;
2122
use Drift\CommandBus\Tests\CommandHandler\ChangeAThingHandler;
2223
use Drift\CommandBus\Tests\Context;
2324
use Drift\CommandBus\Tests\Middleware\Middleware1;
2425
use Drift\CommandBus\Tests\Middleware\Middleware3;
25-
use function Clue\React\Block\await;
2626

2727
/**
2828
* Class AsyncTest.

0 commit comments

Comments
 (0)