Skip to content

Commit

Permalink
remove ExpectedVersion::EmptyStream
Browse files Browse the repository at this point in the history
  • Loading branch information
prolic committed Aug 24, 2019
1 parent b11bcee commit 1ce899d
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 76 deletions.
24 changes: 12 additions & 12 deletions tests/append_to_stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,11 @@ public function in_slightly_reasonable_multiple_case_of_multiple_writes_with_exp
$x = TestEvent::newTestEvent();
$events = [$x, $x, $x, $x, $x, $x];

$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, $events);
$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::NO_STREAM, $events);
\assert($result instanceof WriteResult);
$this->assertSame(5, $result->nextExpectedVersion());

$f = yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, $events);
$f = yield $connection->appendToStreamAsync($stream, ExpectedVersion::NO_STREAM, $events);
\assert($f instanceof WriteResult);
$this->assertSame(5, $f->nextExpectedVersion());

Expand All @@ -272,7 +272,7 @@ public function should_fail_writing_with_correct_exp_ver_to_deleted_stream(): vo

yield $connection->connectAsync();

yield $connection->deleteStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, true);
yield $connection->deleteStreamAsync($stream, ExpectedVersion::NO_STREAM, true);

try {
$this->expectException(StreamDeleted::class);
Expand All @@ -296,7 +296,7 @@ public function should_return_log_position_when_writing(): void

yield $connection->connectAsync();

$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::newTestEvent()]);
$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::NO_STREAM, [TestEvent::newTestEvent()]);
\assert($result instanceof WriteResult);
$this->assertGreaterThan(0, $result->logPosition()->preparePosition());
$this->assertGreaterThan(0, $result->logPosition()->commitPosition());
Expand All @@ -319,7 +319,7 @@ public function should_fail_writing_with_any_exp_ver_to_deleted_stream(): void
yield $connection->connectAsync();

try {
yield $connection->deleteStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, true);
yield $connection->deleteStreamAsync($stream, ExpectedVersion::NO_STREAM, true);
} catch (Throwable $e) {
$this->fail($e->getMessage());
}
Expand All @@ -346,7 +346,7 @@ public function should_fail_writing_with_invalid_exp_ver_to_deleted_stream(): vo

yield $connection->connectAsync();

yield $connection->deleteStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, true);
yield $connection->deleteStreamAsync($stream, ExpectedVersion::NO_STREAM, true);

$this->expectException(StreamDeleted::class);
try {
Expand All @@ -371,7 +371,7 @@ public function should_append_with_correct_exp_ver_to_existing_stream(): void

yield $connection->connectAsync();

yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::newTestEvent()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::NO_STREAM, [TestEvent::newTestEvent()]);

$connection->close();
}));
Expand All @@ -390,7 +390,7 @@ public function should_append_with_any_exp_ver_to_existing_stream(): void

yield $connection->connectAsync();

$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::newTestEvent()]);
$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::NO_STREAM, [TestEvent::newTestEvent()]);
\assert($result instanceof WriteResult);
$this->assertSame(0, $result->nextExpectedVersion());

Expand Down Expand Up @@ -437,7 +437,7 @@ public function should_append_with_stream_exists_exp_ver_to_existing_stream(): v

yield $connection->connectAsync();

yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::newTestEvent()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::NO_STREAM, [TestEvent::newTestEvent()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::STREAM_EXISTS, [TestEvent::newTestEvent()]);

$connection->close();
Expand Down Expand Up @@ -531,7 +531,7 @@ public function should_fail_appending_with_stream_exists_exp_ver_to_hard_deleted

yield $connection->connectAsync();

yield $connection->deleteStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, true);
yield $connection->deleteStreamAsync($stream, ExpectedVersion::NO_STREAM, true);

try {
$this->expectException(StreamDeleted::class);
Expand All @@ -555,7 +555,7 @@ public function should_fail_appending_with_stream_exists_exp_ver_to_soft_deleted

yield $connection->connectAsync();

yield $connection->deleteStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, false);
yield $connection->deleteStreamAsync($stream, ExpectedVersion::NO_STREAM, false);

