@@ -8,7 +8,8 @@ class ClientTest extends TestCase
88{
99 public function testPingSucceedsWhenServerIsReachable (): void
1010 {
11- $ container = new Container ();
11+ $ imageVersion = $ this ->getImageVersionFromDockerfile ();
12+ $ container = new Container ()->withImageTag ($ imageVersion );
1213 $ container ->start ();
1314 try {
1415 $ client = $ container ->getClient ();
@@ -21,7 +22,8 @@ public function testPingSucceedsWhenServerIsReachable(): void
2122
2223 public function testPingFailsWhenServerIsUnreachable (): void
2324 {
24- $ container = new Container ();
25+ $ imageVersion = $ this ->getImageVersionFromDockerfile ();
26+ $ container = new Container ()->withImageTag ($ imageVersion );
2527 $ container ->start ();
2628 try {
2729 $ port = $ container ->getMappedPort ();
@@ -33,4 +35,50 @@ public function testPingFailsWhenServerIsUnreachable(): void
3335 $ container ->stop ();
3436 }
3537 }
38+
39+ public function testVerifyApiTokenDoesNotThrowAnErrorIfTheTokenIsValid (): void
40+ {
41+ $ imageVersion = $ this ->getImageVersionFromDockerfile ();
42+ $ container = new Container ()->withImageTag ($ imageVersion );
43+ $ container ->start ();
44+ try {
45+ $ client = $ container ->getClient ();
46+ $ client ->verifyApiToken ();
47+ $ this ->expectNotToPerformAssertions ();
48+ } finally {
49+ $ container ->stop ();
50+ }
51+ }
52+
53+ public function testVerifyApiTokenThrowsAnErrorIfTheTokenIsInvalid (): void
54+ {
55+ $ imageVersion = $ this ->getImageVersionFromDockerfile ();
56+ $ container = new Container ()->withImageTag ($ imageVersion );
57+ $ container ->start ();
58+ try {
59+ $ baseUrl = $ container ->getBaseUrl ();
60+ $ apiToken = $ container ->getApiToken () . '-invalid ' ;
61+ $ client = new Client ($ baseUrl , $ apiToken );
62+ $ this ->expectException (Throwable::class);
63+ $ client ->verifyApiToken ();
64+ } finally {
65+ $ container ->stop ();
66+ }
67+ }
68+
69+ private function getImageVersionFromDockerfile (): string
70+ {
71+ $ dockerfile = __DIR__ . '/../docker/Dockerfile ' ;
72+
73+ if (!file_exists ($ dockerfile )) {
74+ throw new \RuntimeException ('Dockerfile not found at ' . $ dockerfile );
75+ }
76+
77+ $ content = file_get_contents ($ dockerfile );
78+ if (!preg_match ('/^FROM\s+thenativeweb\/eventsourcingdb:(.+)$/m ' , $ content , $ matches )) {
79+ throw new \RuntimeException ('Failed to extract image version from Dockerfile ' );
80+ }
81+
82+ return trim ($ matches [1 ]);
83+ }
3684}
0 commit comments