Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/coding-standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
coverage: none
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1, opcache.enable_cli=1
extensions: pdo_sqlite

- uses: ramsey/composer-install@3.1.1
with:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/deptrac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
coverage: "pcov"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
extensions: pdo_sqlite

- uses: ramsey/composer-install@3.1.1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mutation-tests-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
coverage: "pcov"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
extensions: pdo_sqlite
extensions: pdo_sqlite, pdo_pgsql

- uses: ramsey/composer-install@3.1.1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mutation-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
coverage: "pcov"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
extensions: pdo_sqlite
extensions: pdo_sqlite, pdo_pgsql

- uses: ramsey/composer-install@3.1.1
with:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
coverage: none
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1, opcache.enable_cli=1
extensions: pdo_sqlite

- uses: ramsey/composer-install@3.1.1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
coverage: "pcov"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
extensions: pdo_sqlite
extensions: pdo_sqlite, pdo_pgsql

- uses: ramsey/composer-install@3.1.1
with:
Expand Down
16 changes: 12 additions & 4 deletions src/Store/DoctrineDbalStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Patchlevel\EventSourcing\Store\Criteria\ToIndexCriterion;
use Patchlevel\EventSourcing\Store\Header\IndexHeader;
use PDO;
use Pdo\Pgsql;

use function array_fill;
use function array_filter;
Expand All @@ -49,6 +50,8 @@
use function is_string;
use function sprintf;

use const PHP_VERSION_ID;