try {
$this->expectException(StreamDeleted::class);
Expand All @@ -581,7 +581,7 @@ public function can_append_multiple_events_at_once(): void

$events = TestEvent::newAmount(100);

$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, $events);
$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::NO_STREAM, $events);
\assert($result instanceof WriteResult);

$this->assertSame(99, $result->nextExpectedVersion());
Expand Down
2 changes: 1 addition & 1 deletion tests/connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function should_close_connection_after_configured_amount_of_failed_reconn

$this->expectException(InvalidOperationException::class);

yield $connection->appendToStreamAsync('stream', ExpectedVersion::EMPTY_STREAM, [TestEvent::newTestEvent()]);
yield $connection->appendToStreamAsync('stream', ExpectedVersion::NO_STREAM, [TestEvent::newTestEvent()]);
}));
}
}
8 changes: 4 additions & 4 deletions tests/deleting_stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function which_doesnt_exists_should_success_when_passed_empty_stream_expe

yield $connection->connectAsync();

yield $connection->deleteStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, true);
yield $connection->deleteStreamAsync($stream, ExpectedVersion::NO_STREAM, true);

$connection->close();
}));
Expand Down Expand Up @@ -101,7 +101,7 @@ public function should_return_log_position_when_writing(): void

yield $connection->connectAsync();

yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::newTestEvent()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::NO_STREAM, [TestEvent::newTestEvent()]);

$delete = yield $connection->deleteStreamAsync($stream, 0, true);
\assert($delete instanceof DeleteResult);
Expand All @@ -126,11 +126,11 @@ public function which_was_already_deleted_should_fail(): void

yield $connection->connectAsync();

yield $connection->deleteStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, true);
yield $connection->deleteStreamAsync($stream, ExpectedVersion::NO_STREAM, true);

try {
$this->expectException(StreamDeleted::class);
yield $connection->deleteStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, true);
yield $connection->deleteStreamAsync($stream, ExpectedVersion::NO_STREAM, true);
} finally {
$connection->close();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/read_all_events_backward_should.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected function when(): Generator

$this->testEvents = TestEvent::newAmount(20);

yield $this->conn->appendToStreamAsync('stream-' . Guid::generateAsHex(), ExpectedVersion::EMPTY_STREAM, $this->testEvents);
yield $this->conn->appendToStreamAsync('stream-' . Guid::generateAsHex(), ExpectedVersion::NO_STREAM, $this->testEvents);

$result = yield $this->conn->appendToStreamAsync('stream-' . Guid::generateAsHex(), ExpectedVersion::NO_STREAM, $this->testEvents);
\assert($result instanceof WriteResult);
Expand Down
2 changes: 1 addition & 1 deletion tests/read_all_events_forward_should.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function when(): Generator
$this->testEvents = TestEvent::newAmount(20);
$this->stream = 'read_all_events_forward_should-' . Guid::generateAsHex();

yield $this->conn->appendToStreamAsync($this->stream, ExpectedVersion::EMPTY_STREAM, $this->testEvents);
yield $this->conn->appendToStreamAsync($this->stream, ExpectedVersion::NO_STREAM, $this->testEvents);
}

protected function end(): Generator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function when(): Generator

yield $this->conn->appendToStreamAsync(
$this->streamName,
ExpectedVersion::EMPTY_STREAM,
ExpectedVersion::NO_STREAM,
$this->testEvents
);

Expand Down
14 changes: 7 additions & 7 deletions tests/read_event_stream_backward_should.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function notify_using_status_code_if_stream_was_deleted(): void

$store = TestConnection::create();
yield $store->connectAsync();
yield $store->deleteStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, true);
yield $store->deleteStreamAsync($stream, ExpectedVersion::NO_STREAM, true);

