Skip to content

Commit 1e430fe

Browse files
committed
refactor: cover psr7, psr18, valinor telemetry bridges with mago
1 parent e1828e8 commit 1e430fe

5 files changed

Lines changed: 50 additions & 25 deletions

File tree

Justfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ analyze-mago *args:
8181
src/bridge/monolog/http \
8282
src/bridge/monolog/telemetry \
8383
src/bridge/phpunit/postgresql \
84-
src/bridge/phpunit/telemetry
84+
src/bridge/phpunit/telemetry \
85+
src/bridge/postgresql/valinor \
86+
src/bridge/psr18/telemetry \
87+
src/bridge/psr7/telemetry
8588

8689
# Auto-fix code style (Mago format + lint --fix) and GitHub Actions findings (zizmor --fix).
8790
fix:

src/bridge/postgresql/valinor/tests/Flow/PostgreSql/Bridge/Valinor/Tests/Unit/ValinorBuilderMapperTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\Framework\TestCase;
1616

1717
use function Flow\PostgreSql\DSL\type_mapper;
18+
use function Flow\Types\DSL\type_instance_of;
1819
use function Flow\Types\DSL\type_integer;
1920
use function Flow\Types\DSL\type_string;
2021
use function Flow\Types\DSL\type_structure;
@@ -36,13 +37,11 @@ public function test_composes_with_type_mapper_to_decode_jsonb_into_nested_objec
3637
new ValinorBuilderMapper(new MapperBuilder(), UserWithAddress::class),
3738
);
3839

39-
$result = $mapper->map([
40+
$result = type_instance_of(UserWithAddress::class)->assert($mapper->map([
4041
'id' => 1,
4142
'name' => 'Jane',
4243
'address' => '{"street":"Main 1","city":"Warsaw"}',
43-
], MapperContextMother::any());
44-
45-
static::assertInstanceOf(UserWithAddress::class, $result);
44+
], MapperContextMother::any()));
4645
static::assertInstanceOf(Address::class, $result->address);
4746
static::assertSame('Main 1', $result->address->street);
4847
static::assertSame('Warsaw', $result->address->city);

src/bridge/postgresql/valinor/tests/Flow/PostgreSql/Bridge/Valinor/Tests/Unit/ValinorTreeMapperTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use function Flow\PostgreSql\DSL\type_mapper;
2121
use function Flow\Types\DSL\type_datetime;
22+
use function Flow\Types\DSL\type_instance_of;
2223
use function Flow\Types\DSL\type_integer;
2324
use function Flow\Types\DSL\type_string;
2425
use function Flow\Types\DSL\type_structure;
@@ -52,12 +53,11 @@ public function test_composes_with_type_mapper_for_datetime_columns(): void
5253
new ValinorTreeMapper((new MapperBuilder())->mapper(), WithDateTime::class),
5354
);
5455

55-
$result = $mapper->map([
56+
$result = type_instance_of(WithDateTime::class)->assert($mapper->map([
5657
'id' => 7,
5758
'createdAt' => '2024-03-15 14:30:00',
58-
], MapperContextMother::any());
59+
], MapperContextMother::any()));
5960

60-
static::assertInstanceOf(WithDateTime::class, $result);
6161
static::assertSame(7, $result->id);
6262
static::assertSame('2024-03-15 14:30:00', $result->createdAt->format('Y-m-d H:i:s'));
6363
}
@@ -76,13 +76,11 @@ public function test_composes_with_type_mapper_to_decode_jsonb_into_nested_objec
7676
new ValinorTreeMapper((new MapperBuilder())->mapper(), UserWithAddress::class),
7777
);
7878

