Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prolic committed Feb 16, 2020
1 parent 93aa3cc commit 9c9004e
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/ClientOperations/AbstractSubscriptionOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ private function executeActions(): Promise
return call(function (): Generator {
while (! $this->actionQueue->isEmpty()) {
$action = $this->actionQueue->dequeue();
\assert(\is_callable($action));
\assert($action instanceof Closure);

try {
yield $action();
Expand Down
5 changes: 3 additions & 2 deletions src/Internal/EventStoreConnectionLogicHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Amp\Deferred;
use Amp\Loop;
use Amp\Promise;
use Closure;
use Exception;
use Generator;
Expand Down Expand Up @@ -654,9 +655,9 @@ private function startSubscription(StartSubscriptionMessage $message): void
$message->streamId(),
$message->resolveTo(),
$message->userCredentials(),
fn (EventStoreSubscription $subscription, ResolvedEvent $resolvedEvent): Promise => $message->eventAppeared($subscription, $resolvedEvent),
fn (EventStoreSubscription $subscription, ResolvedEvent $resolvedEvent): Promise => ($message->eventAppeared())($subscription, $resolvedEvent),
function (EventStoreSubscription $subscription, SubscriptionDropReason $reason, ?Throwable $exception = null) use ($message): void {
$message->subscriptionDropped($subscription, $reason, $exception);
($message->subscriptionDropped())($subscription, $reason, $exception);
},
$this->settings->verboseLogging(),
fn (): ?TcpPackageConnection => $this->connection
Expand Down
2 changes: 1 addition & 1 deletion tests/CountdownEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function wait(int $timeout): Promise
$deferred = new Deferred();
$newPromise = $deferred->promise();

$promise->onResolve(function (?\Throwable $exception = null, $result) use ($deferred) {
$promise->onResolve(function (?\Throwable $exception = null, $result) use ($deferred): void {
if ($exception) {
$deferred->resolve(false);
} else {
Expand Down
3 changes: 2 additions & 1 deletion tests/Helper/EventsStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use function Amp\call;
use Amp\Promise;
use Amp\Success;
use Generator;
use Prooph\EventStore\Async\EventStoreConnection;
use Prooph\EventStore\StreamEventsSlice;

Expand All @@ -27,7 +28,7 @@ class EventsStream
/** @return Promise<int> */
public static function count(EventStoreConnection $connection, string $stream): Promise
{
return call(function () use ($connection, $stream) {
return call(function () use ($connection, $stream): Generator {
$result = 0;

while (true) {
Expand Down
3 changes: 2 additions & 1 deletion tests/Helper/StreamWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use function Amp\call;
use Amp\Promise;
use Amp\Success;
use Generator;
use Prooph\EventStore\Async\EventStoreConnection;
use Prooph\EventStore\ExpectedVersion;
use Prooph\EventStore\WriteResult;
Expand All @@ -37,7 +38,7 @@ public function __construct(EventStoreConnection $connection, string $stream, in
/** @return Promise<TailWriter> */
public function append(array $events): Promise
{
return call(function () use ($events) {
return call(function () use ($events): Generator {
foreach ($events as $key => $event) {
$expVer = $this->version === ExpectedVersion::ANY ? ExpectedVersion::ANY : $this->version + $key;
$result = yield $this->connection->appendToStreamAsync($this->stream, $expVer, [$event]);
Expand Down
3 changes: 2 additions & 1 deletion tests/Helper/TailWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use function Amp\call;
use Amp\Promise;
use Amp\Success;
use Generator;
use Prooph\EventStore\Async\EventStoreConnection;
use Prooph\EventStore\EventData;

Expand All @@ -34,7 +35,7 @@ public function __construct(EventStoreConnection $connection, string $stream)
/** @return Promise<TailWriter> */
public function then(EventData $event, int $expectedVersion): Promise
{
return call(function () use ($event, $expectedVersion) {
return call(function () use ($event, $expectedVersion): Generator {
yield $this->connection->appendToStreamAsync($this->stream, $expectedVersion, [$event]);

return new Success($this);
Expand Down
2 changes: 1 addition & 1 deletion tests/ProjectionSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ abstract protected function when(): Generator;
/** @throws Throwable */
protected function execute(Closure $test): void
{
wait(call(function () use ($test) {
wait(call(function () use ($test): Generator {
$this->credentials = DefaultData::adminCredentials();
$this->connection = TestConnection::create();

Expand Down
6 changes: 3 additions & 3 deletions tests/Security/AuthenticationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ protected function createStreamWithMeta(StreamMetadata $metadata, ?string $strea
new UserCredentials('adm', 'admpa$$')
);

$promise->onResolve(function () use ($deferred, $stream) {
$promise->onResolve(function () use ($deferred, $stream): void {
$deferred->resolve($stream);
});

Expand Down Expand Up @@ -414,7 +414,7 @@ protected function expectExceptionFromCallback(string $expectedException, Closur
$deferred = new Deferred();

$promise = $callback();
$promise->onResolve(function ($e, $r) use ($deferred, $expectedException) {
$promise->onResolve(function ($e, $r) use ($deferred, $expectedException): void {
$this->assertThat(
$e,
new ExceptionConstraint(
Expand All @@ -433,7 +433,7 @@ protected function expectNoExceptionFromCallback(Closure $callback): Promise
$deferred = new Deferred();

$promise = $callback();
$promise->onResolve(function ($e, $r) use ($deferred) {
$promise->onResolve(function ($e, $r) use ($deferred): void {
$this->assertNull($e);
$deferred->resolve($r);
});
Expand Down
3 changes: 2 additions & 1 deletion tests/Security/authorized_default_credentials_security.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use function Amp\call;
use function Amp\Promise\wait;
use Generator;
use Prooph\EventStore\Async\EventStoreTransaction;
use Prooph\EventStore\Exception\AccessDenied;
use Prooph\EventStore\Exception\NotAuthenticated;
Expand Down Expand Up @@ -81,7 +82,7 @@ public function all_operations_are_not_authenticated_when_overriden_with_not_exi
$transId = $trans->transactionId();

$trans = $this->connection->continueTransaction($transId, new UserCredentials('badlogin', 'badpass'));
yield $this->expectExceptionFromCallback(NotAuthenticated::class, fn () => call(function () use ($trans) {
yield $this->expectExceptionFromCallback(NotAuthenticated::class, fn () => call(function () use ($trans): Generator {
yield $trans->writeAsync();
yield $trans->commitAsync();
}));
Expand Down
2 changes: 1 addition & 1 deletion tests/SpecificationWithConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function when(): Generator
/** @throws Throwable */
protected function execute(Closure $test): void
{
wait(call(function () use ($test) {
wait(call(function () use ($test): Generator {
$this->conn = TestConnection::create();

yield $this->conn->connectAsync();
Expand Down
4 changes: 2 additions & 2 deletions tests/connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function should_throw_exception_when_trying_to_reopen_closed_connection()
$settings
);

$connection->onClosed(function () use ($closed) {
$connection->onClosed(function () use ($closed): void {
$closed->resolve(true);
});

Expand Down Expand Up @@ -115,7 +115,7 @@ public function should_close_connection_after_configured_amount_of_failed_reconn
$settings
);

$connection->onClosed(function (ClientClosedEventArgs $args) use ($closed) {
$connection->onClosed(function (ClientClosedEventArgs $args) use ($closed): void {
$this->assertInstanceOf(EventStoreConnection::class, $args->connection());
$this->assertEquals('Reconnection limit reached', $args->reason());

Expand Down
2 changes: 1 addition & 1 deletion tests/not_connected_tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function should_timeout_connection_after_configured_amount_time_on_connec
\var_dump('error');
});

$connection->onClosed(function () use ($deferred) {
$connection->onClosed(function () use ($deferred): void {
$deferred->resolve();
});

Expand Down
2 changes: 1 addition & 1 deletion tests/soft_delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function tearDownTestCase(): void
/** @throws Throwable */
protected function execute(Closure $callback): void
{
wait(call(function () use ($callback) {
wait(call(function () use ($callback): Generator {
yield from $this->setUpTestCase();

yield from $callback();
Expand Down
3 changes: 2 additions & 1 deletion tests/subscribe_to_all_should.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Amp\Success;
use Amp\TimeoutException;
use Closure;
use Generator;
use PHPUnit\Framework\TestCase;
use Prooph\EventStore\Async\EventAppearedOnSubscription;
use Prooph\EventStore\Common\SystemRoles;
Expand All @@ -41,7 +42,7 @@ class subscribe_to_all_should extends TestCase
*/
private function execute(Closure $function): void
{
Promise\wait(call(function () use ($function) {
Promise\wait(call(function () use ($function): Generator {
$connection = TestConnection::create();

yield $connection->connectAsync();
Expand Down
3 changes: 2 additions & 1 deletion tests/transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Amp\Parallel\Worker\DefaultPool;
use Amp\Promise;
use Closure;
use Generator;
use PHPUnit\Framework\TestCase;
use Prooph\EventStore\Async\EventStoreConnection;
use Prooph\EventStore\Async\EventStoreTransaction;
Expand All @@ -40,7 +41,7 @@ class transaction extends TestCase
*/
private function execute(Closure $function): void
{
Promise\wait(call(function () use ($function) {
Promise\wait(call(function () use ($function): Generator {
$this->conn = TestConnection::create();

yield $this->conn->connectAsync();
Expand Down
2 changes: 1 addition & 1 deletion tests/when_creating_continuous_projection.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function should_create_projection(): string
*/
public function should_have_turn_on_emit_to_stream(string $projectionId): void
{
$this->execute(function () use ($projectionId) {
$this->execute(function () use ($projectionId): Generator {
$event = yield $this->connection->readEventAsync(
'$projections-' . $projectionId,
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function should_create_projection(): string
*/
public function should_enable_track_emitted_streams(string $projectionId): void
{
$this->execute(function () use ($projectionId) {
$this->execute(function () use ($projectionId): Generator {
$event = yield $this->connection->readEventAsync(
'$projections-' . $projectionId,
0,
Expand Down
2 changes: 1 addition & 1 deletion tests/when_having_max_count_set_for_stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class when_having_max_count_set_for_stream extends TestCase
/** @throws Throwable */
private function execute(Closure $function): void
{
Promise\wait(call(function () use ($function) {
Promise\wait(call(function () use ($function): Generator {
$this->conn = TestConnection::create();

yield $this->conn->connectAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use function Amp\call;
use function Amp\Promise\wait;
use Closure;
use Generator;
use PHPUnit\Framework\TestCase;
use Prooph\EventStore\Async\EventStoreConnection;
use Prooph\EventStore\Exception\RuntimeException;
Expand All @@ -36,7 +37,7 @@ class when_working_with_stream_metadata_as_structured_info extends TestCase
/** @throws Throwable */
private function execute(Closure $function): void
{
wait(call(function () use ($function) {
wait(call(function () use ($function): Generator {
$this->stream = self::class . '\\' . $this->getName();
$this->conn = TestConnection::create(DefaultData::adminCredentials());
yield $this->conn->connectAsync();
Expand Down

0 comments on commit 9c9004e

Please sign in to comment.