Skip to content

Commit

Permalink
Merge pull request #116 from prooph/refactor_test_suite
Browse files Browse the repository at this point in the history
Refactoring tests
  • Loading branch information
prolic committed Apr 6, 2020
2 parents fae0a96 + 2b23d8f commit 5ad391a
Show file tree
Hide file tree
Showing 125 changed files with 5,437 additions and 7,168 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ cache:
- $HOME/.local

before_script:
- echo downloading EventStore 5.0.5
- wget https://eventstore.org/downloads/ubuntu/EventStore-OSS-Linux-Ubuntu-16.04-v5.0.5.tar.gz
- echo downloading EventStore 5.0.8
- wget https://eventstore.org/downloads/ubuntu/EventStore-OSS-Linux-Ubuntu-16.04-v5.0.8.tar.gz
- echo extracting event-store
- tar xf EventStore-OSS-Linux-Ubuntu-16.04-v5.0.5.tar.gz
- cd EventStore-OSS-Linux-Ubuntu-16.04-v5.0.5
- tar xf EventStore-OSS-Linux-Ubuntu-16.04-v5.0.8.tar.gz
- cd EventStore-OSS-Linux-Ubuntu-16.04-v5.0.8
- echo starting event-store
- ./run-node.sh --run-projections=all --mem-db --ext-tcp-heartbeat-interval 5000 --ext-tcp-heartbeat-timeout 1500 > /dev/null &
- cd ..
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"require-dev": {
"amphp/log": "^1.0",
"amphp/phpunit-util": "dev-alt-13",
"doctrine/instantiator": "^1.1",
"php-coveralls/php-coveralls": "^2.1",
"phpspec/prophecy": "^1.7.2",
Expand Down
2 changes: 1 addition & 1 deletion docker/unittest/phpunit/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.0/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.0/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
Expand All @@ -20,7 +20,7 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="tests/_bootstrap.php"
bootstrap="vendor/autoload.php"
failOnWarning="true"
failOnRisky="true"
>
Expand Down
39 changes: 39 additions & 0 deletions tests/EventStoreConnectionTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* This file is part of `prooph/event-store-client`.
* (c) 2018-2020 Alexander Miertsch <kontakt@codeliner.ws>
* (c) 2018-2020 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* 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\PHPUnit\AsyncTestCase;
use Amp\Promise;
use Prooph\EventStore\Async\EventStoreConnection;
use ProophTest\EventStoreClient\Helper\TestConnection;

abstract class EventStoreConnectionTestCase extends AsyncTestCase
{
protected EventStoreConnection $connection;

protected function setUpAsync(): Promise
{
$this->connection = TestConnection::create();
$this->connection->connectAsync();

return parent::setUpAsync();
}

protected function tearDownAsync(): Promise
{
$this->connection->close();

return parent::tearDownAsync();
}
}
2 changes: 2 additions & 0 deletions tests/Helper/ParallelTransactionTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public function run(Environment $environment)

yield $transaction->commitAsync();

$store->close();

return true;
}
}
9 changes: 6 additions & 3 deletions tests/Helper/StreamWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

use function Amp\call;
use Amp\Promise;
use Amp\Success;
use Generator;
use Prooph\EventStore\Async\EventStoreConnection;
use Prooph\EventStore\EventData;
use Prooph\EventStore\ExpectedVersion;
use Prooph\EventStore\WriteResult;

Expand All @@ -35,7 +35,10 @@ public function __construct(EventStoreConnection $connection, string $stream, in
$this->version = $version;
}

