diff --git a/examples/demo-subscription5.php b/examples/demo-subscription5.php index 458e13e3..8c33ba0d 100644 --- a/examples/demo-subscription5.php +++ b/examples/demo-subscription5.php @@ -17,7 +17,6 @@ use Amp\Success; use Prooph\EventStoreClient\Exception\InvalidOperationException; use Prooph\EventStoreClient\Internal\AbstractEventStorePersistentSubscription; -use Prooph\EventStoreClient\Internal\EventStorePersistentSubscription; use Prooph\EventStoreClient\Internal\ResolvedEvent; use Prooph\EventStoreClient\Messages\ClientMessages\CreatePersistentSubscription; use Throwable; @@ -60,7 +59,7 @@ \var_dump($result); - $subscription = $connection->connectToPersistentSubscription( + $connection->connectToPersistentSubscriptionAsync( 'foo-bar', 'test-persistent-subscription', new class() implements EventAppearedOnPersistentSubscription { @@ -92,7 +91,4 @@ public function __invoke( true, new UserCredentials('admin', 'changeit') ); - - /** @var EventStorePersistentSubscription $subscription */ - $subscription = yield $subscription->start(); }); diff --git a/examples/demo-subscription6.php b/examples/demo-subscription6.php deleted file mode 100644 index 8c33ba0d..00000000 --- a/examples/demo-subscription6.php +++ /dev/null @@ -1,94 +0,0 @@ - - * (c) 2018-2018 Sascha-Oliver Prolic - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Prooph\EventStoreClient; - -use Amp\Loop; -use Amp\Promise; -use Amp\Success; -use Prooph\EventStoreClient\Exception\InvalidOperationException; -use Prooph\EventStoreClient\Internal\AbstractEventStorePersistentSubscription; -use Prooph\EventStoreClient\Internal\ResolvedEvent; -use Prooph\EventStoreClient\Messages\ClientMessages\CreatePersistentSubscription; -use Throwable; - -require __DIR__ . '/../vendor/autoload.php'; - -Loop::run(function () { - $connection = EventStoreAsyncConnectionBuilder::createFromSettingsWithIpEndPoint( - new EndPoint('eventstore', 1113) - ); - - $connection->onConnected(function (): void { - echo 'connected' . PHP_EOL; - }); - - $connection->onClosed(function (): void { - echo 'connection closed' . PHP_EOL; - }); - - yield $connection->connectAsync(); - - try { - $result = yield $connection->deletePersistentSubscriptionAsync( - 'foo-bar', - 'test-persistent-subscription', - new UserCredentials('admin', 'changeit') - ); - \var_dump($result); - } catch (InvalidOperationException $exception) { - echo 'no such subscription exists (yet)' . PHP_EOL; - } - - /** @var CreatePersistentSubscription $result */ - $result = yield $connection->createPersistentSubscriptionAsync( - 'foo-bar', - 'test-persistent-subscription', - PersistentSubscriptionSettings::default(), - new UserCredentials('admin', 'changeit') - ); - - \var_dump($result); - - $connection->connectToPersistentSubscriptionAsync( - 'foo-bar', - 'test-persistent-subscription', - new class() implements EventAppearedOnPersistentSubscription { - public function __invoke( - AbstractEventStorePersistentSubscription $subscription, - ResolvedEvent $resolvedEvent, - ?int $retryCount = null - ): Promise { - echo 'incoming event: ' . $resolvedEvent->originalEventNumber() . '@' . $resolvedEvent->originalStreamName() . PHP_EOL; - echo 'data: ' . $resolvedEvent->originalEvent()->data() . PHP_EOL; - - return new Success(); - } - }, - new class() implements PersistentSubscriptionDropped { - public function __invoke( - AbstractEventStorePersistentSubscription $subscription, - SubscriptionDropReason $reason, - ?Throwable $exception = null - ): void { - echo 'dropped with reason: ' . $reason->name() . PHP_EOL; - - if ($exception) { - echo 'ex: ' . $exception->getMessage() . PHP_EOL; - } - } - }, - 10, - true, - new UserCredentials('admin', 'changeit') - ); -}); diff --git a/src/ClientOperations/AbstractSubscriptionOperation.php b/src/ClientOperations/AbstractSubscriptionOperation.php index 08919cbc..db73f756 100644 --- a/src/ClientOperations/AbstractSubscriptionOperation.php +++ b/src/ClientOperations/AbstractSubscriptionOperation.php @@ -13,6 +13,7 @@ namespace Prooph\EventStoreClient\ClientOperations; use Amp\Deferred; +use Amp\Loop; use Amp\Promise; use Amp\Success; use Generator; @@ -371,7 +372,9 @@ private function executeActionAsync(callable $action): void $this->dropSubscription(SubscriptionDropReason::userInitiated(), new \Exception('client buffer too big')); } - Promise\rethrow($this->executeActions()); + Loop::defer(function (): Generator { + yield $this->executeActions(); + }); } /** @return Promise */ diff --git a/src/EventStoreAsyncConnection.php b/src/EventStoreAsyncConnection.php index 345dc192..a9b993d9 100644 --- a/src/EventStoreAsyncConnection.php +++ b/src/EventStoreAsyncConnection.php @@ -14,7 +14,6 @@ use Amp\Promise; use Prooph\EventStoreClient\Internal\EventStoreAllCatchUpSubscription; -use Prooph\EventStoreClient\Internal\EventStorePersistentSubscription; use Prooph\EventStoreClient\Internal\EventStoreStreamCatchUpSubscription; use Prooph\EventStoreClient\Internal\ListenerHandler; @@ -197,16 +196,6 @@ public function subscribeToAllFrom( ?UserCredentials $userCredentials = null ): EventStoreAllCatchUpSubscription; - public function connectToPersistentSubscription( - string $stream, - string $groupName, - EventAppearedOnPersistentSubscription $eventAppeared, - ?PersistentSubscriptionDropped $subscriptionDropped = null, - int $bufferSize = 10, - bool $autoAck = true, - ?UserCredentials $userCredentials = null - ): EventStorePersistentSubscription; - /** * @return Promise */ diff --git a/src/Internal/AbstractEventStorePersistentSubscription.php b/src/Internal/AbstractEventStorePersistentSubscription.php index e5c561e2..a06c2e89 100644 --- a/src/Internal/AbstractEventStorePersistentSubscription.php +++ b/src/Internal/AbstractEventStorePersistentSubscription.php @@ -349,11 +349,7 @@ private function enqueue(PersistentSubscriptionResolvedEvent $resolvedEvent): vo $this->isProcessing = true; Loop::defer(function (): Generator { - $promise = $this->processQueue(); - - Promise\rethrow($promise); - - yield $promise; + yield $this->processQueue(); }); } } diff --git a/src/Internal/EventStoreAsyncNodeConnection.php b/src/Internal/EventStoreAsyncNodeConnection.php index 77dfb694..6fa76ecf 100644 --- a/src/Internal/EventStoreAsyncNodeConnection.php +++ b/src/Internal/EventStoreAsyncNodeConnection.php @@ -616,7 +616,7 @@ public function subscribeToStreamFrom( $settings ); - Promise\rethrow($catchUpSubscription->startAsync()); + $catchUpSubscription->startAsync(); return $catchUpSubscription; } @@ -671,47 +671,11 @@ public function subscribeToAllFrom( $settings ); - Promise\rethrow($catchUpSubscription->startAsync()); + $catchUpSubscription->startAsync(); return $catchUpSubscription; } - public function connectToPersistentSubscription( - string $stream, - string $groupName, - EventAppearedOnPersistentSubscription $eventAppeared, - ?PersistentSubscriptionDropped $subscriptionDropped = null, - int $bufferSize = 10, - bool $autoAck = true, - ?UserCredentials $userCredentials = null - ): EventStorePersistentSubscription { - if (empty($stream)) { - throw new InvalidArgumentException('Stream cannot be empty'); - } - - if (empty($groupName)) { - throw new InvalidArgumentException('Group cannot be empty'); - } - - $subscription = new EventStorePersistentSubscription( - $groupName, - $stream, - $eventAppeared, - $subscriptionDropped, - $userCredentials, - $this->settings->log(), - $this->settings->verboseLogging(), - $this->settings, - $this->handler, - $bufferSize, - $autoAck - ); - - Promise\rethrow($subscription->start()); - - return $subscription; - } - /** {@inheritdoc} */ public function connectToPersistentSubscriptionAsync( string $stream, diff --git a/src/Internal/EventStoreCatchUpSubscription.php b/src/Internal/EventStoreCatchUpSubscription.php index 16d1ebf3..e8e983ad 100644 --- a/src/Internal/EventStoreCatchUpSubscription.php +++ b/src/Internal/EventStoreCatchUpSubscription.php @@ -221,10 +221,7 @@ private function onReconnect(ClientConnectionEventArgs $clientConnectionEventArg $this->connection->detach($this->connectListener); Loop::defer(function (): Generator { - $promise = $this->runSubscriptionAsync(); - Promise\rethrow($promise); - - yield $promise; + yield $this->runSubscriptionAsync(); }); } @@ -462,10 +459,7 @@ private function ensureProcessingPushQueue(): void $this->isProcessing = true; Loop::defer(function (): Generator { - $promise = $this->processLiveQueueAsync(); - Promise\rethrow($promise); - - yield $promise; + yield $this->processLiveQueueAsync(); }); } } diff --git a/src/Internal/EventStoreConnectionLogicHandler.php b/src/Internal/EventStoreConnectionLogicHandler.php index ae167ef8..c40f07f5 100644 --- a/src/Internal/EventStoreConnectionLogicHandler.php +++ b/src/Internal/EventStoreConnectionLogicHandler.php @@ -48,7 +48,6 @@ use Prooph\EventStoreClient\SystemData\TcpPackage; use Prooph\EventStoreClient\Transport\Tcp\TcpPackageConnection; use Throwable; -use function Amp\Promise\rethrow; /** @internal */ class EventStoreConnectionLogicHandler @@ -250,8 +249,6 @@ private function discoverEndPoint(?Deferred $deferred): void $deferred->resolve(null); } }); - - rethrow($promise); } /** @throws \Exception */ @@ -334,10 +331,7 @@ function (TcpPackageConnection $connection, Throwable $exception): void { ); Loop::defer(function (): Generator { - $promise = $this->connection->connectAsync(); - rethrow($promise); - - yield $promise; + yield $this->connection->connectAsync(); if (! $this->connection->isClosed()) { $this->connection->startReceiving(); diff --git a/src/Internal/EventStoreSyncNodeConnection.php b/src/Internal/EventStoreSyncNodeConnection.php index 62619605..8fdd51b9 100644 --- a/src/Internal/EventStoreSyncNodeConnection.php +++ b/src/Internal/EventStoreSyncNodeConnection.php @@ -20,7 +20,6 @@ use Prooph\EventStoreClient\ClusterSettings; use Prooph\EventStoreClient\ConditionalWriteResult; use Prooph\EventStoreClient\ConnectionSettings; -use Prooph\EventStoreClient\EventAppearedOnSubscription; use Prooph\EventStoreClient\EventReadResult; use Prooph\EventStoreClient\EventStoreAsyncConnection; use Prooph\EventStoreClient\EventStoreSyncConnection; @@ -31,7 +30,6 @@ use Prooph\EventStoreClient\StreamEventsSlice; use Prooph\EventStoreClient\StreamMetadata; use Prooph\EventStoreClient\StreamMetadataResult; -use Prooph\EventStoreClient\SubscriptionDropped; use Prooph\EventStoreClient\SystemSettings; use Prooph\EventStoreClient\UserCredentials; use Prooph\EventStoreClient\WriteResult; @@ -273,27 +271,6 @@ public function deletePersistentSubscription( return Promise\wait($this->asyncConnection->deletePersistentSubscriptionAsync($stream, $groupName, $userCredentials)); } - /** @throws Throwable */ - public function connectToPersistentSubscription( - string $stream, - string $groupName, - EventAppearedOnSubscription $eventAppeared, - ?SubscriptionDropped $subscriptionDropped = null, - int $bufferSize = 10, - bool $autoAck = true, - ?UserCredentials $userCredentials = null - ): EventStorePersistentSubscription { - return $this->asyncConnection->connectToPersistentSubscription( - $stream, - $groupName, - $eventAppeared, - $subscriptionDropped, - $bufferSize, - $autoAck, - $userCredentials - ); - } - public function startTransaction( string $stream, int $expectedVersion, diff --git a/tests/SpecificationWithConnection.php b/tests/SpecificationWithConnection.php index efb0bc7f..d2cafef4 100644 --- a/tests/SpecificationWithConnection.php +++ b/tests/SpecificationWithConnection.php @@ -33,7 +33,7 @@ protected function given(): Generator abstract protected function when(); /** @throws Throwable */ - protected function executeCallback(callable $test): void + protected function execute(callable $test): void { wait(call(function () use ($test) { $this->conn = TestConnection::createAsync(); @@ -52,8 +52,7 @@ protected function executeCallback(callable $test): void protected function end(): Generator { - // @todo is this a bug? - //$this->conn->close(); + $this->conn->close(); yield new Success(); } diff --git a/tests/a_nak_in_subscription_handler_in_autoack_mode_drops_the_subscription.php b/tests/a_nak_in_subscription_handler_in_autoack_mode_drops_the_subscription.php index 209d140d..82fc4689 100644 --- a/tests/a_nak_in_subscription_handler_in_autoack_mode_drops_the_subscription.php +++ b/tests/a_nak_in_subscription_handler_in_autoack_mode_drops_the_subscription.php @@ -77,7 +77,7 @@ protected function given(): Generator $this->resetEvent->resolve(true); }; - $this->conn->connectToPersistentSubscription( + yield $this->conn->connectToPersistentSubscriptionAsync( $this->stream, $this->group, new class() implements EventAppearedOnPersistentSubscription { @@ -129,7 +129,7 @@ protected function when(): Generator */ public function the_subscription_gets_dropped(): void { - $this->executeCallback(function (): Generator { + $this->execute(function (): Generator { try { $result = yield Promise\timeout($this->resetEvent->promise(), 5000); } catch (TimeoutException $e) { diff --git a/tests/can_create_duplicate_persistent_subscription_group_name_on_different_streams.php b/tests/can_create_duplicate_persistent_subscription_group_name_on_different_streams.php index 0c0021e6..33f740fd 100644 --- a/tests/can_create_duplicate_persistent_subscription_group_name_on_different_streams.php +++ b/tests/can_create_duplicate_persistent_subscription_group_name_on_different_streams.php @@ -53,7 +53,7 @@ protected function when(): Generator */ public function the_completion_succeeds(): void { - $this->executeCallback(function () { + $this->execute(function () { yield $this->conn->createPersistentSubscriptionAsync( 'someother' . $this->stream, 'group3211', diff --git a/tests/connect_to_existing_persistent_subscription_with_max_one_client.php b/tests/connect_to_existing_persistent_subscription_with_max_one_client.php index 82c465c0..24e6b01b 100644 --- a/tests/connect_to_existing_persistent_subscription_with_max_one_client.php +++ b/tests/connect_to_existing_persistent_subscription_with_max_one_client.php @@ -12,15 +12,14 @@ namespace ProophTest\EventStoreClient; -use Amp\Delayed; use Amp\Promise; use Amp\Success; -use Error; use Generator; use PHPUnit\Framework\TestCase; use Prooph\EventStoreClient\EventAppearedOnPersistentSubscription; use Prooph\EventStoreClient\Exception\MaximumSubscribersReachedException; use Prooph\EventStoreClient\Internal\AbstractEventStorePersistentSubscription; +use Prooph\EventStoreClient\Internal\EventStorePersistentSubscription; use Prooph\EventStoreClient\Internal\ResolvedEvent; use Prooph\EventStoreClient\Internal\UuidGenerator; use Prooph\EventStoreClient\PersistentSubscriptionSettings; @@ -34,8 +33,12 @@ class connect_to_existing_persistent_subscription_with_max_one_client extends Te private $stream; /** @var PersistentSubscriptionSettings */ private $settings; + /** @var Throwable */ + private $exception; /** @var string */ private $group = 'startinbeginning1'; + /** @var EventStorePersistentSubscription|null */ + private $firstSubscription; protected function setUp(): void { @@ -56,7 +59,7 @@ protected function given(): Generator DefaultData::adminCredentials() ); - $this->conn->connectToPersistentSubscription( + $this->firstSubscription = yield $this->conn->connectToPersistentSubscriptionAsync( $this->stream, $this->group, new class() implements EventAppearedOnPersistentSubscription { @@ -79,43 +82,53 @@ public function __invoke( protected function when(): Generator { - $this->conn->connectToPersistentSubscription( - $this->stream, - $this->group, - new class() implements EventAppearedOnPersistentSubscription { - public function __invoke( - AbstractEventStorePersistentSubscription $subscription, - ResolvedEvent $resolvedEvent, - ?int $retryCount = null - ): Promise { - $subscription->acknowledge($resolvedEvent); - - return new Success(); - } - }, - null, - 10, - false, - DefaultData::adminCredentials() - ); + try { + yield $this->conn->connectToPersistentSubscriptionAsync( + $this->stream, + $this->group, + new class() implements EventAppearedOnPersistentSubscription { + public function __invoke( + AbstractEventStorePersistentSubscription $subscription, + ResolvedEvent $resolvedEvent, + ?int $retryCount = null + ): Promise { + $subscription->acknowledge($resolvedEvent); - yield new Delayed(50); // wait for it + return new Success(); + } + }, + null, + 10, + false, + DefaultData::adminCredentials() + ); + } catch (Throwable $e) { + $this->exception = $e; + } } /** * @test * @throws Throwable */ - public function the_second_subscription_fails_to_connect(): void + public function the_first_subscription_connects_successfully(): void { - try { - $this->executeCallback(function (): Generator { - yield new Success(); - }); + $this->execute(function (): Generator { + $this->assertNotNull($this->firstSubscription); - $this->fail('Should have thrown'); - } catch (Error $exception) { - $this->assertInstanceOf(MaximumSubscribersReachedException::class, $exception->getPrevious()); - } + yield new Success(); + }); + } + + /** + * @test + * @throws Throwable + */ + public function the_second_subscription_throws_maximum_subscribers_reached_exception(): void + { + $this->execute(function (): Generator { + $this->assertInstanceOf(MaximumSubscribersReachedException::class, $this->exception); + yield new Success(); + }); } } diff --git a/tests/connect_to_existing_persistent_subscription_with_max_one_client_async.php b/tests/connect_to_existing_persistent_subscription_with_max_one_client_async.php deleted file mode 100644 index 7edbbc59..00000000 --- a/tests/connect_to_existing_persistent_subscription_with_max_one_client_async.php +++ /dev/null @@ -1,134 +0,0 @@ - - * (c) 2018-2018 Sascha-Oliver Prolic - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace ProophTest\EventStoreClient; - -use Amp\Promise; -use Amp\Success; -use Generator; -use PHPUnit\Framework\TestCase; -use Prooph\EventStoreClient\EventAppearedOnPersistentSubscription; -use Prooph\EventStoreClient\Exception\MaximumSubscribersReachedException; -use Prooph\EventStoreClient\Internal\AbstractEventStorePersistentSubscription; -use Prooph\EventStoreClient\Internal\EventStorePersistentSubscription; -use Prooph\EventStoreClient\Internal\ResolvedEvent; -use Prooph\EventStoreClient\Internal\UuidGenerator; -use Prooph\EventStoreClient\PersistentSubscriptionSettings; -use Throwable; - -class connect_to_existing_persistent_subscription_with_max_one_client_async extends TestCase -{ - use SpecificationWithConnection; - - /** @var string */ - private $stream; - /** @var PersistentSubscriptionSettings */ - private $settings; - /** @var Throwable */ - private $exception; - /** @var string */ - private $group = 'startinbeginning1'; - /** @var EventStorePersistentSubscription|null */ - private $firstSubscription; - - protected function setUp(): void - { - $this->stream = '$' . UuidGenerator::generate(); - $this->settings = PersistentSubscriptionSettings::create() - ->doNotResolveLinkTos() - ->startFromCurrent() - ->withMaxSubscriberCountOf(1) - ->build(); - } - - protected function given(): Generator - { - yield $this->conn->createPersistentSubscriptionAsync( - $this->stream, - $this->group, - $this->settings, - DefaultData::adminCredentials() - ); - - $this->firstSubscription = yield $this->conn->connectToPersistentSubscriptionAsync( - $this->stream, - $this->group, - new class() implements EventAppearedOnPersistentSubscription { - public function __invoke( - AbstractEventStorePersistentSubscription $subscription, - ResolvedEvent $resolvedEvent, - ?int $retryCount = null - ): Promise { - $subscription->acknowledge($resolvedEvent); - - return new Success(); - } - }, - null, - 10, - false, - DefaultData::adminCredentials() - ); - } - - protected function when(): Generator - { - try { - yield $this->conn->connectToPersistentSubscriptionAsync( - $this->stream, - $this->group, - new class() implements EventAppearedOnPersistentSubscription { - public function __invoke( - AbstractEventStorePersistentSubscription $subscription, - ResolvedEvent $resolvedEvent, - ?int $retryCount = null - ): Promise { - $subscription->acknowledge($resolvedEvent); - - return new Success(); - } - }, - null, - 10, - false, - DefaultData::adminCredentials() - ); - } catch (Throwable $e) { - $this->exception = $e; - } - } - - /** - * @test - * @throws Throwable - */ - public function the_first_subscription_connects_successfully(): void - { - $this->executeCallback(function (): Generator { - $this->assertNotNull($this->firstSubscription); - - yield new Success(); - }); - } - - /** - * @test - * @throws Throwable - */ - public function the_second_subscription_throws_maximum_subscribers_reached_exception(): void - { - $this->executeCallback(function (): Generator { - $this->assertInstanceOf(MaximumSubscribersReachedException::class, $this->exception); - yield new Success(); - }); - } -} diff --git a/tests/connect_to_existing_persistent_subscription_with_permissions.php b/tests/connect_to_existing_persistent_subscription_with_permissions.php index af94c1a7..4be59ce3 100644 --- a/tests/connect_to_existing_persistent_subscription_with_permissions.php +++ b/tests/connect_to_existing_persistent_subscription_with_permissions.php @@ -52,7 +52,7 @@ protected function when(): Generator DefaultData::adminCredentials() ); - $this->sub = $this->conn->connectToPersistentSubscription( + $this->sub = $this->conn->connectToPersistentSubscriptionAsync( $this->stream, 'agroupname17', new class() implements EventAppearedOnPersistentSubscription { @@ -73,10 +73,8 @@ public function __invoke( */ public function the_subscription_suceeds(): void { - $this->executeCallback(function () { - $this->assertNotNull($this->sub); - - yield new Success(); + $this->execute(function () { + $this->assertNotNull(yield $this->sub); }); } } diff --git a/tests/connect_to_existing_persistent_subscription_with_permissions_async.php b/tests/connect_to_existing_persistent_subscription_with_permissions_async.php deleted file mode 100644 index 724dc25f..00000000 --- a/tests/connect_to_existing_persistent_subscription_with_permissions_async.php +++ /dev/null @@ -1,80 +0,0 @@ - - * (c) 2018-2018 Sascha-Oliver Prolic - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace ProophTest\EventStoreClient; - -use Amp\Promise; -use Amp\Success; -use Generator; -use PHPUnit\Framework\TestCase; -use Prooph\EventStoreClient\EventAppearedOnPersistentSubscription; -use Prooph\EventStoreClient\Internal\AbstractEventStorePersistentSubscription; -use Prooph\EventStoreClient\Internal\ResolvedEvent; -use Prooph\EventStoreClient\Internal\UuidGenerator; -use Prooph\EventStoreClient\PersistentSubscriptionSettings; -use Throwable; - -class connect_to_existing_persistent_subscription_with_permissions_async extends TestCase -{ - use SpecificationWithConnection; - - /** @var AbstractEventStorePersistentSubscription */ - private $sub; - /** @var string */ - private $stream; - /** @var PersistentSubscriptionSettings */ - private $settings; - - protected function setUp(): void - { - $this->stream = UuidGenerator::generate(); - $this->settings = PersistentSubscriptionSettings::create() - ->doNotResolveLinkTos() - ->startFromCurrent() - ->build(); - } - - protected function when(): Generator - { - yield $this->conn->createPersistentSubscriptionAsync( - $this->stream, - 'agroupname17', - $this->settings, - DefaultData::adminCredentials() - ); - - $this->sub = $this->conn->connectToPersistentSubscriptionAsync( - $this->stream, - 'agroupname17', - new class() implements EventAppearedOnPersistentSubscription { - public function __invoke( - AbstractEventStorePersistentSubscription $subscription, - ResolvedEvent $resolvedEvent, - ?int $retryCount = null - ): Promise { - return new Success(); - } - } - ); - } - - /** - * @test - * @throws Throwable - */ - public function the_subscription_suceeds(): void - { - $this->executeCallback(function () { - $this->assertNotNull(yield $this->sub); - }); - } -} diff --git a/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_and_events_in_it.php b/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_and_events_in_it.php index 370abe76..059b41b6 100644 --- a/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_and_events_in_it.php +++ b/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_and_events_in_it.php @@ -87,7 +87,7 @@ private function writeEvents(): Promise protected function when(): Generator { - $this->conn->connectToPersistentSubscription( + yield $this->conn->connectToPersistentSubscriptionAsync( $this->stream, $this->group, new class($this->set, $this->resetEvent, $this->firstEvent) implements EventAppearedOnPersistentSubscription { @@ -121,8 +121,6 @@ public function __invoke( true, DefaultData::adminCredentials() ); - - yield new Success(); } /** @@ -131,7 +129,7 @@ public function __invoke( */ public function the_subscription_gets_event_zero_as_its_first_event(): void { - $this->executeCallback(function (): Generator { + $this->execute(function (): Generator { $value = yield Promise\timeout($this->resetEvent->promise(), 10000); $this->assertTrue($value); $this->assertSame(0, $this->firstEvent->originalEventNumber()); diff --git a/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_and_events_in_it_async.php b/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_and_events_in_it_async.php deleted file mode 100644 index 86b1ac50..00000000 --- a/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_and_events_in_it_async.php +++ /dev/null @@ -1,141 +0,0 @@ - - * (c) 2018-2018 Sascha-Oliver Prolic - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace ProophTest\EventStoreClient; - -use Amp\Deferred; -use Amp\Promise; -use Amp\Success; -use Generator; -use PHPUnit\Framework\TestCase; -use Prooph\EventStoreClient\EventAppearedOnPersistentSubscription; -use Prooph\EventStoreClient\EventData; -use Prooph\EventStoreClient\EventId; -use Prooph\EventStoreClient\ExpectedVersion; -use Prooph\EventStoreClient\Internal\AbstractEventStorePersistentSubscription; -use Prooph\EventStoreClient\Internal\ResolvedEvent; -use Prooph\EventStoreClient\Internal\UuidGenerator; -use Prooph\EventStoreClient\PersistentSubscriptionSettings; -use Throwable; -use function Amp\call; - -class connect_to_existing_persistent_subscription_with_start_from_beginning_and_events_in_it_async extends TestCase -{ - use SpecificationWithConnection; - - /** @var string */ - private $stream; - /** @var PersistentSubscriptionSettings */ - private $settings; - /** @var string */ - private $group = 'startinbeginning1'; - /** @var ResolvedEvent */ - private $firstEvent; - /** @var Deferred */ - private $resetEvent; - /** @var array */ - private $ids = []; - /** @var bool */ - private $set = false; - - protected function setUp(): void - { - $this->stream = '$' . UuidGenerator::generate(); - $this->settings = PersistentSubscriptionSettings::create() - ->doNotResolveLinkTos() - ->startFromBeginning() - ->build(); - $this->resetEvent = new Deferred(); - } - - protected function given(): Generator - { - yield $this->writeEvents(); - - yield $this->conn->createPersistentSubscriptionAsync( - $this->stream, - $this->group, - $this->settings, - DefaultData::adminCredentials() - ); - } - - private function writeEvents(): Promise - { - return call(function (): Generator { - for ($i = 0; $i < 10; $i++) { - $this->ids[$i] = EventId::generate(); - - yield $this->conn->appendToStreamAsync( - $this->stream, - ExpectedVersion::ANY, - [new EventData($this->ids[$i], 'test', true, '{"foo":"bar"}')], - DefaultData::adminCredentials() - ); - } - }); - } - - protected function when(): Generator - { - yield $this->conn->connectToPersistentSubscriptionAsync( - $this->stream, - $this->group, - new class($this->set, $this->resetEvent, $this->firstEvent) implements EventAppearedOnPersistentSubscription { - private $set; - private $deferred; - private $firstEvent; - - public function __construct(&$set, &$deferred, &$firstEvent) - { - $this->set = &$set; - $this->deferred = $deferred; - $this->firstEvent = &$firstEvent; - } - - public function __invoke( - AbstractEventStorePersistentSubscription $subscription, - ResolvedEvent $resolvedEvent, - ?int $retryCount = null - ): Promise { - if (! $this->set) { - $this->set = true; - $this->firstEvent = $resolvedEvent; - $this->deferred->resolve(true); - } - - return new Success(); - } - }, - null, - 10, - true, - DefaultData::adminCredentials() - ); - } - - /** - * @test - * @throws Throwable - */ - public function the_subscription_gets_event_zero_as_its_first_event(): void - { - $this->executeCallback(function (): Generator { - $value = yield Promise\timeout($this->resetEvent->promise(), 10000); - $this->assertTrue($value); - $this->assertSame(0, $this->firstEvent->originalEventNumber()); - $this->assertTrue($this->firstEvent->originalEvent()->eventId()->equals($this->ids[0])); - - yield new Success(); - }); - } -} diff --git a/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_and_no_stream.php b/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_and_no_stream.php index b6ff619b..96b2fc3d 100644 --- a/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_and_no_stream.php +++ b/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_and_no_stream.php @@ -66,7 +66,7 @@ protected function given(): Generator DefaultData::adminCredentials() ); - $this->conn->connectToPersistentSubscription( + yield $this->conn->connectToPersistentSubscriptionAsync( $this->stream, $this->group, new class($this->set, $this->resetEvent, $this->firstEvent) implements EventAppearedOnPersistentSubscription { @@ -129,7 +129,7 @@ protected function when(): Generator */ public function the_subscription_gets_event_zero_as_its_first_event(): void { - $this->executeCallback(function (): Generator { + $this->execute(function (): Generator { $value = yield Promise\timeout($this->resetEvent->promise(), 10000); $this->assertTrue($value); $this->assertSame(0, $this->firstEvent->originalEventNumber()); diff --git a/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_and_no_stream_async.php b/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_and_no_stream_async.php deleted file mode 100644 index 826c5b11..00000000 --- a/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_and_no_stream_async.php +++ /dev/null @@ -1,141 +0,0 @@ - - * (c) 2018-2018 Sascha-Oliver Prolic - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace ProophTest\EventStoreClient; - -use Amp\Deferred; -use Amp\Promise; -use Amp\Success; -use Generator; -use PHPUnit\Framework\TestCase; -use Prooph\EventStoreClient\EventAppearedOnPersistentSubscription; -use Prooph\EventStoreClient\EventData; -use Prooph\EventStoreClient\EventId; -use Prooph\EventStoreClient\ExpectedVersion; -use Prooph\EventStoreClient\Internal\AbstractEventStorePersistentSubscription; -use Prooph\EventStoreClient\Internal\ResolvedEvent; -use Prooph\EventStoreClient\Internal\UuidGenerator; -use Prooph\EventStoreClient\PersistentSubscriptionSettings; -use Throwable; -use function Amp\call; - -class connect_to_existing_persistent_subscription_with_start_from_beginning_and_no_stream_async extends TestCase -{ - use SpecificationWithConnection; - - /** @var string */ - private $stream; - /** @var PersistentSubscriptionSettings */ - private $settings; - /** @var string */ - private $group = 'startinbeginning1'; - /** @var ResolvedEvent */ - private $firstEvent; - /** @var Deferred */ - private $resetEvent; - /** @var array */ - private $ids = []; - /** @var bool */ - private $set = false; - - protected function setUp(): void - { - $this->stream = '$' . UuidGenerator::generate(); - $this->settings = PersistentSubscriptionSettings::create() - ->doNotResolveLinkTos() - ->startFromBeginning() - ->build(); - $this->resetEvent = new Deferred(); - } - - protected function given(): Generator - { - yield $this->conn->createPersistentSubscriptionAsync( - $this->stream, - $this->group, - $this->settings, - DefaultData::adminCredentials() - ); - - yield $this->conn->connectToPersistentSubscriptionAsync( - $this->stream, - $this->group, - new class($this->set, $this->resetEvent, $this->firstEvent) implements EventAppearedOnPersistentSubscription { - private $set; - private $deferred; - private $firstEvent; - - public function __construct(&$set, &$deferred, &$firstEvent) - { - $this->set = &$set; - $this->deferred = $deferred; - $this->firstEvent = &$firstEvent; - } - - public function __invoke( - AbstractEventStorePersistentSubscription $subscription, - ResolvedEvent $resolvedEvent, - ?int $retryCount = null - ): Promise { - if (! $this->set) { - $this->set = true; - $this->firstEvent = $resolvedEvent; - $this->deferred->resolve(true); - } - - return new Success(); - } - }, - null, - 10, - true, - DefaultData::adminCredentials() - ); - } - - private function writeEvents(): Promise - { - return call(function (): Generator { - for ($i = 0; $i < 10; $i++) { - $this->ids[$i] = EventId::generate(); - - yield $this->conn->appendToStreamAsync( - $this->stream, - ExpectedVersion::ANY, - [new EventData($this->ids[$i], 'test', true, '{"foo":"bar"}')], - DefaultData::adminCredentials() - ); - } - }); - } - - protected function when(): Generator - { - yield $this->writeEvents(); - } - - /** - * @test - * @throws Throwable - */ - public function the_subscription_gets_event_zero_as_its_first_event(): void - { - $this->executeCallback(function (): Generator { - $value = yield Promise\timeout($this->resetEvent->promise(), 10000); - $this->assertTrue($value); - $this->assertSame(0, $this->firstEvent->originalEventNumber()); - $this->assertTrue($this->firstEvent->originalEvent()->eventId()->equals($this->ids[0])); - - yield new Success(); - }); - } -} diff --git a/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it.php b/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it.php index c804ef0e..5b40bcdf 100644 --- a/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it.php +++ b/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it.php @@ -20,7 +20,6 @@ use PHPUnit\Framework\TestCase; use Prooph\EventStoreClient\EventAppearedOnPersistentSubscription; use Prooph\EventStoreClient\EventData; -use Prooph\EventStoreClient\EventId; use Prooph\EventStoreClient\ExpectedVersion; use Prooph\EventStoreClient\Internal\AbstractEventStorePersistentSubscription; use Prooph\EventStoreClient\Internal\ResolvedEvent; @@ -65,7 +64,7 @@ protected function given(): Generator $deferred = $this->resetEvent; - $this->conn->connectToPersistentSubscription( + yield $this->conn->connectToPersistentSubscriptionAsync( $this->stream, $this->group, new class($deferred) implements EventAppearedOnPersistentSubscription { @@ -99,12 +98,10 @@ private function writeEvents(): Promise { return call(function (): Generator { for ($i = 0; $i < 10; $i++) { - $this->ids[$i] = EventId::generate(); - yield $this->conn->appendToStreamAsync( $this->stream, ExpectedVersion::ANY, - [new EventData($this->ids[$i], 'test', true, '{"foo":"bar"}')], + [new EventData(null, 'test', true, '{"foo":"bar"}')], DefaultData::adminCredentials() ); } @@ -122,7 +119,7 @@ protected function when(): Generator */ public function the_subscription_gets_no_events(): void { - $this->executeCallback(function (): Generator { + $this->execute(function (): Generator { $this->expectException(TimeoutException::class); yield Promise\timeout($this->resetEvent->promise(), 1000); }); diff --git a/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it_async.php b/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it_async.php deleted file mode 100644 index 563321c1..00000000 --- a/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it_async.php +++ /dev/null @@ -1,127 +0,0 @@ - - * (c) 2018-2018 Sascha-Oliver Prolic - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace ProophTest\EventStoreClient; - -use Amp\Deferred; -use Amp\Promise; -use Amp\Success; -use Amp\TimeoutException; -use Generator; -use PHPUnit\Framework\TestCase; -use Prooph\EventStoreClient\EventAppearedOnPersistentSubscription; -use Prooph\EventStoreClient\EventData; -use Prooph\EventStoreClient\ExpectedVersion; -use Prooph\EventStoreClient\Internal\AbstractEventStorePersistentSubscription; -use Prooph\EventStoreClient\Internal\ResolvedEvent; -use Prooph\EventStoreClient\Internal\UuidGenerator; -use Prooph\EventStoreClient\PersistentSubscriptionSettings; -use Throwable; -use function Amp\call; - -class connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it_async extends TestCase -{ - use SpecificationWithConnection; - - /** @var string */ - private $stream; - /** @var PersistentSubscriptionSettings */ - private $settings; - /** @var string */ - private $group = 'startinbeginning1'; - /** @var Deferred */ - private $resetEvent; - - protected function setUp(): void - { - $this->stream = '$' . UuidGenerator::generate(); - $this->settings = PersistentSubscriptionSettings::create() - ->doNotResolveLinkTos() - ->startFromCurrent() - ->build(); - $this->resetEvent = new Deferred(); - } - - protected function given(): Generator - { - yield $this->writeEvents(); - - yield $this->conn->createPersistentSubscriptionAsync( - $this->stream, - $this->group, - $this->settings, - DefaultData::adminCredentials() - ); - - $deferred = $this->resetEvent; - - yield $this->conn->connectToPersistentSubscriptionAsync( - $this->stream, - $this->group, - new class($deferred) implements EventAppearedOnPersistentSubscription { - private $deferred; - - public function __construct($deferred) - { - $this->deferred = $deferred; - } - - public function __invoke( - AbstractEventStorePersistentSubscription $subscription, - ResolvedEvent $resolvedEvent, - ?int $retryCount = null - ): Promise { - if ($resolvedEvent->originalEventNumber() === 0) { - $this->deferred->resolve(true); - } - - return new Success(); - } - }, - null, - 10, - true, - DefaultData::adminCredentials() - ); - } - - private function writeEvents(): Promise - { - return call(function (): Generator { - for ($i = 0; $i < 10; $i++) { - yield $this->conn->appendToStreamAsync( - $this->stream, - ExpectedVersion::ANY, - [new EventData(null, 'test', true, '{"foo":"bar"}')], - DefaultData::adminCredentials() - ); - } - }); - } - - protected function when(): Generator - { - yield $this->writeEvents(); - } - - /** - * @test - * @throws Throwable - */ - public function the_subscription_gets_no_events(): void - { - $this->executeCallback(function (): Generator { - $this->expectException(TimeoutException::class); - yield Promise\timeout($this->resetEvent->promise(), 1000); - }); - } -} diff --git a/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it_then_event_written.php b/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it_then_event_written.php index 4d7e0a1a..b90f3607 100644 --- a/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it_then_event_written.php +++ b/tests/connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it_then_event_written.php @@ -66,7 +66,7 @@ protected function given(): Generator DefaultData::adminCredentials() ); - $this->conn->connectToPersistentSubscription( + yield $this->conn->connectToPersistentSubscriptionAsync( $this->stream, $this->group, new class($this->resetEvent, $this->firstEvent) implements EventAppearedOnPersistentSubscription { @@ -131,7 +131,7 @@ protected function when(): Generator */ public function the_subscription_gets_the_written_event_as_its_first_event(): void { - $this->executeCallback(function (): Generator { + $this->execute(function (): Generator { $value = yield Promise\timeout($this->resetEvent->promise(), 10000); $this->assertTrue($value); $this->assertNotNull($this->firstEvent); diff --git a/tests/connect_to_existing_persistent_subscription_with_start_from_two_and_no_stream.php b/tests/connect_to_existing_persistent_subscription_with_start_from_two_and_no_stream.php index 427ddc29..415b881a 100644 --- a/tests/connect_to_existing_persistent_subscription_with_start_from_two_and_no_stream.php +++ b/tests/connect_to_existing_persistent_subscription_with_start_from_two_and_no_stream.php @@ -66,7 +66,7 @@ protected function given(): Generator DefaultData::adminCredentials() ); - $this->conn->connectToPersistentSubscription( + yield $this->conn->connectToPersistentSubscriptionAsync( $this->stream, $this->group, new class($this->set, $this->resetEvent, $this->firstEvent) implements EventAppearedOnPersistentSubscription { @@ -132,7 +132,7 @@ protected function when(): Generator */ public function the_subscription_gets_event_two_as_its_first_event(): void { - $this->executeCallback(function (): Generator { + $this->execute(function (): Generator { $value = yield Promise\timeout($this->resetEvent->promise(), 10000); $this->assertTrue($value); $this->assertSame(2, $this->firstEvent->originalEventNumber()); diff --git a/tests/connect_to_existing_persistent_subscription_with_start_from_two_and_no_stream_async.php b/tests/connect_to_existing_persistent_subscription_with_start_from_two_and_no_stream_async.php deleted file mode 100644 index 7143ed79..00000000 --- a/tests/connect_to_existing_persistent_subscription_with_start_from_two_and_no_stream_async.php +++ /dev/null @@ -1,144 +0,0 @@ - - * (c) 2018-2018 Sascha-Oliver Prolic - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace ProophTest\EventStoreClient; - -use Amp\Deferred; -use Amp\Promise; -use Amp\Success; -use Generator; -use PHPUnit\Framework\TestCase; -use Prooph\EventStoreClient\EventAppearedOnPersistentSubscription; -use Prooph\EventStoreClient\EventData; -use Prooph\EventStoreClient\EventId; -use Prooph\EventStoreClient\ExpectedVersion; -use Prooph\EventStoreClient\Internal\AbstractEventStorePersistentSubscription; -use Prooph\EventStoreClient\Internal\ResolvedEvent; -use Prooph\EventStoreClient\Internal\UuidGenerator; -use Prooph\EventStoreClient\PersistentSubscriptionSettings; -use Throwable; - -class connect_to_existing_persistent_subscription_with_start_from_two_and_no_stream_async extends TestCase -{ - use SpecificationWithConnection; - - /** @var string */ - private $stream; - /** @var PersistentSubscriptionSettings */ - private $settings; - /** @var string */ - private $group = 'startinbeginning1'; - /** @var ResolvedEvent */ - private $firstEvent; - /** @var Deferred */ - private $resetEvent; - /** @var EventId */ - private $eventId; - /** @var bool */ - private $set = false; - - protected function setUp(): void - { - $this->eventId = EventId::generate(); - $this->stream = '$' . UuidGenerator::generate(); - $this->settings = PersistentSubscriptionSettings::create() - ->doNotResolveLinkTos() - ->startFrom(2) - ->build(); - $this->resetEvent = new Deferred(); - } - - protected function given(): Generator - { - yield $this->conn->createPersistentSubscriptionAsync( - $this->stream, - $this->group, - $this->settings, - DefaultData::adminCredentials() - ); - - yield $this->conn->connectToPersistentSubscriptionAsync( - $this->stream, - $this->group, - new class($this->set, $this->resetEvent, $this->firstEvent) implements EventAppearedOnPersistentSubscription { - private $set; - private $deferred; - private $firstEvent; - - public function __construct(&$set, &$deferred, &$firstEvent) - { - $this->set = &$set; - $this->deferred = $deferred; - $this->firstEvent = &$firstEvent; - } - - public function __invoke( - AbstractEventStorePersistentSubscription $subscription, - ResolvedEvent $resolvedEvent, - ?int $retryCount = null - ): Promise { - if (! $this->set) { - $this->set = true; - $this->firstEvent = $resolvedEvent; - $this->deferred->resolve(true); - } - - return new Success(); - } - }, - null, - 10, - true, - DefaultData::adminCredentials() - ); - } - - protected function when(): Generator - { - yield $this->conn->appendToStreamAsync( - $this->stream, - ExpectedVersion::ANY, - [new EventData(null, 'test', true, '{"foo":"bar"}')], - DefaultData::adminCredentials() - ); - - yield $this->conn->appendToStreamAsync( - $this->stream, - ExpectedVersion::ANY, - [new EventData(null, 'test', true, '{"foo":"bar"}')], - DefaultData::adminCredentials() - ); - - yield $this->conn->appendToStreamAsync( - $this->stream, - ExpectedVersion::ANY, - [new EventData($this->eventId, 'test', true, '{"foo":"bar"}')], - DefaultData::adminCredentials() - ); - } - - /** - * @test - * @throws Throwable - */ - public function the_subscription_gets_event_two_as_its_first_event(): void - { - $this->executeCallback(function (): Generator { - $value = yield Promise\timeout($this->resetEvent->promise(), 10000); - $this->assertTrue($value); - $this->assertSame(2, $this->firstEvent->originalEventNumber()); - $this->assertTrue($this->firstEvent->originalEvent()->eventId()->equals($this->eventId)); - - yield new Success(); - }); - } -} diff --git a/tests/connect_to_existing_persistent_subscription_with_start_from_x_set_and_events_in_it.php b/tests/connect_to_existing_persistent_subscription_with_start_from_x_set_and_events_in_it.php index fef1941b..05cc70a8 100644 --- a/tests/connect_to_existing_persistent_subscription_with_start_from_x_set_and_events_in_it.php +++ b/tests/connect_to_existing_persistent_subscription_with_start_from_x_set_and_events_in_it.php @@ -66,7 +66,7 @@ protected function given(): Generator DefaultData::adminCredentials() ); - $this->conn->connectToPersistentSubscription( + yield $this->conn->connectToPersistentSubscriptionAsync( $this->stream, $this->group, new class($this->resetEvent, $this->firstEvent) implements EventAppearedOnPersistentSubscription { @@ -133,7 +133,7 @@ protected function when(): Generator */ public function the_subscription_gets_the_written_event_as_its_first_event(): void { - $this->executeCallback(function (): Generator { + $this->execute(function (): Generator { $value = yield Promise\timeout($this->resetEvent->promise(), 10000); $this->assertTrue($value); $this->assertNotNull($this->firstEvent); diff --git a/tests/connect_to_existing_persistent_subscription_with_start_from_x_set_and_events_in_it_then_event_written.php b/tests/connect_to_existing_persistent_subscription_with_start_from_x_set_and_events_in_it_then_event_written.php index 35d5bed4..09407198 100644 --- a/tests/connect_to_existing_persistent_subscription_with_start_from_x_set_and_events_in_it_then_event_written.php +++ b/tests/connect_to_existing_persistent_subscription_with_start_from_x_set_and_events_in_it_then_event_written.php @@ -66,7 +66,7 @@ protected function given(): Generator DefaultData::adminCredentials() ); - $this->conn->connectToPersistentSubscription( + yield $this->conn->connectToPersistentSubscriptionAsync( $this->stream, $this->group, new class($this->resetEvent, $this->firstEvent) implements EventAppearedOnPersistentSubscription { @@ -131,7 +131,7 @@ protected function when(): Generator */ public function the_subscription_gets_the_written_event_as_its_first_event(): void { - $this->executeCallback(function (): Generator { + $this->execute(function (): Generator { $value = yield Promise\timeout($this->resetEvent->promise(), 10000); $this->assertTrue($value); $this->assertNotNull($this->firstEvent); diff --git a/tests/connect_to_existing_persistent_subscription_with_start_from_x_set_higher_than_x_and_events_in_it_then_event_written.php b/tests/connect_to_existing_persistent_subscription_with_start_from_x_set_higher_than_x_and_events_in_it_then_event_written.php index ba1d33a2..7b870357 100644 --- a/tests/connect_to_existing_persistent_subscription_with_start_from_x_set_higher_than_x_and_events_in_it_then_event_written.php +++ b/tests/connect_to_existing_persistent_subscription_with_start_from_x_set_higher_than_x_and_events_in_it_then_event_written.php @@ -66,7 +66,7 @@ protected function given(): Generator DefaultData::adminCredentials() ); - $this->conn->connectToPersistentSubscription( + yield $this->conn->connectToPersistentSubscriptionAsync( $this->stream, $this->group, new class($this->resetEvent, $this->firstEvent) implements EventAppearedOnPersistentSubscription { @@ -131,7 +131,7 @@ protected function when(): Generator */ public function the_subscription_gets_the_written_event_as_its_first_event(): void { - $this->executeCallback(function (): Generator { + $this->execute(function (): Generator { $value = yield Promise\timeout($this->resetEvent->promise(), 10000); $this->assertTrue($value); $this->assertNotNull($this->firstEvent); diff --git a/tests/connect_to_existing_persistent_subscription_without_permissions.php b/tests/connect_to_existing_persistent_subscription_without_permissions.php index 4a99968e..6ed76234 100644 --- a/tests/connect_to_existing_persistent_subscription_without_permissions.php +++ b/tests/connect_to_existing_persistent_subscription_without_permissions.php @@ -12,7 +12,6 @@ namespace ProophTest\EventStoreClient; -use Amp\Delayed; use Amp\Promise; use Amp\Success; use Generator; @@ -51,36 +50,32 @@ protected function when(): Generator $this->settings, DefaultData::adminCredentials() ); + + yield $this->conn->connectToPersistentSubscriptionAsync( + $this->stream, + 'agroupname55', + new class() implements EventAppearedOnPersistentSubscription { + public function __invoke( + AbstractEventStorePersistentSubscription $subscription, + ResolvedEvent $resolvedEvent, + ?int $retryCount = null + ): Promise { + return new Success(); + } + } + ); } /** * @test * @throws Throwable */ - public function the_subscription_fails_to_connect(): void + public function the_subscription_fails_to_connect_with_access_denied_exception(): void { - try { - $this->executeCallback(function (): Generator { - $this->conn->connectToPersistentSubscription( - $this->stream, - 'agroupname55', - new class() implements EventAppearedOnPersistentSubscription { - public function __invoke( - AbstractEventStorePersistentSubscription $subscription, - ResolvedEvent $resolvedEvent, - ?int $retryCount = null - ): Promise { - return new Success(); - } - } - ); - - yield new Delayed(50); // wait for it + $this->expectException(AccessDeniedException::class); - $this->fail('Should have thrown'); - }); - } catch (Throwable $e) { - $this->assertInstanceOf(AccessDeniedException::class, $e->getPrevious()); - } + $this->execute(function (): Generator { + yield new Success(); + }); } } diff --git a/tests/connect_to_existing_persistent_subscription_without_permissions_async.php b/tests/connect_to_existing_persistent_subscription_without_permissions_async.php deleted file mode 100644 index ede4e8c1..00000000 --- a/tests/connect_to_existing_persistent_subscription_without_permissions_async.php +++ /dev/null @@ -1,81 +0,0 @@ - - * (c) 2018-2018 Sascha-Oliver Prolic - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace ProophTest\EventStoreClient; - -use Amp\Promise; -use Amp\Success; -use Generator; -use PHPUnit\Framework\TestCase; -use Prooph\EventStoreClient\EventAppearedOnPersistentSubscription; -use Prooph\EventStoreClient\Exception\AccessDeniedException; -use Prooph\EventStoreClient\Internal\AbstractEventStorePersistentSubscription; -use Prooph\EventStoreClient\Internal\ResolvedEvent; -use Prooph\EventStoreClient\Internal\UuidGenerator; -use Prooph\EventStoreClient\PersistentSubscriptionSettings; -use Throwable; - -class connect_to_existing_persistent_subscription_without_permissions_async extends TestCase -{ - use SpecificationWithConnection; - - /** @var string */ - private $stream; - /** @var PersistentSubscriptionSettings */ - private $settings; - - protected function setUp(): void - { - $this->stream = '$' . UuidGenerator::generate(); - $this->settings = PersistentSubscriptionSettings::create() - ->doNotResolveLinkTos() - ->startFromCurrent() - ->build(); - } - - protected function when(): Generator - { - yield $this->conn->createPersistentSubscriptionAsync( - $this->stream, - 'agroupname55', - $this->settings, - DefaultData::adminCredentials() - ); - - yield $this->conn->connectToPersistentSubscriptionAsync( - $this->stream, - 'agroupname55', - new class() implements EventAppearedOnPersistentSubscription { - public function __invoke( - AbstractEventStorePersistentSubscription $subscription, - ResolvedEvent $resolvedEvent, - ?int $retryCount = null - ): Promise { - return new Success(); - } - } - ); - } - - /** - * @test - * @throws Throwable - */ - public function the_subscription_fails_to_connect_with_access_denied_exception(): void - { - $this->expectException(AccessDeniedException::class); - - $this->executeCallback(function (): Generator { - yield new Success(); - }); - } -} diff --git a/tests/connect_to_non_existing_persistent_subscription_with_permissions.php b/tests/connect_to_non_existing_persistent_subscription_with_permissions.php index 9493a733..27e8fa23 100644 --- a/tests/connect_to_non_existing_persistent_subscription_with_permissions.php +++ b/tests/connect_to_non_existing_persistent_subscription_with_permissions.php @@ -12,10 +12,8 @@ namespace ProophTest\EventStoreClient; -use Amp\Delayed; use Amp\Promise; use Amp\Success; -use Error; use Generator; use PHPUnit\Framework\TestCase; use Prooph\EventStoreClient\EventAppearedOnPersistentSubscription; @@ -30,6 +28,9 @@ class connect_to_non_existing_persistent_subscription_with_permissions extends T { use SpecificationWithConnection; + /** @var Throwable */ + private $exception; + protected function setUp(): void { $this->stream = '$' . UuidGenerator::generate(); @@ -41,37 +42,38 @@ protected function setUp(): void protected function when(): Generator { - $this->conn->connectToPersistentSubscription( - 'nonexisting2', - 'foo', - new class() implements EventAppearedOnPersistentSubscription { - public function __invoke( - AbstractEventStorePersistentSubscription $subscription, - ResolvedEvent $resolvedEvent, - ?int $retryCount = null - ): Promise { - return new Success(); + try { + yield $this->conn->connectToPersistentSubscriptionAsync( + 'nonexisting2', + 'foo', + new class() implements EventAppearedOnPersistentSubscription { + public function __invoke( + AbstractEventStorePersistentSubscription $subscription, + ResolvedEvent $resolvedEvent, + ?int $retryCount = null + ): Promise { + return new Success(); + } } - } - ); + ); - yield new Delayed(50); // wait for it - - $this->fail('should have thrown'); + $this->fail('should have thrown'); + } catch (Throwable $e) { + $this->exception = $e; + } } /** * @test * @throws Throwable */ - public function the_completion_fails(): void + public function the_subscription_fails_to_connect_with_invalid_argument_exception(): void { - try { - $this->executeCallback(function (): Generator { - yield new Success(); - }); - } catch (Error $e) { - $this->assertInstanceOf(InvalidArgumentException::class, $e->getPrevious()); - } + $this->execute(function (): Generator { + $this->assertNotNull($this->exception); + $this->assertInstanceOf(InvalidArgumentException::class, $this->exception); + + yield new Success(); + }); } } diff --git a/tests/connect_to_non_existing_persistent_subscription_with_permissions_async.php b/tests/connect_to_non_existing_persistent_subscription_with_permissions_async.php deleted file mode 100644 index 49594b20..00000000 --- a/tests/connect_to_non_existing_persistent_subscription_with_permissions_async.php +++ /dev/null @@ -1,79 +0,0 @@ - - * (c) 2018-2018 Sascha-Oliver Prolic - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace ProophTest\EventStoreClient; - -use Amp\Promise; -use Amp\Success; -use Generator; -use PHPUnit\Framework\TestCase; -use Prooph\EventStoreClient\EventAppearedOnPersistentSubscription; -use Prooph\EventStoreClient\Exception\InvalidArgumentException; -use Prooph\EventStoreClient\Internal\AbstractEventStorePersistentSubscription; -use Prooph\EventStoreClient\Internal\ResolvedEvent; -use Prooph\EventStoreClient\Internal\UuidGenerator; -use Prooph\EventStoreClient\PersistentSubscriptionSettings; -use Throwable; - -class connect_to_non_existing_persistent_subscription_with_permissions_async extends TestCase -{ - use SpecificationWithConnection; - - /** @var Throwable */ - private $exception; - - protected function setUp(): void - { - $this->stream = '$' . UuidGenerator::generate(); - $this->settings = PersistentSubscriptionSettings::create() - ->doNotResolveLinkTos() - ->startFromCurrent() - ->build(); - } - - protected function when(): Generator - { - try { - yield $this->conn->connectToPersistentSubscriptionAsync( - 'nonexisting2', - 'foo', - new class() implements EventAppearedOnPersistentSubscription { - public function __invoke( - AbstractEventStorePersistentSubscription $subscription, - ResolvedEvent $resolvedEvent, - ?int $retryCount = null - ): Promise { - return new Success(); - } - } - ); - - $this->fail('should have thrown'); - } catch (Throwable $e) { - $this->exception = $e; - } - } - - /** - * @test - * @throws Throwable - */ - public function the_subscription_fails_to_connect_with_invalid_argument_exception(): void - { - $this->executeCallback(function (): Generator { - $this->assertNotNull($this->exception); - $this->assertInstanceOf(InvalidArgumentException::class, $this->exception); - - yield new Success(); - }); - } -} diff --git a/tests/connect_to_persistent_subscription_with_retries.php b/tests/connect_to_persistent_subscription_with_retries.php index a1b3a5fa..ecb65b63 100644 --- a/tests/connect_to_persistent_subscription_with_retries.php +++ b/tests/connect_to_persistent_subscription_with_retries.php @@ -64,7 +64,7 @@ protected function given(): Generator DefaultData::adminCredentials() ); - $this->conn->connectToPersistentSubscription( + yield $this->conn->connectToPersistentSubscriptionAsync( $this->stream, 'agroupname55', new class($this->retryCount, $this->resetEvent) implements EventAppearedOnPersistentSubscription { @@ -120,7 +120,7 @@ protected function when(): Generator */ public function events_are_retried_until_success(): void { - $this->executeCallback(function (): Generator { + $this->execute(function (): Generator { $value = yield Promise\timeout($this->resetEvent->promise(), 10000); $this->assertTrue($value); $this->assertSame(5, $this->retryCount); diff --git a/tests/create_duplicate_persistent_subscription_group.php b/tests/create_duplicate_persistent_subscription_group.php index 290488f8..5454ee01 100644 --- a/tests/create_duplicate_persistent_subscription_group.php +++ b/tests/create_duplicate_persistent_subscription_group.php @@ -53,7 +53,7 @@ protected function when(): Generator */ public function the_completion_fails_with_invalid_operation_exception(): void { - $this->executeCallback(function (): Generator { + $this->execute(function (): Generator { $this->expectException(InvalidOperationException::class); yield $this->conn->createPersistentSubscriptionAsync( diff --git a/tests/create_persistent_subscription_after_deleting_the_same.php b/tests/create_persistent_subscription_after_deleting_the_same.php index 618888f5..b45ebec2 100644 --- a/tests/create_persistent_subscription_after_deleting_the_same.php +++ b/tests/create_persistent_subscription_after_deleting_the_same.php @@ -68,7 +68,7 @@ protected function when(): Generator */ public function the_completion_succeeds(): void { - $this->executeCallback(function () { + $this->execute(function () { yield $this->conn->createPersistentSubscriptionAsync( $this->stream, 'existing', diff --git a/tests/create_persistent_subscription_group_without_permissions.php b/tests/create_persistent_subscription_group_without_permissions.php index 85ea5dea..3c5391d1 100644 --- a/tests/create_persistent_subscription_group_without_permissions.php +++ b/tests/create_persistent_subscription_group_without_permissions.php @@ -49,7 +49,7 @@ protected function when(): Generator */ public function the_completion_succeeds(): void { - $this->executeCallback(function () { + $this->execute(function () { try { yield $this->conn->createPersistentSubscriptionAsync( $this->stream, diff --git a/tests/create_persistent_subscription_on_all_stream.php b/tests/create_persistent_subscription_on_all_stream.php index 27b4a54a..9537f1e1 100644 --- a/tests/create_persistent_subscription_on_all_stream.php +++ b/tests/create_persistent_subscription_on_all_stream.php @@ -45,7 +45,7 @@ protected function when(): Generator */ public function the_completion_fails_with_invalid_stream(): void { - $this->executeCallback(function () { + $this->execute(function () { try { yield $this->conn->createPersistentSubscriptionAsync( '$all', diff --git a/tests/create_persistent_subscription_on_existing_stream.php b/tests/create_persistent_subscription_on_existing_stream.php index c8b05334..1838ff1e 100644 --- a/tests/create_persistent_subscription_on_existing_stream.php +++ b/tests/create_persistent_subscription_on_existing_stream.php @@ -54,7 +54,7 @@ protected function when(): Generator */ public function the_completion_succeeds(): void { - $this->executeCallback(function () { + $this->execute(function () { yield $this->conn->createPersistentSubscriptionAsync( $this->stream, 'existing', diff --git a/tests/create_persistent_subscription_on_non_existing_stream.php b/tests/create_persistent_subscription_on_non_existing_stream.php index 37d7c394..e98bfe78 100644 --- a/tests/create_persistent_subscription_on_non_existing_stream.php +++ b/tests/create_persistent_subscription_on_non_existing_stream.php @@ -49,7 +49,7 @@ protected function when(): Generator */ public function the_completion_succeeds(): void { - $this->executeCallback(function () { + $this->execute(function () { yield $this->conn->createPersistentSubscriptionAsync( $this->stream, 'nonexistinggroup', diff --git a/tests/create_persistent_subscription_with_dont_timeout.php b/tests/create_persistent_subscription_with_dont_timeout.php index 0190bfc6..a093503b 100644 --- a/tests/create_persistent_subscription_with_dont_timeout.php +++ b/tests/create_persistent_subscription_with_dont_timeout.php @@ -59,7 +59,7 @@ public function the_message_timeout_should_be_zero(): void */ public function the_subscription_is_created_without_error(): void { - $this->executeCallback(function () { + $this->execute(function () { yield $this->conn->createPersistentSubscriptionAsync( $this->stream, 'dont-timeout', diff --git a/tests/deleting_existing_persistent_subscription_group_with_permissions.php b/tests/deleting_existing_persistent_subscription_group_with_permissions.php index 93beee10..a86a084f 100644 --- a/tests/deleting_existing_persistent_subscription_group_with_permissions.php +++ b/tests/deleting_existing_persistent_subscription_group_with_permissions.php @@ -53,7 +53,7 @@ protected function when(): Generator */ public function the_delete_of_group_succeeds(): void { - $this->executeCallback(function () { + $this->execute(function () { yield $this->conn->deletePersistentSubscriptionAsync( $this->stream, 'groupname123', diff --git a/tests/deleting_existing_persistent_subscription_with_subscriber.php b/tests/deleting_existing_persistent_subscription_with_subscriber.php index 03114e9f..0e1d7c0c 100644 --- a/tests/deleting_existing_persistent_subscription_with_subscriber.php +++ b/tests/deleting_existing_persistent_subscription_with_subscriber.php @@ -56,7 +56,7 @@ protected function given(): Generator DefaultData::adminCredentials() ); - $this->conn->connectToPersistentSubscription( + yield $this->conn->connectToPersistentSubscriptionAsync( $this->stream, 'groupname123', new class() implements EventAppearedOnPersistentSubscription { @@ -102,7 +102,7 @@ protected function when(): Generator */ public function the_subscription_is_dropped(): void { - $this->executeCallback(function () { + $this->execute(function () { $value = yield Promise\timeout($this->called->promise(), 5000); $this->assertTrue($value); }); diff --git a/tests/deleting_persistent_subscription_group_that_doesnt_exist.php b/tests/deleting_persistent_subscription_group_that_doesnt_exist.php index d48a7052..0689648f 100644 --- a/tests/deleting_persistent_subscription_group_that_doesnt_exist.php +++ b/tests/deleting_persistent_subscription_group_that_doesnt_exist.php @@ -42,7 +42,7 @@ protected function when(): Generator */ public function the_delete_fails_with_argument_exception(): void { - $this->executeCallback(function () { + $this->execute(function () { $this->expectException(InvalidOperationException::class); yield $this->conn->deletePersistentSubscriptionAsync( diff --git a/tests/deleting_persistent_subscription_group_without_permissions.php b/tests/deleting_persistent_subscription_group_without_permissions.php index 39b79cbf..eaa2e79e 100644 --- a/tests/deleting_persistent_subscription_group_without_permissions.php +++ b/tests/deleting_persistent_subscription_group_without_permissions.php @@ -42,7 +42,7 @@ protected function when(): Generator */ public function the_delete_fails_with_access_denied(): void { - $this->executeCallback(function () { + $this->execute(function () { $this->expectException(AccessDeniedException::class); yield $this->conn->deletePersistentSubscriptionAsync( diff --git a/tests/happy_case_catching_up_to_link_to_events_auto_ack.php b/tests/happy_case_catching_up_to_link_to_events_auto_ack.php index 2b7bc87b..0acf9432 100644 --- a/tests/happy_case_catching_up_to_link_to_events_auto_ack.php +++ b/tests/happy_case_catching_up_to_link_to_events_auto_ack.php @@ -64,7 +64,7 @@ protected function when(): Generator */ public function test(): void { - $this->executeCallback(function () { + $this->execute(function () { $settings = PersistentSubscriptionSettings::create() ->startFromBeginning() ->resolveLinkTos() @@ -88,7 +88,7 @@ public function test(): void DefaultData::adminCredentials() ); - $this->conn->connectToPersistentSubscription( + yield $this->conn->connectToPersistentSubscriptionAsync( $this->streamName, $this->groupName, new class($this->eventsReceived, $this->eventReceivedCount, self::EVENT_WRITE_COUNT) implements EventAppearedOnPersistentSubscription { diff --git a/tests/happy_case_catching_up_to_link_to_events_manual_ack.php b/tests/happy_case_catching_up_to_link_to_events_manual_ack.php index 3f693a5f..737dcc2e 100644 --- a/tests/happy_case_catching_up_to_link_to_events_manual_ack.php +++ b/tests/happy_case_catching_up_to_link_to_events_manual_ack.php @@ -64,7 +64,7 @@ protected function when(): Generator */ public function test(): void { - $this->executeCallback(function () { + $this->execute(function () { $settings = PersistentSubscriptionSettings::create() ->startFromBeginning() ->resolveLinkTos() @@ -88,7 +88,7 @@ public function test(): void DefaultData::adminCredentials() ); - $this->conn->connectToPersistentSubscription( + yield $this->conn->connectToPersistentSubscriptionAsync( $this->streamName, $this->groupName, new class($this->eventsReceived, $this->eventReceivedCount, self::EVENT_WRITE_COUNT) implements EventAppearedOnPersistentSubscription { diff --git a/tests/happy_case_catching_up_to_normal_events_auto_ack.php b/tests/happy_case_catching_up_to_normal_events_auto_ack.php index 94555648..aee1350d 100644 --- a/tests/happy_case_catching_up_to_normal_events_auto_ack.php +++ b/tests/happy_case_catching_up_to_normal_events_auto_ack.php @@ -63,7 +63,7 @@ protected function when(): Generator */ public function test(): void { - $this->executeCallback(function () { + $this->execute(function () { $settings = PersistentSubscriptionSettings::create() ->startFromBeginning() ->resolveLinkTos() @@ -87,7 +87,7 @@ public function test(): void DefaultData::adminCredentials() ); - $this->conn->connectToPersistentSubscription( + yield $this->conn->connectToPersistentSubscriptionAsync( $this->streamName, $this->groupName, new class($this->eventsReceived, $this->eventReceivedCount, self::EVENT_WRITE_COUNT) implements EventAppearedOnPersistentSubscription { diff --git a/tests/happy_case_catching_up_to_normal_events_manual_ack.php b/tests/happy_case_catching_up_to_normal_events_manual_ack.php index 5b7870ae..49efce77 100644 --- a/tests/happy_case_catching_up_to_normal_events_manual_ack.php +++ b/tests/happy_case_catching_up_to_normal_events_manual_ack.php @@ -63,7 +63,7 @@ protected function when(): Generator */ public function test(): void { - $this->executeCallback(function () { + $this->execute(function () { $settings = PersistentSubscriptionSettings::create() ->startFromBeginning() ->resolveLinkTos() @@ -87,7 +87,7 @@ public function test(): void DefaultData::adminCredentials() ); - $this->conn->connectToPersistentSubscription( + yield $this->conn->connectToPersistentSubscriptionAsync( $this->streamName, $this->groupName, new class($this->eventsReceived, $this->eventReceivedCount, self::EVENT_WRITE_COUNT) implements EventAppearedOnPersistentSubscription { diff --git a/tests/happy_case_writing_and_subscribing_to_normal_events_auto_ack.php b/tests/happy_case_writing_and_subscribing_to_normal_events_auto_ack.php index ed400409..99402502 100644 --- a/tests/happy_case_writing_and_subscribing_to_normal_events_auto_ack.php +++ b/tests/happy_case_writing_and_subscribing_to_normal_events_auto_ack.php @@ -63,7 +63,7 @@ protected function when(): Generator */ public function test(): void { - $this->executeCallback(function () { + $this->execute(function () { $settings = PersistentSubscriptionSettings::default(); yield $this->conn->createPersistentSubscriptionAsync( @@ -73,7 +73,7 @@ public function test(): void DefaultData::adminCredentials() ); - $this->conn->connectToPersistentSubscription( + yield $this->conn->connectToPersistentSubscriptionAsync( $this->streamName, $this->groupName, new class($this->eventsReceived, $this->eventReceivedCount, self::EVENT_WRITE_COUNT) implements EventAppearedOnPersistentSubscription { diff --git a/tests/happy_case_writing_and_subscribing_to_normal_events_manual_ack.php b/tests/happy_case_writing_and_subscribing_to_normal_events_manual_ack.php index e49860c2..a2a45eda 100644 --- a/tests/happy_case_writing_and_subscribing_to_normal_events_manual_ack.php +++ b/tests/happy_case_writing_and_subscribing_to_normal_events_manual_ack.php @@ -63,7 +63,7 @@ protected function when(): Generator */ public function test(): void { - $this->executeCallback(function () { + $this->execute(function () { $settings = PersistentSubscriptionSettings::default(); yield $this->conn->createPersistentSubscriptionAsync( @@ -73,7 +73,7 @@ public function test(): void DefaultData::adminCredentials() ); - $this->conn->connectToPersistentSubscription( + yield $this->conn->connectToPersistentSubscriptionAsync( $this->streamName, $this->groupName, new class($this->eventsReceived, $this->eventReceivedCount, self::EVENT_WRITE_COUNT) implements EventAppearedOnPersistentSubscription { diff --git a/tests/read_all_events_backward_should.php b/tests/read_all_events_backward_should.php index 58611222..e574bff0 100644 --- a/tests/read_all_events_backward_should.php +++ b/tests/read_all_events_backward_should.php @@ -103,7 +103,7 @@ protected function end(): Generator */ public function return_empty_slice_if_asked_to_read_from_start(): void { - $this->executeCallback(function () { + $this->execute(function () { /** @var AllEventsSlice $read */ $read = yield $this->conn->readAllEventsBackwardAsync(Position::start(), 1, false); @@ -118,7 +118,7 @@ public function return_empty_slice_if_asked_to_read_from_start(): void */ public function return_events_in_reversed_order_compared_to_written(): void { - $this->executeCallback(function () { + $this->execute(function () { /** @var AllEventsSlice $read */ $read = yield $this->conn->readAllEventsBackwardAsync($this->endOfEvents, \count($this->testEvents), false); @@ -142,7 +142,7 @@ function (ResolvedEvent $resolvedEvent): RecordedEvent { */ public function be_able_to_read_all_one_by_one_until_end_of_stream(): void { - $this->executeCallback(function () { + $this->execute(function () { $all = []; $position = $this->endOfEvents; @@ -170,7 +170,7 @@ public function be_able_to_read_all_one_by_one_until_end_of_stream(): void */ public function be_able_to_read_events_slice_at_time(): void { - $this->executeCallback(function () { + $this->execute(function () { $all = []; $position = $this->endOfEvents; @@ -197,7 +197,7 @@ public function be_able_to_read_events_slice_at_time(): void */ public function throw_when_got_int_max_value_as_maxcount(): void { - $this->executeCallback(function () { + $this->execute(function () { $this->expectException(InvalidArgumentException::class); yield $this->conn->readAllEventsBackwardAsync(Position::start(), \PHP_INT_MAX, false); diff --git a/tests/read_all_events_backward_with_linkto_deleted_event.php b/tests/read_all_events_backward_with_linkto_deleted_event.php index ea45e97b..410f7cda 100644 --- a/tests/read_all_events_backward_with_linkto_deleted_event.php +++ b/tests/read_all_events_backward_with_linkto_deleted_event.php @@ -40,7 +40,7 @@ protected function when(): Generator */ public function one_event_is_read(): void { - $this->executeCallback(function () { + $this->execute(function () { $this->assertCount(1, $this->read->events()); yield new Success(); @@ -53,7 +53,7 @@ public function one_event_is_read(): void */ public function the_linked_event_is_not_resolved(): void { - $this->executeCallback(function () { + $this->execute(function () { $this->assertNull($this->read->events()[0]->event()); yield new Success(); @@ -66,7 +66,7 @@ public function the_linked_event_is_not_resolved(): void */ public function the_link_event_is_included(): void { - $this->executeCallback(function () { + $this->execute(function () { $this->assertNotNull($this->read->events()[0]->originalEvent()); yield new Success(); @@ -79,7 +79,7 @@ public function the_link_event_is_included(): void */ public function the_event_is_not_resolved(): void { - $this->executeCallback(function () { + $this->execute(function () { $this->assertFalse($this->read->events()[0]->isResolved()); yield new Success(); diff --git a/tests/read_all_events_forward_should.php b/tests/read_all_events_forward_should.php index f74b5f42..2d363c06 100644 --- a/tests/read_all_events_forward_should.php +++ b/tests/read_all_events_forward_should.php @@ -89,7 +89,7 @@ protected function end(): Generator */ public function return_empty_slice_if_asked_to_read_from_end(): void { - $this->executeCallback(function () { + $this->execute(function () { /** @var AllEventsSlice $read */ $read = yield $this->conn->readAllEventsForwardAsync(Position::end(), 1, false); @@ -104,7 +104,7 @@ public function return_empty_slice_if_asked_to_read_from_end(): void */ public function return_events_in_same_order_as_written(): void { - $this->executeCallback(function () { + $this->execute(function () { /** @var AllEventsSlice $read */ $read = yield $this->conn->readAllEventsForwardAsync($this->from, \count($this->testEvents) + 10, false); @@ -125,7 +125,7 @@ function (ResolvedEvent $e): RecordedEvent { */ public function be_able_to_read_all_one_by_one_until_end_of_stream(): void { - $this->executeCallback(function () { + $this->execute(function () { $all = []; $position = $this->from; @@ -153,7 +153,7 @@ public function be_able_to_read_all_one_by_one_until_end_of_stream(): void */ public function be_able_to_read_events_slice_at_time(): void { - $this->executeCallback(function () { + $this->execute(function () { $all = []; $position = $this->from; @@ -180,7 +180,7 @@ public function be_able_to_read_events_slice_at_time(): void */ public function return_partial_slice_if_not_enough_events(): void { - $this->executeCallback(function () { + $this->execute(function () { /** @var AllEventsSlice $read */ $read = yield $this->conn->readAllEventsForwardAsync($this->from, 30, false); @@ -203,7 +203,7 @@ function (ResolvedEvent $e): RecordedEvent { */ public function throw_when_got_int_max_value_as_maxcount(): void { - $this->executeCallback(function () { + $this->execute(function () { $this->expectException(InvalidArgumentException::class); yield $this->conn->readAllEventsForwardAsync(Position::start(), \PHP_INT_MAX, false); diff --git a/tests/read_all_events_forward_with_hard_deleted_stream_should.php b/tests/read_all_events_forward_with_hard_deleted_stream_should.php index c2b70c6c..a27bb944 100644 --- a/tests/read_all_events_forward_with_hard_deleted_stream_should.php +++ b/tests/read_all_events_forward_with_hard_deleted_stream_should.php @@ -85,7 +85,7 @@ protected function when(): Generator */ public function ensure_deleted_stream(): void { - $this->executeCallback(function () { + $this->execute(function () { /** @var StreamEventsSlice $res */ $res = yield $this->conn->readStreamEventsForwardAsync($this->streamName, 0, 100, false); $this->assertTrue($res->status()->equals(SliceReadStatus::streamDeleted())); @@ -99,7 +99,7 @@ public function ensure_deleted_stream(): void */ public function returns_all_events_including_tombstone(): void { - $this->executeCallback(function () { + $this->execute(function () { /** @var AllEventsSlice $read */ $read = yield $this->conn->readAllEventsForwardAsync($this->from, \count($this->testEvents) + 10, false); diff --git a/tests/read_all_events_forward_with_linkto_passed_max_count.php b/tests/read_all_events_forward_with_linkto_passed_max_count.php index d13f7a74..5ac1f9f3 100644 --- a/tests/read_all_events_forward_with_linkto_passed_max_count.php +++ b/tests/read_all_events_forward_with_linkto_passed_max_count.php @@ -36,7 +36,7 @@ protected function when(): Generator */ public function one_event_is_read(): void { - $this->executeCallback(function () { + $this->execute(function () { $this->assertCount(1, $this->read->events()); yield new Success(); diff --git a/tests/read_all_events_forward_with_soft_deleted_stream_should.php b/tests/read_all_events_forward_with_soft_deleted_stream_should.php index 43513e3d..c732ecd8 100644 --- a/tests/read_all_events_forward_with_soft_deleted_stream_should.php +++ b/tests/read_all_events_forward_with_soft_deleted_stream_should.php @@ -75,7 +75,7 @@ protected function when(): Generator */ public function ensure_deleted_stream(): void { - $this->executeCallback(function () { + $this->execute(function () { /** @var StreamEventsSlice $res */ $res = yield $this->conn->readStreamEventsForwardAsync($this->streamName, 0, 100, false); $this->assertTrue($res->status()->equals(SliceReadStatus::streamNotFound())); @@ -90,7 +90,7 @@ public function ensure_deleted_stream(): void */ public function returns_all_events_including_tombstone(): void { - $this->executeCallback(function () { + $this->execute(function () { /** @var StreamEventsSlice $metadataEvents */ $metadataEvents = yield $this->conn->readStreamEventsBackwardAsync( '$$' . $this->streamName, diff --git a/tests/read_event_of_linkto_to_deleted_event.php b/tests/read_event_of_linkto_to_deleted_event.php index 11f605a5..d04ec184 100644 --- a/tests/read_event_of_linkto_to_deleted_event.php +++ b/tests/read_event_of_linkto_to_deleted_event.php @@ -41,7 +41,7 @@ protected function when(): Generator */ public function the_linked_event_is_returned(): void { - $this->executeCallback(function () { + $this->execute(function () { $this->assertNotNull($this->read->event()->link()); yield new Success(); @@ -54,7 +54,7 @@ public function the_linked_event_is_returned(): void */ public function the_deleted_event_is_not_resolved(): void { - $this->executeCallback(function () { + $this->execute(function () { $this->assertNull($this->read->event()->event()); yield new Success(); @@ -67,7 +67,7 @@ public function the_deleted_event_is_not_resolved(): void */ public function the_status_is_success(): void { - $this->executeCallback(function () { + $this->execute(function () { $this->assertTrue(EventReadStatus::success()->equals($this->read->status())); yield new Success(); diff --git a/tests/read_event_should.php b/tests/read_event_should.php index b6d23364..cf8e5b28 100644 --- a/tests/read_event_should.php +++ b/tests/read_event_should.php @@ -57,7 +57,7 @@ protected function when(): Generator */ public function throw_if_stream_id_is_empty(): void { - $this->executeCallback(function () { + $this->execute(function () { $this->expectException(InvalidArgumentException::class); $this->conn->readEventAsync('', 0, false); }); @@ -69,7 +69,7 @@ public function throw_if_stream_id_is_empty(): void */ public function throw_if_event_number_is_less_than_minus_one(): void { - $this->executeCallback(function () { + $this->execute(function () { $this->expectException(OutOfRangeException::class); $this->conn->readEventAsync('stream', -2, false); }); @@ -81,7 +81,7 @@ public function throw_if_event_number_is_less_than_minus_one(): void */ public function notify_using_status_code_if_stream_not_found(): void { - $this->executeCallback(function () { + $this->execute(function () { /** @var EventReadResult $res */ $res = yield $this->conn->readEventAsync('unexisting-stream', 5, false); @@ -98,7 +98,7 @@ public function notify_using_status_code_if_stream_not_found(): void */ public function return_no_stream_if_requested_last_event_in_empty_stream(): void { - $this->executeCallback(function () { + $this->execute(function () { /** @var EventReadResult $res */ $res = yield $this->conn->readEventAsync('some-really-empty-stream', -1, false); @@ -112,7 +112,7 @@ public function return_no_stream_if_requested_last_event_in_empty_stream(): void */ public function notify_using_status_code_if_stream_was_deleted(): void { - $this->executeCallback(function () { + $this->execute(function () { /** @var EventReadResult $res */ $res = yield $this->conn->readEventAsync($this->deletedStream, 5, false); @@ -129,7 +129,7 @@ public function notify_using_status_code_if_stream_was_deleted(): void */ public function notify_using_status_code_if_stream_does_not_have_event(): void { - $this->executeCallback(function () { + $this->execute(function () { /** @var EventReadResult $res */ $res = yield $this->conn->readEventAsync($this->testStream, 5, false); @@ -146,7 +146,7 @@ public function notify_using_status_code_if_stream_does_not_have_event(): void */ public function return_existing_event(): void { - $this->executeCallback(function () { + $this->execute(function () { /** @var EventReadResult $res */ $res = yield $this->conn->readEventAsync($this->testStream, 0, false); @@ -164,7 +164,7 @@ public function return_existing_event(): void */ public function retrieve_the_is_json_flag_properly(): void { - $this->executeCallback(function () { + $this->execute(function () { /** @var EventReadResult $res */ $res = yield $this->conn->readEventAsync($this->testStream, 1, false); @@ -180,7 +180,7 @@ public function retrieve_the_is_json_flag_properly(): void */ public function return_last_event_in_stream_if_event_number_is_minus_one(): void { - $this->executeCallback(function () { + $this->execute(function () { /** @var EventReadResult $res */ $res = yield $this->conn->readEventAsync($this->testStream, -1, false); diff --git a/tests/read_stream_events_with_unresolved_linkto.php b/tests/read_stream_events_with_unresolved_linkto.php index 325f8256..9203b190 100644 --- a/tests/read_stream_events_with_unresolved_linkto.php +++ b/tests/read_stream_events_with_unresolved_linkto.php @@ -70,7 +70,7 @@ public function ensure_deleted_stream(): void $this->stream = 'read_stream_events_with_unresolved_linkto_1'; $this->links = 'read_stream_events_with_unresolved_linkto_links_1'; - $this->executeCallback(function () { + $this->execute(function () { /** @var StreamEventsSlice $res */ $res = yield $this->conn->readStreamEventsForwardAsync( $this->stream, @@ -93,7 +93,7 @@ public function returns_unresolved_linkto(): void $this->stream = 'read_stream_events_with_unresolved_linkto_2'; $this->links = 'read_stream_events_with_unresolved_linkto_links_2'; - $this->executeCallback(function () { + $this->execute(function () { /** @var StreamEventsSlice $read */ $read = yield $this->conn->readStreamEventsForwardAsync( $this->links,