Skip to content

Commit f6bbd36

Browse files
committed
test: add input immutability tests for OpenApiSchemaConverter
Verify that convert() does not mutate the caller's input array, ensuring the in-place optimization is safely encapsulated behind the value-passed public API boundary.
1 parent 2766914 commit f6bbd36

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

tests/Unit/OpenApiSchemaConverterTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,60 @@ public function v31_read_only_write_only_preserved(): void
308308
$this->assertTrue($result['readOnly']);
309309
$this->assertFalse($result['writeOnly']);
310310
}
311+
312+
// ========================================
313+
// Input immutability tests
314+
// ========================================
315+
316+
#[Test]
317+
public function convert_does_not_mutate_input_schema(): void
318+
{
319+
$schema = [
320+
'type' => 'object',
321+
'nullable' => true,
322+
'example' => 'test',
323+
'properties' => [
324+
'name' => [
325+
'type' => 'string',
326+
'nullable' => true,
327+
'example' => 'John',
328+
],
329+
'tags' => [
330+
'type' => 'array',
331+
'items' => [
332+
'type' => 'string',
333+
'deprecated' => true,
334+
],
335+
],
336+
],
337+
];
338+
$original = $schema;
339+
340+
OpenApiSchemaConverter::convert($schema, OpenApiVersion::V3_0);
341+
342+
$this->assertSame($original, $schema);
343+
}
344+
345+
#[Test]
346+
public function convert_does_not_mutate_input_schema_v31(): void
347+
{
348+
$schema = [
349+
'type' => 'object',
350+
'prefixItems' => [
351+
['type' => 'string'],
352+
],
353+
'examples' => [['key' => 'value']],
354+
'properties' => [
355+
'data' => [
356+
'type' => 'object',
357+
'$dynamicRef' => '#meta',
358+
],
359+
],
360+
];
361+
$original = $schema;
362+
363+
OpenApiSchemaConverter::convert($schema, OpenApiVersion::V3_1);
364+
365+
$this->assertSame($original, $schema);
366+
}
311367
}

0 commit comments

Comments
 (0)