Skip to content

Commit 7687414

Browse files
committed
[Platform] Add more PHPStan array type annotations to bridge tests
1 parent 17e0cfa commit 7687414

File tree

8 files changed

+44
-0
lines changed

8 files changed

+44
-0
lines changed

src/platform/src/Bridge/HuggingFace/Tests/Output/ClassificationResultTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ public function testFromArrayPreservesOrder()
108108
$this->assertSame('third', $result->classifications[2]->label);
109109
}
110110

111+
/**
112+
* @param array{label: string, score: float} $classification
113+
*/
111114
#[TestDox('fromArray handles various label formats')]
112115
#[TestWith([['label' => '', 'score' => 0.5]])]
113116
#[TestWith([['label' => 'UPPERCASE', 'score' => 0.5]])]

src/platform/src/Bridge/HuggingFace/Tests/Output/QuestionAnsweringResultTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ public function testFromArray()
6868
$this->assertSame(0.87, $result->score);
6969
}
7070

71+
/**
72+
* @param array{answer: string, start: int, end: int, score: float} $data
73+
*/
7174
#[TestDox('fromArray handles various data formats')]
7275
#[TestWith([['answer' => 'Yes', 'start' => 0, 'end' => 3, 'score' => 1.0]])]
7376
#[TestWith([['answer' => 'No answer found', 'start' => -1, 'end' => -1, 'score' => 0.0]])]

src/platform/src/Bridge/HuggingFace/Tests/Output/SentenceSimilarityResultTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public function testConstructionWithEmptyArray()
4040
$this->assertCount(0, $result->similarities);
4141
}
4242

43+
/**
44+
* @param array<int, float> $similarities
45+
*/
4346
#[TestDox('Constructor accepts various similarity arrays')]
4447
#[TestWith([[0.5]])]
4548
#[TestWith([[0.0, 1.0]])]
@@ -70,6 +73,9 @@ public function testFromArray()
7073
$this->assertSame(0.23, $result->similarities[3]);
7174
}
7275

76+
/**
77+
* @param array<int, float> $data
78+
*/
7379
#[TestDox('fromArray handles various data formats')]
7480
#[TestWith([[]])] // Empty array
7581
#[TestWith([[0.999]])] // Single high similarity
@@ -90,6 +96,9 @@ public function testFromArrayWithVariousData(array $data)
9096
}
9197
}
9298

99+
/**
100+
* @param array<int, float> $similarities
101+
*/
93102
#[TestDox('Special float values are handled correctly')]
94103
#[TestWith([[0.0, 1.0, 0.5]])] // Boundary values
95104
#[TestWith([[-1.0, 2.0]])] // Outside normal range

src/platform/src/Bridge/HuggingFace/Tests/Output/TableQuestionAnsweringResultTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public function testConstructionWithAllParameters()
4747
$this->assertSame($aggregator, $result->aggregator);
4848
}
4949

50+
/**
51+
* @param array<int, array<int, int>> $coordinates
52+
* @param array<int, int|string> $cells
53+
* @param array<int, string> $aggregator
54+
*/
5055
#[TestDox('Constructor accepts various parameter combinations')]
5156
#[TestWith(['Yes', [], [], []])]
5257
#[TestWith(['No', [[0, 1]], ['A1'], ['COUNT']])]
@@ -94,6 +99,9 @@ public function testFromArrayWithAllFields()
9499
$this->assertSame(['SUM'], $result->aggregator);
95100
}
96101

102+
/**
103+
* @param array<string, mixed> $data
104+
*/
97105
#[TestDox('fromArray handles optional fields with default values')]
98106
#[TestWith([['answer' => 'Test', 'coordinates' => [[0, 0], [1, 1]]]])]
99107
#[TestWith([['answer' => 'Test', 'cells' => ['A1', 'B1']]])]
@@ -130,6 +138,9 @@ public function testFromArrayWithVariousCellTypes()
130138
$this->assertSame(['NONE'], $result->aggregator);
131139
}
132140

141+
/**
142+
* @param array<string, mixed> $data
143+
*/
133144
#[TestDox('fromArray handles various aggregator formats')]
134145
#[TestWith([['answer' => 'Test', 'aggregator' => []]])]
135146
#[TestWith([['answer' => 'Test', 'aggregator' => ['NONE']]])]

src/platform/src/Bridge/Mistral/Tests/TokenOutputProcessorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ public function testItHandlesMissingUsageFields()
127127
$this->assertNull($tokenUsage->totalTokens);
128128
}
129129

130+
/**
131+
* @param array<string, mixed> $data
132+
*/
130133
private function createRawResponse(array $data = []): RawHttpResult
131134
{
132135
$rawResponse = $this->createStub(ResponseInterface::class);

src/platform/src/Bridge/Ollama/Tests/Contract/AssistantMessageNormalizerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public function testGetSupportedTypes()
4646
$this->assertSame([AssistantMessage::class => true], $this->normalizer->getSupportedTypes(null));
4747
}
4848

49+
/**
50+
* @param array<string, mixed> $expectedOutput
51+
*/
4952
#[DataProvider('normalizeDataProvider')]
5053
public function testNormalize(AssistantMessage $message, array $expectedOutput)
5154
{

src/platform/src/Bridge/Ollama/Tests/OllamaResultConverterTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,19 @@ public function testConvertThinkingStreamingResponse()
217217
$this->assertArrayHasKey('total_duration', $chunks->current()->raw);
218218
}
219219

220+
/**
221+
* @return iterable<array<string, mixed>>
222+
*/
220223
private function generateConvertStreamingStream(): iterable
221224
{
222225
yield ['model' => 'deepseek-r1:latest', 'created_at' => '2025-10-29T17:15:49.631700779Z', 'message' => ['role' => 'assistant', 'content' => 'Hello'], 'done' => false];
223226
yield ['model' => 'deepseek-r1:latest', 'created_at' => '2025-10-29T17:15:49.905924913Z', 'message' => ['role' => 'assistant', 'content' => ' world!'], 'done' => true,
224227
'done_reason' => 'stop', 'total_duration' => 100, 'load_duration' => 10, 'prompt_eval_count' => 42, 'prompt_eval_duration' => 30, 'eval_count' => 17, 'eval_duration' => 60];
225228
}
226229

230+
/**
231+
* @return iterable<array<string, mixed>>
232+
*/
227233
private function generateConvertThinkingStreamingStream(): iterable
228234
{
229235
yield ['model' => 'deepseek-r1:latest', 'created_at' => '2025-10-29T17:15:49.631700779Z', 'message' => ['role' => 'assistant', 'content' => '', 'thinking' => 'Thinking'], 'done' => false];

src/platform/src/Bridge/OpenAi/Tests/Contract/DocumentNormalizerTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public function testGetSupportedTypes()
4141
$this->assertSame($expected, $normalizer->getSupportedTypes(null));
4242
}
4343

44+
/**
45+
* @param array<string, mixed> $expected
46+
*/
4447
#[DataProvider('normalizeDataProvider')]
4548
public function testNormalize(Document $document, array $expected)
4649
{
@@ -51,6 +54,9 @@ public function testNormalize(Document $document, array $expected)
5154
$this->assertEquals($expected, $normalized);
5255
}
5356

57+
/**
58+
* @return iterable<array{0: Document, 1: array<string, mixed>}>
59+
*/
5460
public static function normalizeDataProvider(): iterable
5561
{
5662
yield 'document from file' => [

0 commit comments

Comments
 (0)