Skip to content

Commit

Permalink
Merge pull request #63 from wjzijderveld/drop-unsupported
Browse files Browse the repository at this point in the history
Drop unsupported
  • Loading branch information
wjzijderveld committed Mar 29, 2024
2 parents 386d346 + 723c559 commit 8ec9f0a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 40 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/ci.yml
Expand Up @@ -17,13 +17,12 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
Expand All @@ -34,7 +33,7 @@ jobs:
- name: "Validate composer.json and composer.lock"
run: "composer validate --strict --no-interaction --ansi"
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
- name: "Run tests"
run: "make test"

Expand All @@ -43,14 +42,14 @@ jobs:
runs-on: "ubuntu-20.04"
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.1"
coverage: "none"
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
- name: "Check coding standards"
run: "make php-cs-fixer-ci"

Expand All @@ -59,13 +58,13 @@ jobs:
runs-on: "ubuntu-20.04"
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.1"
coverage: "none"
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
- name: "Run PHPStan"
run: "make phpstan"
9 changes: 5 additions & 4 deletions composer.json
Expand Up @@ -3,9 +3,9 @@
"description": "Event store implementation using doctrine/dbal",
"license": "MIT",
"require": {
"php": ">=7.2",
"broadway/broadway": "^2.3.1",
"doctrine/dbal": "^3.1"
"php": "^8.1",
"broadway/broadway": "^2.5",
"doctrine/dbal": "^3.8"
},
"authors": [
{
Expand Down Expand Up @@ -39,7 +39,8 @@
"ramsey/uuid": "^4.0",
"broadway/coding-standard": "^1.2",
"phpstan/phpstan": "@stable",
"phpspec/prophecy": "^1.15"
"phpspec/prophecy": "^1.15",
"phpspec/prophecy-phpunit": "^2.2"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Expand Up @@ -12,7 +12,7 @@ parameters:

-
message: "#^Cannot cast mixed to string\\.$#"
count: 1
count: 3
path: src/DBALEventStore.php

-
Expand Down
35 changes: 8 additions & 27 deletions src/DBALEventStore.php
Expand Up @@ -59,7 +59,7 @@ class DBALEventStore implements EventStore, EventStoreManagement
/**
* @var Statement|null
*/
private $loadStatement = null;
private $loadStatement;

/**
* @var string
Expand All @@ -82,7 +82,7 @@ public function __construct(
Serializer $metadataSerializer,
string $tableName,
bool $useBinary,
BinaryUuidConverterInterface $binaryUuidConverter = null
?BinaryUuidConverterInterface $binaryUuidConverter = null
) {
$this->connection = $connection;
$this->payloadSerializer = $payloadSerializer;
Expand All @@ -96,9 +96,6 @@ public function __construct(
}
}

/**
* {@inheritdoc}
*/
public function load($id): DomainEventStream
{
$statement = $this->prepareLoadStatement();
Expand All @@ -118,9 +115,6 @@ public function load($id): DomainEventStream
return new DomainEventStream($events);
}

/**
* {@inheritdoc}
*/
public function loadFromPlayhead($id, int $playhead): DomainEventStream
{
$statement = $this->prepareLoadStatement();
Expand All @@ -136,9 +130,6 @@ public function loadFromPlayhead($id, int $playhead): DomainEventStream
return new DomainEventStream($events);
}

/**
* {@inheritdoc}
*/
public function append($id, DomainEventStream $eventStream): void
{
// noop to ensure that an error will be thrown early if the ID
Expand Down Expand Up @@ -191,7 +182,7 @@ public function configureSchema(Schema $schema): ?\Doctrine\DBAL\Schema\Table
return $this->configureTable($schema);
}

public function configureTable(Schema $schema = null): \Doctrine\DBAL\Schema\Table
public function configureTable(?Schema $schema = null): \Doctrine\DBAL\Schema\Table
{
$schema = $schema ?: new Schema();

Expand Down Expand Up @@ -251,34 +242,24 @@ private function deserializeEvent(array $row): DomainMessage
);
}

/**
* @param mixed $id
*
* @return mixed
*/
private function convertIdentifierToStorageValue($id)
private function convertIdentifierToStorageValue(mixed $id): string
{
if ($this->useBinary) {
try {
return $this->binaryUuidConverter::fromString($id);
return $this->binaryUuidConverter::fromString((string) $id);
} catch (\Exception $e) {
throw new InvalidIdentifierException('Only valid UUIDs are allowed to by used with the binary storage mode.');
}
}

return $id;
return (string) $id;
}

/**
* @param mixed $id
*
* @return mixed
*/
private function convertStorageValueToIdentifier($id)
private function convertStorageValueToIdentifier(string $id): string
{
if ($this->useBinary) {
try {
return $this->binaryUuidConverter::fromBytes($id);
return $this->binaryUuidConverter::fromBytes((string) $id);
} catch (\Exception $e) {
throw new InvalidIdentifierException('Could not convert binary storage value to UUID.');
}
Expand Down
23 changes: 23 additions & 0 deletions test/BinaryDBALEventStoreTest.php
Expand Up @@ -21,12 +21,15 @@
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Prophecy\PhpUnit\ProphecyTrait;

/**
* @requires extension pdo_sqlite
*/
class BinaryDBALEventStoreTest extends DBALEventStoreTest
{
use ProphecyTrait;

/** @var \Doctrine\DBAL\Schema\Table */
protected $table;

Expand Down Expand Up @@ -101,4 +104,24 @@ public function it_throws_when_no_binary_uuid_converter_provided_when_using_bina
null
);
}

/**
* Overriding base test as it doesn't use the data provider andthis testcase fails on non-uuid ids.
*
* @test
*/
public function empty_set_of_events_can_be_added(): void
{
$id = (new Version4Generator())->generate();

$domainMessage = $this->createDomainMessage($id, 0);
$baseStream = new DomainEventStream([$domainMessage]);
$this->eventStore->append($id, $baseStream);
$appendedEventStream = new DomainEventStream([]);

$this->eventStore->append($id, $appendedEventStream);

$events = $this->eventStore->load($id);
$this->assertCount(1, $events);
}
}
3 changes: 3 additions & 0 deletions test/DBALEventStoreTest.php
Expand Up @@ -18,12 +18,15 @@
use Broadway\UuidGenerator\Converter\BinaryUuidConverter;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Prophecy\PhpUnit\ProphecyTrait;

/**
* @requires extension pdo_sqlite
*/
class DBALEventStoreTest extends EventStoreTest
{
use ProphecyTrait;

protected function setUp(): void
{
$connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true]);
Expand Down

0 comments on commit 8ec9f0a

Please sign in to comment.