Skip to content

Commit 519c06c

Browse files
authored
refactor: making more test method calls static with rector (#294)
1 parent b0ee187 commit 519c06c

20 files changed

+85
-87
lines changed

tests/Bridge/HuggingFace/ModelClientTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function testSupportsWithNonHuggingFaceModel(): void
3737
{
3838
$httpClient = new MockHttpClient();
3939
$modelClient = new ModelClient($httpClient, 'test-provider', 'test-api-key');
40-
$model = $this->createMock(BaseModel::class);
40+
$model = self::createMock(BaseModel::class);
4141

4242
self::assertFalse($modelClient->supports($model, 'test-input'));
4343
}
@@ -48,8 +48,8 @@ public function testRequestWithUnsupportedInputType(): void
4848
$modelClient = new ModelClient($httpClient, 'test-provider', 'test-api-key');
4949
$model = new Model('test-model');
5050

51-
$this->expectException(\InvalidArgumentException::class);
52-
$this->expectExceptionMessage('Unsupported input type: stdClass');
51+
self::expectException(\InvalidArgumentException::class);
52+
self::expectExceptionMessage('Unsupported input type: stdClass');
5353

5454
$modelClient->request($model, new \stdClass());
5555
}
@@ -58,9 +58,9 @@ public function testRequestWithNonHuggingFaceModel(): void
5858
{
5959
$httpClient = new MockHttpClient();
6060
$modelClient = new ModelClient($httpClient, 'test-provider', 'test-api-key');
61-
$model = $this->createMock(BaseModel::class);
61+
$model = self::createMock(BaseModel::class);
6262

63-
$this->expectException(\InvalidArgumentException::class);
63+
self::expectException(\InvalidArgumentException::class);
6464

6565
$modelClient->request($model, 'test input');
6666
}

tests/Bridge/OpenAI/DallE/Base64ImageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public function itCreatesBase64Image(): void
2626
#[Test]
2727
public function itThrowsExceptionWhenBase64ImageIsEmpty(): void
2828
{
29-
$this->expectException(\InvalidArgumentException::class);
30-
$this->expectExceptionMessage('The base64 encoded image generated must be given.');
29+
self::expectException(\InvalidArgumentException::class);
30+
self::expectExceptionMessage('The base64 encoded image generated must be given.');
3131

3232
new Base64Image('');
3333
}

tests/Bridge/OpenAI/DallE/UrlImageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public function itCreatesUrlImage(): void
2525
#[Test]
2626
public function itThrowsExceptionWhenUrlIsEmpty(): void
2727
{
28-
$this->expectException(\InvalidArgumentException::class);
29-
$this->expectExceptionMessage('The image url must be given.');
28+
self::expectException(\InvalidArgumentException::class);
29+
self::expectExceptionMessage('The image url must be given.');
3030

3131
new UrlImage('');
3232
}