$read = yield $store->readStreamEventsBackwardAsync(
$stream,
Expand Down Expand Up @@ -141,7 +141,7 @@ public function return_partial_slice_if_no_enough_events_in_stream(): void
$testEvents = TestEvent::newAmount(10);
yield $store->appendToStreamAsync(
$stream,
ExpectedVersion::EMPTY_STREAM,
ExpectedVersion::NO_STREAM,
$testEvents
);

Expand Down Expand Up @@ -172,7 +172,7 @@ public function return_events_reversed_compared_to_written(): void
$testEvents = TestEvent::newAmount(10);
yield $store->appendToStreamAsync(
$stream,
ExpectedVersion::EMPTY_STREAM,
ExpectedVersion::NO_STREAM,
$testEvents
);

Expand Down Expand Up @@ -210,7 +210,7 @@ public function be_able_to_read_single_event_from_arbitrary_position(): void
$testEvents = TestEvent::newAmount(10);
yield $store->appendToStreamAsync(
$stream,
ExpectedVersion::EMPTY_STREAM,
ExpectedVersion::NO_STREAM,
$testEvents
);

Expand Down Expand Up @@ -241,7 +241,7 @@ public function be_able_to_read_first_event(): void
$testEvents = TestEvent::newAmount(10);
yield $store->appendToStreamAsync(
$stream,
ExpectedVersion::EMPTY_STREAM,
ExpectedVersion::NO_STREAM,
$testEvents
);

Expand Down Expand Up @@ -272,7 +272,7 @@ public function be_able_to_read_last_event(): void
$testEvents = TestEvent::newAmount(10);
yield $store->appendToStreamAsync(
$stream,
ExpectedVersion::EMPTY_STREAM,
ExpectedVersion::NO_STREAM,
$testEvents
);

Expand Down Expand Up @@ -303,7 +303,7 @@ public function be_able_to_read_slice_from_arbitrary_position(): void
$testEvents = TestEvent::newAmount(10);
yield $store->appendToStreamAsync(
$stream,
ExpectedVersion::EMPTY_STREAM,
ExpectedVersion::NO_STREAM,
$testEvents
);

Expand Down
10 changes: 5 additions & 5 deletions tests/read_event_stream_forward_should.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function notify_using_status_code_if_stream_was_deleted(): void

$store = TestConnection::create();
yield $store->connectAsync();
yield $store->deleteStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, true);
yield $store->deleteStreamAsync($stream, ExpectedVersion::NO_STREAM, true);

$read = yield $store->readStreamEventsForwardAsync(
$stream,
Expand Down Expand Up @@ -164,7 +164,7 @@ public function return_empty_slice_when_called_on_non_existing_range(): void
$testEvents = TestEvent::newAmount(10);
yield $store->appendToStreamAsync(
$stream,
ExpectedVersion::EMPTY_STREAM,
ExpectedVersion::NO_STREAM,
$testEvents
);

Expand Down Expand Up @@ -195,7 +195,7 @@ public function return_partial_slice_if_no_enough_events_in_stream(): void
$testEvents = TestEvent::newAmount(10);
yield $store->appendToStreamAsync(
$stream,
ExpectedVersion::EMPTY_STREAM,
ExpectedVersion::NO_STREAM,
$testEvents
);

Expand Down Expand Up @@ -247,7 +247,7 @@ public function return_events_in_same_order_as_written(): void
$testEvents = TestEvent::newAmount(10);
yield $store->appendToStreamAsync(
$stream,
ExpectedVersion::EMPTY_STREAM,
ExpectedVersion::NO_STREAM,
$testEvents
);

Expand Down Expand Up @@ -285,7 +285,7 @@ public function be_able_to_read_slice_from_arbitrary_position(): void
$testEvents = TestEvent::newAmount(10);
yield $store->appendToStreamAsync(
$stream,
ExpectedVersion::EMPTY_STREAM,
ExpectedVersion::NO_STREAM,
$testEvents
);

Expand Down
4 changes: 2 additions & 2 deletions tests/read_stream_events_with_unresolved_linkto.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ protected function when(): Generator

yield $this->conn->appendToStreamAsync(
$this->stream,
ExpectedVersion::EMPTY_STREAM,
ExpectedVersion::NO_STREAM,
$this->testEvents
);

yield $this->conn->appendToStreamAsync(
$this->links,
ExpectedVersion::EMPTY_STREAM,
ExpectedVersion::NO_STREAM,
[new EventData(null, SystemEventTypes::LINK_TO, false, '0@read_stream_events_with_unresolved_linkto')]
);

Expand Down
6 changes: 3 additions & 3 deletions tests/subscribe_should.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function be_able_to_subscribe_to_non_existing_stream_and_then_catch_new_e
$this->eventAppearedResolver($appeared)
);

yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::newTestEvent()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::NO_STREAM, [TestEvent::newTestEvent()]);

try {
$result = yield timeout($appeared->promise(), self::TIMEOUT);
Expand Down Expand Up @@ -97,7 +97,7 @@ public function allow_multiple_subscriptions_to_same_stream(): void
$this->eventAppearedResolver($appeared2)
);

$connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::newTestEvent()]);
$connection->appendToStreamAsync($stream, ExpectedVersion::NO_STREAM, [TestEvent::newTestEvent()]);

try {
$result = yield timeout($appeared1->promise(), self::TIMEOUT);
Expand Down Expand Up @@ -181,7 +181,7 @@ public function catch_deleted_events_as_well(): void
$this->eventAppearedResolver($appeared)
);

yield $connection->deleteStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, true);
yield $connection->deleteStreamAsync($stream, ExpectedVersion::NO_STREAM, true);

try {
$result = yield timeout($appeared->promise(), self::TIMEOUT);
Expand Down
4 changes: 2 additions & 2 deletions tests/subscribe_to_all_should.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function allow_multiple_subscriptions(): void

$create = $store->appendToStreamAsync(
$stream,
ExpectedVersion::EMPTY_STREAM,
ExpectedVersion::NO_STREAM,
[TestEvent::newTestEvent()]
);

Expand Down Expand Up @@ -135,7 +135,7 @@ public function catch_deleted_events_as_well(): void
$this->droppedWithCountdown($dropped)
);

$delete = $store->deleteStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, true);
$delete = $store->deleteStreamAsync($stream, ExpectedVersion::NO_STREAM, true);

try {
yield Promise\timeout($delete, self::TIMEOUT);
Expand Down
4 changes: 2 additions & 2 deletions tests/subscribe_to_stream_catching_up_should.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function be_able_to_subscribe_to_non_existing_stream_and_then_catch_event

yield $this->conn->appendToStreamAsync(
$stream,
ExpectedVersion::EMPTY_STREAM,
ExpectedVersion::NO_STREAM,
[TestEvent::newTestEvent()]
);

Expand Down Expand Up @@ -183,7 +183,7 @@ public function allow_multiple_subscriptions_to_same_stream(): void

yield $this->conn->appendToStreamAsync(
$stream,
ExpectedVersion::EMPTY_STREAM,
ExpectedVersion::NO_STREAM,
[TestEvent::newTestEvent()]
);

Expand Down
10 changes: 5 additions & 5 deletions tests/transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,11 @@ public function should_fail_to_commit_if_started_with_correct_ver_but_committing

$transaction = yield $this->conn->startTransactionAsync(
$stream,
ExpectedVersion::EMPTY_STREAM
ExpectedVersion::NO_STREAM
);
\assert($transaction instanceof EventStoreTransaction);

yield $this->conn->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::newTestEvent()]);
yield $this->conn->appendToStreamAsync($stream, ExpectedVersion::NO_STREAM, [TestEvent::newTestEvent()]);

yield $transaction->writeAsync([TestEvent::newTestEvent()]);

Expand All @@ -305,7 +305,7 @@ public function should_not_fail_to_commit_if_started_with_wrong_ver_but_committi
);
\assert($transaction instanceof EventStoreTransaction);

yield $this->conn->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::newTestEvent()]);
yield $this->conn->appendToStreamAsync($stream, ExpectedVersion::NO_STREAM, [TestEvent::newTestEvent()]);

yield $transaction->writeAsync([TestEvent::newTestEvent()]);

Expand All @@ -327,13 +327,13 @@ public function should_fail_to_commit_if_started_with_correct_ver_but_on_commit_

$transaction = yield $this->conn->startTransactionAsync(
$stream,
ExpectedVersion::EMPTY_STREAM
ExpectedVersion::NO_STREAM
);
\assert($transaction instanceof EventStoreTransaction);

yield $transaction->writeAsync([TestEvent::newTestEvent()]);

yield $this->conn->deleteStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, true);
yield $this->conn->deleteStreamAsync($stream, ExpectedVersion::NO_STREAM, true);

$this->expectException(StreamDeleted::class);

Expand Down

0 comments on commit 1ce899d

Please sign in to comment.