Skip to content

Commit f386256

Browse files
authored
Merge branch 'thenativeweb:main' into main
2 parents 82d7c4c + a6e2466 commit f386256

29 files changed

+182
-47
lines changed

.github/workflows/qa.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ jobs:
1414

1515
strategy:
1616
matrix:
17-
version: [ '8.2', '8.3', '8.4', 'latest' ]
17+
version: [ '8.2', '8.3', '8.4', '8.5', 'latest' ]
1818

1919
steps:
2020
- name: Clone repository
21-
uses: actions/checkout@v5
21+
uses: actions/checkout@v6
2222
- name: Use PHP
2323
uses: shivammathur/setup-php@v2
2424
with:

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ jobs:
1616

1717
steps:
1818
- name: Clone repository
19-
uses: actions/checkout@v5
19+
uses: actions/checkout@v6
2020
with:
2121
fetch-depth: '0'
2222
- name: Use PHP
2323
uses: shivammathur/setup-php@v2
2424
with:
25-
php-version: '8.4'
25+
php-version: '8.5'
2626
tools: composer
2727
- name: Install dependencies
2828
run: |

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ $writtenEvents = $client->writeEvents([
7979
]);
8080
```
8181

82+
#### Using the `isSubjectPopulated` precondition
83+
84+
If you only want to write events in case a subject (such as `/books/42`) already has at least one event, import the `IsSubjectPopulated` class, use it to create a precondition, and pass it in an array as the second argument:
85+
86+
```php
87+
use Thenativeweb\Eventsourcingdb\IsSubjectPopulated;
88+
89+
$writtenEvents = $client->writeEvents([
90+
// events
91+
], [
92+
new IsSubjectPopulated('/books/42'),
93+
]);
94+
```
95+
8296
#### Using the `isSubjectOnEventId` precondition
8397

8498
If you only want to write events in case the last event of a subject (such as `/books/42`) has a specific ID (e.g., `0`), import the `IsSubjectOnEventId` class, use it to create a precondition, and pass it in an array as the second argument:

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
"testcontainers/testcontainers": "1.0.3"
3232
},
3333
"require-dev": {
34-
"phpstan/phpstan": "2.1.31",
34+
"phpstan/phpstan": "2.1.32",
3535
"phpunit/phpunit": "11.5.21",
36-
"rector/rector": "2.2.3",
37-
"symplify/easy-coding-standard": "12.6.0"
36+
"rector/rector": "2.2.7",
37+
"symplify/easy-coding-standard": "13.0.0"
3838
},
3939
"scripts": {
4040
"analyze": [

composer.lock

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Container.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ final class Container
1818
private string $apiToken = 'secret';
1919
private ?SigningKey $signingKey = null;
2020
private ?StartedGenericContainer $container = null;
21+
private ?string $tempSigningKeyFile = null;
2122

2223
public function withImageTag(string $tag): self
2324
{
@@ -57,26 +58,25 @@ public function start(): void
5758
'--http-enabled',
5859
'--https-enabled=false',
5960
];
60-
$content = [];
6161

6262
if ($this->signingKey instanceof SigningKey) {
6363
$command[] = '--signing-key-file';
6464
$command[] = '/etc/esdb/signing-key.pem';
65+
}
66+
67+
$container = (new GenericContainer("{$this->imageName}:{$this->imageTag}"))
68+
->withExposedPorts($this->internalPort)
69+
->withCommand($command);
70+
71+
if ($this->signingKey instanceof SigningKey) {
72+
$this->tempSigningKeyFile = getcwd() . '/.esdb_signing_key_' . uniqid();
73+
file_put_contents($this->tempSigningKeyFile, $this->signingKey->privateKeyPem);
74+
chmod($this->tempSigningKeyFile, 0o644);
6575

66-
$content[] = [
67-
'content' => $this->signingKey->privateKeyPem,
68-
'target' => '/etc/esdb/signing-key.pem',
69-
'mode' => 0o777,
70-
];
76+
$container = $container->withMount($this->tempSigningKeyFile, '/etc/esdb/signing-key.pem');
7177
}
7278

73-
$container =
74-
(new GenericContainer("{$this->imageName}:{$this->imageTag}"))
75-
->withExposedPorts($this->internalPort)
76-
->withCommand($command)
77-
->withCopyContentToContainer($content)
78-
->withWait((new WaitForHttp($this->internalPort, 20000))->withPath('/api/v1/ping'))
79-
;
79+
$container = $container->withWait((new WaitForHttp($this->internalPort, 20000))->withPath('/api/v1/ping'));
8080

8181
try {
8282
$this->container = $container->start();
@@ -139,6 +139,11 @@ public function stop(): void
139139
$this->container->stop();
140140
$this->container = null;
141141
}
142+
143+
if ($this->tempSigningKeyFile !== null && file_exists($this->tempSigningKeyFile)) {
144+
unlink($this->tempSigningKeyFile);
145+
$this->tempSigningKeyFile = null;
146+
}
142147
}
143148

144149
public function getClient(): Client

src/IsSubjectPopulated.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Thenativeweb\Eventsourcingdb;
6+
7+
use JsonSerializable;
8+
9+
final readonly class IsSubjectPopulated implements JsonSerializable
10+
{
11+
public function __construct(
12+
public string $subject,
13+
) {
14+
}
15+
16+
public function jsonSerialize(): array
17+
{
18+
return [
19+
'type' => 'isSubjectPopulated',
20+
'payload' => [
21+
'subject' => $this->subject,
22+
],
23+
];
24+
}
25+
}

tests/CloudEventSignatureTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
declare(strict_types=1);
44

5+
namespace Thenativeweb\Eventsourcingdb\Tests;
6+
7+
use Exception;
58
use PHPUnit\Framework\TestCase;
9+
use RuntimeException;
610
use Thenativeweb\Eventsourcingdb\CloudEvent;
711
use Thenativeweb\Eventsourcingdb\Container;
812
use Thenativeweb\Eventsourcingdb\EventCandidate;

tests/CloudEventTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
declare(strict_types=1);
44

5+
namespace Thenativeweb\Eventsourcingdb\Tests;
6+
57
use PHPUnit\Framework\TestCase;
8+
use RuntimeException;
69
use Thenativeweb\Eventsourcingdb\CloudEvent;
710
use Thenativeweb\Eventsourcingdb\EventCandidate;
811
use Thenativeweb\Eventsourcingdb\Tests\Trait\ClientTestTrait;

tests/ObserveEventsTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
declare(strict_types=1);
44

5+
namespace Thenativeweb\Eventsourcingdb\Tests;
6+
57
use PHPUnit\Framework\TestCase;
68
use Thenativeweb\Eventsourcingdb\Bound;
79
use Thenativeweb\Eventsourcingdb\BoundType;

0 commit comments

Comments
 (0)