tests/Bridge/OpenAI/GPT/ResponseConverterTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ResponseConverterTest extends TestCase
3131
public function testConvertTextResponse(): void
3232
{
3333
$converter = new ResponseConverter();
34-
$httpResponse = $this->createMock(ResponseInterface::class);
34+
$httpResponse = self::createMock(ResponseInterface::class);
3535
$httpResponse->method('toArray')->willReturn([
3636
'choices' => [
3737
[
@@ -53,7 +53,7 @@ public function testConvertTextResponse(): void
5353
public function testConvertToolCallResponse(): void
5454
{
5555
$converter = new ResponseConverter();
56-
$httpResponse = $this->createMock(ResponseInterface::class);
56+
$httpResponse = self::createMock(ResponseInterface::class);
5757
$httpResponse->method('toArray')->willReturn([
5858
'choices' => [
5959
[
@@ -89,7 +89,7 @@ public function testConvertToolCallResponse(): void
8989
public function testConvertMultipleChoices(): void
9090
{
9191
$converter = new ResponseConverter();
92-
$httpResponse = $this->createMock(ResponseInterface::class);
92+
$httpResponse = self::createMock(ResponseInterface::class);
9393
$httpResponse->method('toArray')->willReturn([
9494
'choices' => [
9595
[
@@ -121,7 +121,7 @@ public function testConvertMultipleChoices(): void
121121
public function testContentFilterException(): void
122122
{
123123
$converter = new ResponseConverter();
124-
$httpResponse = $this->createMock(ResponseInterface::class);
124+
$httpResponse = self::createMock(ResponseInterface::class);
125125

126126
$httpResponse->expects($this->exactly(2))
127127
->method('toArray')
@@ -143,28 +143,28 @@ public function getResponse(): ResponseInterface
143143
];
144144
});
145145

146-
$this->expectException(ContentFilterException::class);
147-
$this->expectExceptionMessage('Content was filtered');
146+
self::expectException(ContentFilterException::class);
147+
self::expectExceptionMessage('Content was filtered');
148148

149149
$converter->convert($httpResponse);
150150
}
151151

152152
public function testThrowsExceptionWhenNoChoices(): void
153153
{
154154
$converter = new ResponseConverter();
155-
$httpResponse = $this->createMock(ResponseInterface::class);
155+
$httpResponse = self::createMock(ResponseInterface::class);
156156
$httpResponse->method('toArray')->willReturn([]);
157157

158-
$this->expectException(RuntimeException::class);
159-
$this->expectExceptionMessage('Response does not contain choices');
158+
self::expectException(RuntimeException::class);
159+
self::expectExceptionMessage('Response does not contain choices');
160160

161161
$converter->convert($httpResponse);
162162
}
163163

164164
public function testThrowsExceptionForUnsupportedFinishReason(): void
165165
{
166166
$converter = new ResponseConverter();
167-
$httpResponse = $this->createMock(ResponseInterface::class);
167+
$httpResponse = self::createMock(ResponseInterface::class);
168168
$httpResponse->method('toArray')->willReturn([
169169
'choices' => [
170170
[
@@ -177,8 +177,8 @@ public function testThrowsExceptionForUnsupportedFinishReason(): void
177177
],
178178
]);
179179

180-
$this->expectException(RuntimeException::class);
181-
$this->expectExceptionMessage('Unsupported finish reason "unsupported_reason"');
180+
self::expectException(RuntimeException::class);
181+
self::expectExceptionMessage('Unsupported finish reason "unsupported_reason"');
182182

183183
$converter->convert($httpResponse);
184184
}

tests/Chain/JsonSchema/Attribute/ToolParameterTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function validEnum(): void
2424
#[Test]
2525
public function invalidEnumContainsNonString(): void
2626
{
27-
$this->expectException(InvalidArgumentException::class);
27+
self::expectException(InvalidArgumentException::class);
2828
$enum = ['value1', 2];
2929
new With(enum: $enum);
3030
}
@@ -40,7 +40,7 @@ public function validConstString(): void
4040
#[Test]
4141
public function invalidConstEmptyString(): void
4242
{
43-
$this->expectException(InvalidArgumentException::class);
43+
self::expectException(InvalidArgumentException::class);
4444
$const = ' ';
4545
new With(const: $const);
4646
}
@@ -56,7 +56,7 @@ public function validPattern(): void
5656
#[Test]
5757
public function invalidPatternEmptyString(): void
5858
{
59-
$this->expectException(InvalidArgumentException::class);
59+
self::expectException(InvalidArgumentException::class);
6060
$pattern = ' ';
6161
new With(pattern: $pattern);
6262
}
@@ -72,7 +72,7 @@ public function validMinLength(): void
7272
#[Test]
7373
public function invalidMinLengthNegative(): void
7474
{
75-
$this->expectException(InvalidArgumentException::class);
75+
self::expectException(InvalidArgumentException::class);
7676
new With(minLength: -1);
7777
}
7878

@@ -89,7 +89,7 @@ public function validMinLengthAndMaxLength(): void
8989
#[Test]
9090
public function invalidMaxLengthLessThanMinLength(): void
9191
{
92-
$this->expectException(InvalidArgumentException::class);
92+
self::expectException(InvalidArgumentException::class);
9393
new With(minLength: 10, maxLength: 5);
9494
}
9595

@@ -104,7 +104,7 @@ public function validMinimum(): void
104104
#[Test]
105105
public function invalidMinimumNegative(): void
106106
{
107-
$this->expectException(InvalidArgumentException::class);
107+
self::expectException(InvalidArgumentException::class);
108108
new With(minimum: -1);
109109
}
110110

@@ -119,7 +119,7 @@ public function validMultipleOf(): void
119119
#[Test]
120120
public function invalidMultipleOfNegative(): void
121121
{
122-
$this->expectException(InvalidArgumentException::class);
122+
self::expectException(InvalidArgumentException::class);
123123
new With(multipleOf: -5);
124124
}
125125

@@ -136,7 +136,7 @@ public function validExclusiveMinimumAndMaximum(): void
136136
#[Test]
137137
public function invalidExclusiveMaximumLessThanExclusiveMinimum(): void
138138
{
139-
$this->expectException(InvalidArgumentException::class);
139+
self::expectException(InvalidArgumentException::class);
140140
new With(exclusiveMinimum: 10, exclusiveMaximum: 5);
141141
}
142142

@@ -153,7 +153,7 @@ public function validMinItemsAndMaxItems(): void
153153
#[Test]
154154
public function invalidMaxItemsLessThanMinItems(): void
155155
{
156-
$this->expectException(InvalidArgumentException::class);
156+
self::expectException(InvalidArgumentException::class);
157157
new With(minItems: 5, maxItems: 1);
158158
}
159159

@@ -167,7 +167,7 @@ public function validUniqueItemsTrue(): void
167167
#[Test]
168168
public function invalidUniqueItemsFalse(): void
169169
{
170-
$this->expectException(InvalidArgumentException::class);
170+
self::expectException(InvalidArgumentException::class);
171171
new With(uniqueItems: false);
172172
}
173173

@@ -184,7 +184,7 @@ public function validMinContainsAndMaxContains(): void
184184
#[Test]
185185
public function invalidMaxContainsLessThanMinContains(): void
186186
{
187-
$this->expectException(InvalidArgumentException::class);
187+
self::expectException(InvalidArgumentException::class);
188188
new With(minContains: 3, maxContains: 1);
189189
}
190190

@@ -208,7 +208,7 @@ public function validMinPropertiesAndMaxProperties(): void
208208
#[Test]
209209
public function invalidMaxPropertiesLessThanMinProperties(): void
210210
{
211-
$this->expectException(InvalidArgumentException::class);
211+
self::expectException(InvalidArgumentException::class);
212212
new With(minProperties: 5, maxProperties: 1);
213213
}
214214

@@ -250,7 +250,7 @@ enum: ['value1', 'value2'],
250250
#[Test]
251251
public function invalidCombination(): void
252252
{
253-
$this->expectException(InvalidArgumentException::class);
253+
self::expectException(InvalidArgumentException::class);
254254
new With(minLength: -1, maxLength: -2);
255255
}
256256
}

tests/Chain/StructuredOutput/ChainProcessorTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function processInputWithOutputStructure(): void
4141
$serializer = new Serializer([new ObjectNormalizer()], [new JsonEncoder()]);
4242
$chainProcessor = new ChainProcessor($responseFormatFactory, $serializer);
4343

44-
$llm = $this->createMock(LanguageModel::class);
44+
$llm = self::createMock(LanguageModel::class);
4545
$llm->method('supportsStructuredOutput')->willReturn(true);
4646

4747
$input = new Input($llm, new MessageBag(), ['output_structure' => 'SomeStructure']);
@@ -58,7 +58,7 @@ public function processInputWithoutOutputStructure(): void
5858
$serializer = new Serializer([new ObjectNormalizer()], [new JsonEncoder()]);
5959
$chainProcessor = new ChainProcessor($responseFormatFactory, $serializer);
6060

61-
$llm = $this->createMock(LanguageModel::class);
61+
$llm = self::createMock(LanguageModel::class);
6262
$input = new Input($llm, new MessageBag(), []);
6363

6464
$chainProcessor->processInput($input);
@@ -69,13 +69,13 @@ public function processInputWithoutOutputStructure(): void
6969
#[Test]
7070
public function processInputThrowsExceptionWhenLlmDoesNotSupportStructuredOutput(): void
7171
{
72-
$this->expectException(MissingModelSupport::class);
72+
self::expectException(MissingModelSupport::class);
7373

7474
$responseFormatFactory = new ConfigurableResponseFormatFactory();
7575
$serializer = new Serializer([new ObjectNormalizer()], [new JsonEncoder()]);
7676
$chainProcessor = new ChainProcessor($responseFormatFactory, $serializer);
7777

78-
$llm = $this->createMock(LanguageModel::class);
78+
$llm = self::createMock(LanguageModel::class);
7979
$llm->method('supportsStructuredOutput')->willReturn(false);
8080

8181
$input = new Input($llm, new MessageBag(), ['output_structure' => 'SomeStructure']);
@@ -90,7 +90,7 @@ public function processOutputWithResponseFormat(): void
9090
$serializer = new Serializer([new ObjectNormalizer()], [new JsonEncoder()]);
9191
$chainProcessor = new ChainProcessor($responseFormatFactory, $serializer);
9292

93-
$llm = $this->createMock(LanguageModel::class);
93+
$llm = self::createMock(LanguageModel::class);
9494
$llm->method('supportsStructuredOutput')->willReturn(true);
9595

9696
$options = ['output_structure' => SomeStructure::class];
@@ -112,10 +112,10 @@ public function processOutputWithResponseFormat(): void
112112
public function processOutputWithoutResponseFormat(): void
113113
{
114114
$responseFormatFactory = new ConfigurableResponseFormatFactory();
115-
$serializer = $this->createMock(SerializerInterface::class);
115+
$serializer = self::createMock(SerializerInterface::class);
116116
$chainProcessor = new ChainProcessor($responseFormatFactory, $serializer);
117117

118-
$llm = $this->createMock(LanguageModel::class);
118+
$llm = self::createMock(LanguageModel::class);
119119
$response = new TextResponse('');
120120

121121
$output = new Output($llm, $response, new MessageBag(), []);

tests/Chain/Toolbox/ChainProcessorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function processInputWithoutRegisteredToolsWillResultInNoOptionChange():
3131
$toolbox = $this->createStub(ToolboxInterface::class);
3232
$toolbox->method('getMap')->willReturn([]);
3333

34-
$llm = $this->createMock(LanguageModel::class);
34+
$llm = self::createMock(LanguageModel::class);
3535
$llm->method('supportsToolCalling')->willReturn(true);
3636

3737
$chainProcessor = new ChainProcessor($toolbox);
@@ -50,7 +50,7 @@ public function processInputWithRegisteredToolsWillResultInOptionChange(): void
5050
$tool2 = new Metadata(new ExecutionReference('ClassTool2', 'method1'), 'tool2', 'description2', null);
5151
$toolbox->method('getMap')->willReturn([$tool1, $tool2]);
5252

53-
$llm = $this->createMock(LanguageModel::class);
53+
$llm = self::createMock(LanguageModel::class);
5454
$llm->method('supportsToolCalling')->willReturn(true);
5555

5656
$chainProcessor = new ChainProcessor($toolbox);
@@ -69,7 +69,7 @@ public function processInputWithRegisteredToolsButToolOverride(): void
6969
$tool2 = new Metadata(new ExecutionReference('ClassTool2', 'method1'), 'tool2', 'description2', null);
7070
$toolbox->method('getMap')->willReturn([$tool1, $tool2]);
7171

72-
$llm = $this->createMock(LanguageModel::class);
72+
$llm = self::createMock(LanguageModel::class);
7373
$llm->method('supportsToolCalling')->willReturn(true);
7474

7575
$chainProcessor = new ChainProcessor($toolbox);
@@ -83,9 +83,9 @@ public function processInputWithRegisteredToolsButToolOverride(): void
8383
#[Test]
8484
public function processInputWithUnsupportedToolCallingWillThrowException(): void
8585
{
86-
$this->expectException(MissingModelSupport::class);
86+
self::expectException(MissingModelSupport::class);
8787

88-
$llm = $this->createMock(LanguageModel::class);
88+
$llm = self::createMock(LanguageModel::class);
8989
$llm->method('supportsToolCalling')->willReturn(false);
9090

9191
$chainProcessor = new ChainProcessor($this->createStub(ToolboxInterface::class));

tests/Chain/Toolbox/MetadataFactory/ChainFactoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ protected function setUp(): void
4242
#[Test]
4343
public function testGetMetadataNotExistingClass(): void
4444
{
45-
$this->expectException(ToolMetadataException::class);
46-
$this->expectExceptionMessage('The reference "NoClass" is not a valid tool.');
45+
self::expectException(ToolMetadataException::class);
46+
self::expectExceptionMessage('The reference "NoClass" is not a valid tool.');
4747

4848
iterator_to_array($this->factory->getMetadata('NoClass'));
4949
}
5050

5151
#[Test]
5252
public function testGetMetadataNotConfiguredClass(): void
5353
{
54-
$this->expectException(ToolConfigurationException::class);
55-
$this->expectExceptionMessage(sprintf('Method "foo" not found in tool "%s".', ToolMisconfigured::class));
54+
self::expectException(ToolConfigurationException::class);
55+
self::expectExceptionMessage(sprintf('Method "foo" not found in tool "%s".', ToolMisconfigured::class));
5656

5757
iterator_to_array($this->factory->getMetadata(ToolMisconfigured::class));
5858
}

tests/Chain/Toolbox/MetadataFactory/MemoryFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ final class MemoryFactoryTest extends TestCase
3030
#[Test]
3131
public function getMetadataWithoutTools(): void
3232
{
33-
$this->expectException(ToolMetadataException::class);
34-
$this->expectExceptionMessage('The reference "SomeClass" is not a valid tool.');
33+
self::expectException(ToolMetadataException::class);
34+
self::expectExceptionMessage('The reference "SomeClass" is not a valid tool.');
3535

3636
$factory = new MemoryFactory();
3737
iterator_to_array($factory->getMetadata('SomeClass')); // @phpstan-ignore-line Yes, this class does not exist

0 commit comments

Comments
 (0)