final class DoctrineDbalStore implements Store, SubscriptionStore, DoctrineSchemaConfigurator
{
/**
Expand Down Expand Up @@ -386,10 +389,15 @@

$this->connection->executeStatement(sprintf('LISTEN "%s"', $this->config['table_name']));

/** @var PDO $nativeConnection */
$nativeConnection = $this->connection->getNativeConnection();

$nativeConnection->pgsqlGetNotify(PDO::FETCH_ASSOC, $timeoutMilliseconds);
if (PHP_VERSION_ID >= 80400) {

Check warning on line 392 in src/Store/DoctrineDbalStore.php

View workflow job for this annotation

GitHub Actions / Mutation tests on diff (locked, 8.5, ubuntu-latest)

Escaped Mutant for Mutator "GreaterThanOrEqualTo": @@ @@ $this->connection->executeStatement(sprintf('LISTEN "%s"', $this->config['table_name'])); - if (PHP_VERSION_ID >= 80400) { + if (PHP_VERSION_ID > 80400) { /** @var Pgsql $nativeConnection */ $nativeConnection = $this->connection->getNativeConnection(); $nativeConnection->getNotify(PDO::FETCH_ASSOC, $timeoutMilliseconds);
/** @var Pgsql $nativeConnection */
$nativeConnection = $this->connection->getNativeConnection();
$nativeConnection->getNotify(PDO::FETCH_ASSOC, $timeoutMilliseconds);
} else {
/** @var PDO $nativeConnection */
$nativeConnection = $this->connection->getNativeConnection();
$nativeConnection->pgsqlGetNotify(PDO::FETCH_ASSOC, $timeoutMilliseconds);
}
}

public function setupSubscription(): void
Expand Down
16 changes: 12 additions & 4 deletions src/Store/StreamDoctrineDbalStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use Patchlevel\EventSourcing\Store\Header\RecordedOnHeader;
use Patchlevel\EventSourcing\Store\Header\StreamNameHeader;
use PDO;
use Pdo\Pgsql;
use Psr\Clock\ClockInterface;
use Ramsey\Uuid\Uuid;

Expand All @@ -58,6 +59,8 @@
use function str_contains;
use function str_replace;

use const PHP_VERSION_ID;

final class StreamDoctrineDbalStore implements StreamStore, SubscriptionStore, DoctrineSchemaConfigurator
{
/**
Expand Down Expand Up @@ -465,10 +468,15 @@

$this->connection->executeStatement(sprintf('LISTEN "%s"', $this->config['table_name']));

/** @var PDO $nativeConnection */
$nativeConnection = $this->connection->getNativeConnection();

$nativeConnection->pgsqlGetNotify(PDO::FETCH_ASSOC, $timeoutMilliseconds);
if (PHP_VERSION_ID >= 80400) {

Check warning on line 471 in src/Store/StreamDoctrineDbalStore.php

View workflow job for this annotation

GitHub Actions / Mutation tests on diff (locked, 8.5, ubuntu-latest)

Escaped Mutant for Mutator "GreaterThanOrEqualTo": @@ @@ $this->connection->executeStatement(sprintf('LISTEN "%s"', $this->config['table_name'])); - if (PHP_VERSION_ID >= 80400) { + if (PHP_VERSION_ID > 80400) { /** @var Pgsql $nativeConnection */ $nativeConnection = $this->connection->getNativeConnection(); $nativeConnection->getNotify(PDO::FETCH_ASSOC, $timeoutMilliseconds);
/** @var Pgsql $nativeConnection */
$nativeConnection = $this->connection->getNativeConnection();
$nativeConnection->getNotify(PDO::FETCH_ASSOC, $timeoutMilliseconds);
} else {
/** @var PDO $nativeConnection */
$nativeConnection = $this->connection->getNativeConnection();
$nativeConnection->pgsqlGetNotify(PDO::FETCH_ASSOC, $timeoutMilliseconds);
}
}

public function setupSubscription(): void
Expand Down
33 changes: 33 additions & 0 deletions tests/Unit/Store/DoctrineDbalStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileEmailChanged;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId;
use PDO;
use Pdo\Pgsql;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhp;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -1343,7 +1344,39 @@ public function testSetupSubscriptionNotPostgres(): void
$doctrineDbalStore->setupSubscription();
}

#[RequiresPhp('>= 8.4')]
public function testWait(): void
{
$nativeConnection = $this->createMock(Pgsql::class);
$nativeConnection
->expects($this->once())
->method('getNotify')
->with(PDO::FETCH_ASSOC, 100)
->willReturn([]);

$connection = $this->createMock(Connection::class);
$connection->expects($this->once())->method('executeStatement')->with('LISTEN "eventstore"')
->willReturn(1);
$connection->expects($this->once())->method('getNativeConnection')
->willReturn($nativeConnection);

$abstractPlatform = $this->createMock(PostgreSQLPlatform::class);
$connection->expects($this->once())->method('getDatabasePlatform')->willReturn($abstractPlatform);

$eventSerializer = $this->createMock(EventSerializer::class);
$headersSerializer = $this->createMock(HeadersSerializer::class);

$doctrineDbalStore = new DoctrineDbalStore(
$connection,
$eventSerializer,
$headersSerializer,
);

$doctrineDbalStore->wait(100);
}

#[RequiresPhp('< 8.4')]
public function testWaitDeprecatedFunction(): void
{
$nativeConnection = $this->getMockBuilder(PDO::class)
->disableOriginalConstructor()
Expand Down
38 changes: 38 additions & 0 deletions tests/Unit/Store/StreamDoctrineDbalStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileEmailChanged;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId;
use PDO;
use Pdo\Pgsql;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhp;
use PHPUnit\Framework\TestCase;
use Psr\Clock\ClockInterface;
use RuntimeException;
Expand Down Expand Up @@ -1367,7 +1369,43 @@ public function testSetupSubscriptionNotPostgres(): void
$doctrineDbalStore->setupSubscription();
}

#[RequiresPhp('>= 8.4')]
public function testWait(): void
{
$nativeConnection = $this->createMock(Pgsql::class);
$nativeConnection
->expects($this->once())
->method('getNotify')
->with(PDO::FETCH_ASSOC, 100)
->willReturn([]);

$connection = $this->createMock(Connection::class);
$connection
->expects($this->once())
->method('executeStatement')
->with('LISTEN "event_store"')
->willReturn(1);
$connection
->expects($this->once())
->method('getNativeConnection')
->willReturn($nativeConnection);

$abstractPlatform = $this->createMock(PostgreSQLPlatform::class);
$connection->method('getDatabasePlatform')->willReturn($abstractPlatform);

$eventSerializer = $this->createMock(EventSerializer::class);
$headersSerializer = $this->createMock(HeadersSerializer::class);

$doctrineDbalStore = new StreamDoctrineDbalStore(
$connection,
$eventSerializer,
$headersSerializer,
);
$doctrineDbalStore->wait(100);
}

#[RequiresPhp('< 8.4')]
public function testWaitDeprecatedFunction(): void
{
$nativeConnection = $this->getMockBuilder(PDO::class)
->disableOriginalConstructor()
Expand Down
Loading