79-
$result = $mapper->map([
79+
$result = type_instance_of(UserWithAddress::class)->assert($mapper->map([
8080
'id' => 1,
8181
'name' => 'Jane',
8282
'address' => '{"street":"Main 1","city":"Warsaw"}',
83-
], MapperContextMother::any());
84-
85-
static::assertInstanceOf(UserWithAddress::class, $result);
83+
], MapperContextMother::any()));
8684
static::assertInstanceOf(Address::class, $result->address);
8785
static::assertSame('Main 1', $result->address->street);
8886
static::assertSame('Warsaw', $result->address->city);

src/bridge/psr18/telemetry/tests/Flow/Bridge/Psr18/Telemetry/Tests/Integration/PSR18TraceableClientIntegrationTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,13 @@ public function test_real_http_request_creates_span(): void
5454
static::assertSame(8080, $attributes['server.port']);
5555
static::assertSame(200, $attributes['http.response.status_code']);
5656

57-
static::assertNotNull($span->status());
58-
static::assertTrue($span->status()->isOk());
57+
$status = $span->status();
58+
59+
if ($status === null) {
60+
static::fail('Expected span to have status');
61+
}
62+
63+
static::assertTrue($status->isOk());
5964
}
6065

6166
private function createTelemetry(MemorySpanProcessor $spanProcessor): Telemetry

src/bridge/psr18/telemetry/tests/Flow/Bridge/Psr18/Telemetry/Tests/Unit/PSR18TraceableClientTest.php

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,14 @@ public function test_exception_is_recorded_and_rethrown(): void
5757
static::assertSame(RuntimeException::class, $eventAttributes['exception.type']);
5858
static::assertSame('Connection failed', $eventAttributes['exception.message']);
5959

60-
static::assertNotNull($span->status());
61-
static::assertTrue($span->status()->isError());
62-
static::assertSame('Connection failed', $span->status()->description);
60+
$status = $span->status();
61+
62+
if ($status === null) {
63+
static::fail('Expected span to have status');
64+
}
65+
66+
static::assertTrue($status->isError());
67+
static::assertSame('Connection failed', $status->description);
6368
}
6469
}
6570

@@ -80,9 +85,14 @@ public function test_request_with_4xx_status_creates_error_span(): void
8085
static::assertCount(1, $spans);
8186
$span = $spans[0];
8287

83-
static::assertNotNull($span->status());
84-
static::assertTrue($span->status()->isError());
85-
static::assertSame('HTTP 404', $span->status()->description);
88+
$status = $span->status();
89+
90+
if ($status === null) {
91+
static::fail('Expected span to have status');
92+
}
93+
94+
static::assertTrue($status->isError());
95+
static::assertSame('HTTP 404', $status->description);
8696
static::assertSame(404, $span->attributes()['http.response.status_code']);
8797
}
8898

@@ -103,9 +113,14 @@ public function test_request_with_5xx_status_creates_error_span(): void
103113
static::assertCount(1, $spans);
104114
$span = $spans[0];
105115

106-
static::assertNotNull($span->status());
107-
static::assertTrue($span->status()->isError());
108-
static::assertSame('HTTP 500', $span->status()->description);
116+
$status = $span->status();
117+
118+
if ($status === null) {
119+
static::fail('Expected span to have status');
120+
}
121+
122+
static::assertTrue($status->isError());
123+
static::assertSame('HTTP 500', $status->description);
109124
static::assertSame(500, $span->attributes()['http.response.status_code']);
110125
}
111126

@@ -173,8 +188,13 @@ public function test_successful_request_creates_span_with_ok_status(): void
173188
$span = $spans[0];
174189

175190
static::assertSame('GET api.example.com', $span->name());
176-
static::assertNotNull($span->status());
177-
static::assertTrue($span->status()->isOk());
191+
$status = $span->status();
192+
193+
if ($status === null) {
194+
static::fail('Expected span to have status');
195+
}
196+
197+
static::assertTrue($status->isOk());
178198
}
179199

180200
private function createTelemetry(MemorySpanProcessor $spanProcessor): Telemetry

0 commit comments

Comments
 (0)