/** @return Promise<TailWriter> */
/**
* @param EventData[] $events
* @return Promise<TailWriter>
*/
public function append(array $events): Promise
{
return call(function () use ($events): Generator {
Expand All @@ -52,7 +55,7 @@ public function append(array $events): Promise
}
}

return new Success(new TailWriter($this->connection, $this->stream));
return new TailWriter($this->connection, $this->stream);
});
}
}
3 changes: 1 addition & 2 deletions tests/Helper/TailWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use function Amp\call;
use Amp\Promise;
use Amp\Success;
use Generator;
use Prooph\EventStore\Async\EventStoreConnection;
use Prooph\EventStore\EventData;
Expand All @@ -38,7 +37,7 @@ public function then(EventData $event, int $expectedVersion): Promise
return call(function () use ($event, $expectedVersion): Generator {
yield $this->connection->appendToStreamAsync($this->stream, $expectedVersion, [$event]);

return new Success($this);
return $this;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
namespace ProophTest\EventStoreClient\PersistentSubscriptionManagement;

use Amp\Delayed;
use Amp\PHPUnit\AsyncTestCase;
use Amp\Promise;
use Amp\Success;
use Generator;
use PHPUnit\Framework\TestCase;
use Prooph\EventStore\Async\EventAppearedOnPersistentSubscription;
use Prooph\EventStore\Async\EventStorePersistentSubscription;
use Prooph\EventStore\EndPoint;
Expand All @@ -34,9 +34,8 @@
use ProophTest\EventStoreClient\CountdownEvent;
use ProophTest\EventStoreClient\DefaultData;
use ProophTest\EventStoreClient\SpecificationWithConnection;
use Throwable;

class persistent_subscription_manager extends TestCase
class persistent_subscription_manager extends AsyncTestCase
{
use SpecificationWithConnection;

Expand All @@ -47,6 +46,8 @@ class persistent_subscription_manager extends TestCase

protected function setUp(): void
{
parent::setUp();

$this->manager = new PersistentSubscriptionsManager(
new EndPoint(
(string) \getenv('ES_HOST'),
Expand All @@ -65,14 +66,14 @@ protected function setUp(): void

protected function when(): Generator
{
yield $this->conn->createPersistentSubscriptionAsync(
yield $this->connection->createPersistentSubscriptionAsync(
$this->stream,
'existing',
$this->settings,
DefaultData::adminCredentials()
);

$this->sub = yield $this->conn->connectToPersistentSubscriptionAsync(
$this->sub = yield $this->connection->connectToPersistentSubscriptionAsync(
$this->stream,
'existing',
new class() implements EventAppearedOnPersistentSubscription {
Expand All @@ -90,7 +91,7 @@ public function __invoke(
DefaultData::adminCredentials()
);

yield $this->conn->appendToStreamAsync(
yield $this->connection->appendToStreamAsync(
$this->stream,
ExpectedVersion::ANY,
[
Expand All @@ -102,11 +103,10 @@ public function __invoke(

/**
* @test
* @throws Throwable
*/
public function can_describe_persistent_subscription(): void
public function can_describe_persistent_subscription(): Generator
{
$this->execute(function () {
yield $this->execute(function (): Generator {
$details = yield $this->manager->describe($this->stream, 'existing');
\assert($details instanceof PersistentSubscriptionDetails);

Expand All @@ -120,35 +120,32 @@ public function can_describe_persistent_subscription(): void

/**
* @test
* @throws Throwable
*/
public function cannot_describe_persistent_subscription_with_empty_stream_name(): void
public function cannot_describe_persistent_subscription_with_empty_stream_name(): Generator
{
$this->execute(function () {
yield $this->execute(function (): Generator {
$this->expectException(InvalidArgumentException::class);
yield $this->manager->describe('', 'existing');
});
}

/**
* @test
* @throws Throwable
*/
public function cannot_describe_persistent_subscription_with_empty_group_name(): void
public function cannot_describe_persistent_subscription_with_empty_group_name(): Generator
{
$this->execute(function () {
yield $this->execute(function (): Generator {
$this->expectException(InvalidArgumentException::class);
yield $this->manager->describe($this->stream, '');
});
}

/**
* @test
* @throws Throwable
*/
public function can_list_all_persistent_subscriptions(): void
public function can_list_all_persistent_subscriptions(): Generator
{
$this->execute(function () {
yield $this->execute(function (): Generator {
$list = yield $this->manager->list();

$found = false;
Expand All @@ -168,11 +165,10 @@ public function can_list_all_persistent_subscriptions(): void

/**
* @test
* @throws Throwable
*/
public function can_list_all_persistent_subscriptions_using_empty_string(): void
public function can_list_all_persistent_subscriptions_using_empty_string(): Generator
{
$this->execute(function () {
yield $this->execute(function (): Generator {
$list = yield $this->manager->list('');

$found = false;
Expand All @@ -192,11 +188,10 @@ public function can_list_all_persistent_subscriptions_using_empty_string(): void

/**
* @test
* @throws Throwable
*/
public function can_list_persistent_subscriptions_for_stream(): void
public function can_list_persistent_subscriptions_for_stream(): Generator
{
$this->execute(function () {
yield $this->execute(function (): Generator {
$list = yield $this->manager->list($this->stream);

$found = false;
Expand All @@ -217,14 +212,13 @@ public function can_list_persistent_subscriptions_for_stream(): void

/**
* @test
* @throws Throwable
*/
public function can_replay_parked_messages(): void
public function can_replay_parked_messages(): Generator
{
$this->execute(function () {
yield $this->execute(function (): Generator {
yield $this->sub->stop();

$this->sub = yield $this->conn->connectToPersistentSubscriptionAsync(
$this->sub = yield $this->connection->connectToPersistentSubscriptionAsync(
$this->stream,
'existing',
new class() implements EventAppearedOnPersistentSubscription {
Expand All @@ -248,7 +242,7 @@ public function __invoke(
DefaultData::adminCredentials()
);

yield $this->conn->appendToStreamAsync(
yield $this->connection->appendToStreamAsync(
$this->stream,
ExpectedVersion::ANY,
[
Expand All @@ -265,7 +259,7 @@ public function __invoke(

$event = new CountdownEvent(2);

yield $this->conn->connectToPersistentSubscriptionAsync(
yield $this->connection->connectToPersistentSubscriptionAsync(
$this->stream,
'existing',
new class($event) implements EventAppearedOnPersistentSubscription {
Expand Down Expand Up @@ -304,23 +298,21 @@ public function __invoke(

/**
* @test
* @throws Throwable
*/
public function cannot_replay_parked_with_empty_stream_name(): void
public function cannot_replay_parked_with_empty_stream_name(): Generator
{
$this->execute(function () {
yield $this->execute(function (): Generator {
$this->expectException(InvalidArgumentException::class);
yield $this->manager->replayParkedMessages('', 'existing');
});
}

/**
* @test
* @throws Throwable
*/
public function cannot_replay_parked_with_empty_group_name(): void
public function cannot_replay_parked_with_empty_group_name(): Generator
{
$this->execute(function () {
yield $this->execute(function (): Generator {
$this->expectException(InvalidArgumentException::class);
yield $this->manager->replayParkedMessages($this->stream, '');
});
Expand Down

0 comments on commit 5ad391a

Please sign in to comment.