Skip to content

Commit 1bf9ca5

Browse files
author
Mohamed Khaled
committed
Fix tokenCount references in test files after rebase
Remove all tokenCount constructor parameters and getTokenCount() method calls from test files to match upstream Candidate DTO changes. Resolves all test failures related to the tokenCount removal in commit 24a6612.
1 parent c44fe96 commit 1bf9ca5

File tree

4 files changed

+888
-112
lines changed

4 files changed

+888
-112
lines changed

tests/unit/Operations/DTO/GenerativeAiOperationTest.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,10 @@ public function testJsonSchemaForSucceededState(): void
247247
);
248248

249249
// Required fields
250-
$this->assertEquals([GenerativeAiOperation::KEY_ID, GenerativeAiOperation::KEY_STATE, GenerativeAiOperation::KEY_RESULT], $succeededSchema['required']);
250+
$this->assertEquals(
251+
[GenerativeAiOperation::KEY_ID, GenerativeAiOperation::KEY_STATE, GenerativeAiOperation::KEY_RESULT],
252+
$succeededSchema['required']
253+
);
251254
}
252255

253256
/**
@@ -275,7 +278,10 @@ public function testJsonSchemaForNonSucceededStates(): void
275278
$this->assertContains(OperationStateEnum::canceled()->value, $stateEnum);
276279

277280
// Required fields
278-
$this->assertEquals([GenerativeAiOperation::KEY_ID, GenerativeAiOperation::KEY_STATE], $otherStatesSchema['required']);
281+
$this->assertEquals(
282+
[GenerativeAiOperation::KEY_ID, GenerativeAiOperation::KEY_STATE],
283+
$otherStatesSchema['required']
284+
);
279285
}
280286

281287
/**
@@ -343,7 +349,10 @@ public function testToArraySucceededState(): void
343349

344350
$json = $this->assertToArrayReturnsArray($operation);
345351

346-
$this->assertArrayHasKeys($json, [GenerativeAiOperation::KEY_ID, GenerativeAiOperation::KEY_STATE, GenerativeAiOperation::KEY_RESULT]);
352+
$this->assertArrayHasKeys(
353+
$json,
354+
[GenerativeAiOperation::KEY_ID, GenerativeAiOperation::KEY_STATE, GenerativeAiOperation::KEY_RESULT]
355+
);
347356
$this->assertEquals('op_success_456', $json[GenerativeAiOperation::KEY_ID]);
348357
$this->assertEquals(OperationStateEnum::succeeded()->value, $json[GenerativeAiOperation::KEY_STATE]);
349358
$this->assertIsArray($json[GenerativeAiOperation::KEY_RESULT]);
@@ -386,10 +395,14 @@ public function testFromArraySucceededState(): void
386395
[
387396
Candidate::KEY_MESSAGE => [
388397
Message::KEY_ROLE => MessageRoleEnum::model()->value,
389-
Message::KEY_PARTS => [[MessagePart::KEY_TYPE => 'text', MessagePart::KEY_TEXT => 'Response text']]
398+
Message::KEY_PARTS => [
399+
[
400+
MessagePart::KEY_TYPE => 'text',
401+
MessagePart::KEY_TEXT => 'Response text'
402+
]
403+
]
390404
],
391405
Candidate::KEY_FINISH_REASON => FinishReasonEnum::stop()->value,
392-
Candidate::KEY_TOKEN_COUNT => 30
393406
]
394407
],
395408
GenerativeAiResult::KEY_TOKEN_USAGE => [

tests/unit/Results/DTO/CandidateTest.php

Lines changed: 26 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ public function testCreateWithBasicProperties(): void
3939
$candidate = new Candidate(
4040
$message,
4141
FinishReasonEnum::stop(),
42-
25
4342
);
4443

4544
$this->assertSame($message, $candidate->getMessage());
4645
$this->assertEquals(FinishReasonEnum::stop(), $candidate->getFinishReason());
47-
$this->assertEquals(25, $candidate->getTokenCount());
4846
}
4947

5048
/**
@@ -58,7 +56,7 @@ public function testWithDifferentFinishReasons(FinishReasonEnum $finishReason):
5856
{
5957
$message = new ModelMessage([new MessagePart('Response')]);
6058

61-
$candidate = new Candidate($message, $finishReason, 10);
59+
$candidate = new Candidate($message, $finishReason);
6260

6361
$this->assertEquals($finishReason, $candidate->getFinishReason());
6462
}
@@ -103,13 +101,11 @@ public function testWithComplexMessage(): void
103101

104102
$candidate = new Candidate(
105103
$message,
106-
FinishReasonEnum::toolCalls(),
107-
150
104+
FinishReasonEnum::toolCalls()
108105
);
109106

110107
$this->assertCount(6, $candidate->getMessage()->getParts());
111108
$this->assertTrue($candidate->getFinishReason()->isToolCalls());
112-
$this->assertEquals(150, $candidate->getTokenCount());
113109
}
114110

115111
/**
@@ -119,7 +115,11 @@ public function testWithComplexMessage(): void
119115
*/
120116
public function testWithMessageContainingFiles(): void
121117
{
122-
$file = new File('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQI12P4DwABAQEAG7buVgAAAABJRU5ErkJggg==', 'image/png');
118+
$base64Data = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQI12P4DwABAQEAG7buVgAAAABJRU5ErkJggg==';
119+
$file = new File(
120+
'data:image/png;base64,' . $base64Data,
121+
'image/png'
122+
);
123123

124124
$message = new ModelMessage([
125125
new MessagePart('I\'ve generated the requested image:'),
@@ -130,7 +130,6 @@ public function testWithMessageContainingFiles(): void
130130
$candidate = new Candidate(
131131
$message,
132132
FinishReasonEnum::stop(),
133-
85
134133
);
135134

136135
$parts = $candidate->getMessage()->getParts();
@@ -139,42 +138,6 @@ public function testWithMessageContainingFiles(): void
139138
$this->assertEquals('The image shows a flowchart of the process.', $parts[2]->getText());
140139
}
141140

142-
/**
143-
* Tests candidate with different token counts.
144-
*
145-
* @dataProvider tokenCountProvider
146-
* @param int $tokenCount
147-
* @return void
148-
*/
149-
public function testWithDifferentTokenCounts(int $tokenCount): void
150-
{
151-
$message = new ModelMessage([new MessagePart('Response')]);
152-
153-
$candidate = new Candidate(
154-
$message,
155-
FinishReasonEnum::stop(),
156-
$tokenCount
157-
);
158-
159-
$this->assertEquals($tokenCount, $candidate->getTokenCount());
160-
}
161-
162-
/**
163-
* Provides different token counts.
164-
*
165-
* @return array
166-
*/
167-
public function tokenCountProvider(): array
168-
{
169-
return [
170-
'zero' => [0],
171-
'small' => [10],
172-
'medium' => [500],
173-
'large' => [4000],
174-
'very_large' => [100000],
175-
];
176-
}
177-
178141
/**
179142
* Tests candidate rejects non-model message.
180143
*
@@ -191,8 +154,7 @@ public function testRejectsNonModelMessage(): void
191154

192155
new Candidate(
193156
$userMessage,
194-
FinishReasonEnum::stop(),
195-
10
157+
FinishReasonEnum::stop()
196158
);
197159
}
198160

@@ -213,8 +175,7 @@ public function testRejectsMessageWithDifferentRole(): void
213175

214176
new Candidate(
215177
$message,
216-
FinishReasonEnum::stop(),
217-
10
178+
FinishReasonEnum::stop()
218179
);
219180
}
220181

@@ -234,7 +195,6 @@ public function testJsonSchema(): void
234195
$this->assertArrayHasKey('properties', $schema);
235196
$this->assertArrayHasKey(Candidate::KEY_MESSAGE, $schema['properties']);
236197
$this->assertArrayHasKey(Candidate::KEY_FINISH_REASON, $schema['properties']);
237-
$this->assertArrayHasKey(Candidate::KEY_TOKEN_COUNT, $schema['properties']);
238198

239199
// Check finishReason property
240200
$finishReasonSchema = $schema['properties'][Candidate::KEY_FINISH_REASON];
@@ -246,13 +206,9 @@ public function testJsonSchema(): void
246206
$this->assertContains('tool_calls', $finishReasonSchema['enum']);
247207
$this->assertContains('error', $finishReasonSchema['enum']);
248208

249-
// Check tokenCount property
250-
$tokenCountSchema = $schema['properties'][Candidate::KEY_TOKEN_COUNT];
251-
$this->assertEquals('integer', $tokenCountSchema['type']);
252-
253209
// Check required fields
254210
$this->assertArrayHasKey('required', $schema);
255-
$this->assertEquals([Candidate::KEY_MESSAGE, Candidate::KEY_FINISH_REASON, Candidate::KEY_TOKEN_COUNT], $schema['required']);
211+
$this->assertEquals([Candidate::KEY_MESSAGE, Candidate::KEY_FINISH_REASON], $schema['required']);
256212
}
257213

258214
/**
@@ -266,12 +222,10 @@ public function testWithEmptyMessageParts(): void
266222

267223
$candidate = new Candidate(
268224
$message,
269-
FinishReasonEnum::stop(),
270-
0
225+
FinishReasonEnum::stop()
271226
);
272227

273228
$this->assertCount(0, $candidate->getMessage()->getParts());
274-
$this->assertEquals(0, $candidate->getTokenCount());
275229
}
276230

277231
/**
@@ -287,12 +241,10 @@ public function testWithMaxLengthFinishReason(): void
287241

288242
$candidate = new Candidate(
289243
$message,
290-
FinishReasonEnum::length(),
291-
4096
244+
FinishReasonEnum::length()
292245
);
293246

294247
$this->assertTrue($candidate->getFinishReason()->isLength());
295-
$this->assertEquals(4096, $candidate->getTokenCount());
296248
}
297249

298250
/**
@@ -308,8 +260,7 @@ public function testWithContentFilterFinishReason(): void
308260

309261
$candidate = new Candidate(
310262
$message,
311-
FinishReasonEnum::contentFilter(),
312-
8
263+
FinishReasonEnum::contentFilter()
313264
);
314265

315266
$this->assertTrue($candidate->getFinishReason()->isContentFilter());
@@ -328,8 +279,7 @@ public function testWithErrorFinishReason(): void
328279

329280
$candidate = new Candidate(
330281
$message,
331-
FinishReasonEnum::error(),
332-
9
282+
FinishReasonEnum::error()
333283
);
334284

335285
$this->assertTrue($candidate->getFinishReason()->isError());
@@ -349,16 +299,14 @@ public function testToArray(): void
349299

350300
$candidate = new Candidate(
351301
$message,
352-
FinishReasonEnum::stop(),
353-
45
302+
FinishReasonEnum::stop()
354303
);
355304

356305
$json = $this->assertToArrayReturnsArray($candidate);
357306

358-
$this->assertArrayHasKeys($json, [Candidate::KEY_MESSAGE, Candidate::KEY_FINISH_REASON, Candidate::KEY_TOKEN_COUNT]);
307+
$this->assertArrayHasKeys($json, [Candidate::KEY_MESSAGE, Candidate::KEY_FINISH_REASON]);
359308
$this->assertIsArray($json[Candidate::KEY_MESSAGE]);
360309
$this->assertEquals(FinishReasonEnum::stop()->value, $json[Candidate::KEY_FINISH_REASON]);
361-
$this->assertEquals(45, $json[Candidate::KEY_TOKEN_COUNT]);
362310
}
363311

364312
/**
@@ -372,19 +320,23 @@ public function testFromArray(): void
372320
Candidate::KEY_MESSAGE => [
373321
Message::KEY_ROLE => MessageRoleEnum::model()->value,
374322
Message::KEY_PARTS => [
375-
[MessagePart::KEY_TYPE => MessagePartTypeEnum::text()->value, MessagePart::KEY_TEXT => 'Response text 1'],
376-
[MessagePart::KEY_TYPE => MessagePartTypeEnum::text()->value, MessagePart::KEY_TEXT => 'Response text 2']
323+
[
324+
MessagePart::KEY_TYPE => MessagePartTypeEnum::text()->value,
325+
MessagePart::KEY_TEXT => 'Response text 1'
326+
],
327+
[
328+
MessagePart::KEY_TYPE => MessagePartTypeEnum::text()->value,
329+
MessagePart::KEY_TEXT => 'Response text 2'
330+
]
377331
]
378332
],
379333
Candidate::KEY_FINISH_REASON => FinishReasonEnum::stop()->value,
380-
Candidate::KEY_TOKEN_COUNT => 75
381334
];
382335

383336
$candidate = Candidate::fromArray($json);
384337

385338
$this->assertInstanceOf(Candidate::class, $candidate);
386339
$this->assertEquals(FinishReasonEnum::stop(), $candidate->getFinishReason());
387-
$this->assertEquals(75, $candidate->getTokenCount());
388340
$this->assertCount(2, $candidate->getMessage()->getParts());
389341
$this->assertEquals('Response text 1', $candidate->getMessage()->getParts()[0]->getText());
390342
$this->assertEquals('Response text 2', $candidate->getMessage()->getParts()[1]->getText());
@@ -403,12 +355,10 @@ public function testArrayRoundTrip(): void
403355
new MessagePart('Generated response'),
404356
new MessagePart(new FunctionCall('call_123', 'search', ['q' => 'test']))
405357
]),
406-
FinishReasonEnum::toolCalls(),
407-
120
358+
FinishReasonEnum::toolCalls()
408359
),
409360
function ($original, $restored) {
410361
$this->assertEquals($original->getFinishReason()->value, $restored->getFinishReason()->value);
411-
$this->assertEquals($original->getTokenCount(), $restored->getTokenCount());
412362
$this->assertCount(
413363
count($original->getMessage()->getParts()),
414364
$restored->getMessage()->getParts()
@@ -434,8 +384,7 @@ public function testImplementsWithArrayTransformationInterface(): void
434384
{
435385
$candidate = new Candidate(
436386
new ModelMessage([new MessagePart('test')]),
437-
FinishReasonEnum::stop(),
438-
10
387+
FinishReasonEnum::stop()
439388
);
440389
$this->assertImplementsArrayTransformation($candidate);
441390
}

0 commit comments

Comments
 (0)