Skip to content

Commit ed4b97e

Browse files
committed
minor #261 Use $this over self:: in tests (OskarStark)
This PR was merged into the main branch. Discussion ---------- Use `$this` over `self::` in tests | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | no | Issues | -- | License | MIT Commits ------- 9235cf9 Use `$this` over `self::` in tests
2 parents f28aa2c + 9235cf9 commit ed4b97e

26 files changed

+103
-103
lines changed

src/agent/tests/InputProcessor/ModelOverrideInputProcessorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public function testProcessInputWithoutModelOption()
5757

5858
public function testProcessInputWithInvalidModelOption()
5959
{
60-
self::expectException(InvalidArgumentException::class);
61-
self::expectExceptionMessage('Option "model" must be an instance of "Symfony\AI\Platform\Model".');
60+
$this->expectException(InvalidArgumentException::class);
61+
$this->expectExceptionMessage('Option "model" must be an instance of "Symfony\AI\Platform\Model".');
6262

6363
$gpt = new Gpt();
6464
$model = new MessageBag();

src/agent/tests/StructuredOutput/AgentProcessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testProcessInputWithoutOutputStructure()
6565

6666
public function testProcessInputThrowsExceptionWhenLlmDoesNotSupportStructuredOutput()
6767
{
68-
self::expectException(MissingModelSupportException::class);
68+
$this->expectException(MissingModelSupportException::class);
6969

7070
$processor = new AgentProcessor(new ConfigurableResponseFormatFactory());
7171

src/agent/tests/Toolbox/AgentProcessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function testProcessInputWithRegisteredToolsButToolOverride()
9090

9191
public function testProcessInputWithUnsupportedToolCallingWillThrowException()
9292
{
93-
self::expectException(MissingModelSupportException::class);
93+
$this->expectException(MissingModelSupportException::class);
9494

9595
$model = new Model('gpt-3');
9696
$processor = new AgentProcessor($this->createStub(ToolboxInterface::class));

src/agent/tests/Toolbox/MetadataFactory/ChainFactoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ protected function setUp(): void
4747

4848
public function testTestGetMetadataNotExistingClass()
4949
{
50-
self::expectException(ToolException::class);
51-
self::expectExceptionMessage('The reference "NoClass" is not a valid tool.');
50+
$this->expectException(ToolException::class);
51+
$this->expectExceptionMessage('The reference "NoClass" is not a valid tool.');
5252

5353
iterator_to_array($this->factory->getTool('NoClass'));
5454
}
5555

5656
public function testTestGetMetadataNotConfiguredClass()
5757
{
58-
self::expectException(ToolConfigurationException::class);
59-
self::expectExceptionMessage(\sprintf('Method "foo" not found in tool "%s".', ToolMisconfigured::class));
58+
$this->expectException(ToolConfigurationException::class);
59+
$this->expectExceptionMessage(\sprintf('Method "foo" not found in tool "%s".', ToolMisconfigured::class));
6060

6161
iterator_to_array($this->factory->getTool(ToolMisconfigured::class));
6262
}

src/agent/tests/Toolbox/MetadataFactory/MemoryFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ final class MemoryFactoryTest extends TestCase
3535
{
3636
public function testGetMetadataWithoutTools()
3737
{
38-
self::expectException(ToolException::class);
39-
self::expectExceptionMessage('The reference "SomeClass" is not a valid tool.');
38+
$this->expectException(ToolException::class);
39+
$this->expectExceptionMessage('The reference "SomeClass" is not a valid tool.');
4040

4141
$factory = new MemoryToolFactory();
4242
iterator_to_array($factory->getTool('SomeClass')); // @phpstan-ignore-line Yes, this class does not exist

src/agent/tests/Toolbox/MetadataFactory/ReflectionFactoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ protected function setUp(): void
4545

4646
public function testInvalidReferenceNonExistingClass()
4747
{
48-
self::expectException(ToolException::class);
49-
self::expectExceptionMessage('The reference "invalid" is not a valid tool.');
48+
$this->expectException(ToolException::class);
49+
$this->expectExceptionMessage('The reference "invalid" is not a valid tool.');
5050

5151
iterator_to_array($this->factory->getTool('invalid')); // @phpstan-ignore-line Yes, this class does not exist
5252
}
5353

5454
public function testWithoutAttribute()
5555
{
56-
self::expectException(ToolException::class);
57-
self::expectExceptionMessage(\sprintf('The class "%s" is not a tool, please add %s attribute.', ToolWrong::class, AsTool::class));
56+
$this->expectException(ToolException::class);
57+
$this->expectExceptionMessage(\sprintf('The class "%s" is not a tool, please add %s attribute.', ToolWrong::class, AsTool::class));
5858

5959
iterator_to_array($this->factory->getTool(ToolWrong::class));
6060
}

src/agent/tests/Toolbox/ToolboxTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,16 @@ public function testGetTools()
153153

154154
public function testExecuteWithUnknownTool()
155155
{
156-
self::expectException(ToolNotFoundException::class);
157-
self::expectExceptionMessage('Tool not found for call: foo_bar_baz');
156+
$this->expectException(ToolNotFoundException::class);
157+
$this->expectExceptionMessage('Tool not found for call: foo_bar_baz');
158158

159159
$this->toolbox->execute(new ToolCall('call_1234', 'foo_bar_baz'));
160160
}
161161

162162
public function testExecuteWithMisconfiguredTool()
163163
{
164-
self::expectException(ToolConfigurationException::class);
165-
self::expectExceptionMessage('Method "foo" not found in tool "Symfony\AI\Fixtures\Tool\ToolMisconfigured".');
164+
$this->expectException(ToolConfigurationException::class);
165+
$this->expectExceptionMessage('Method "foo" not found in tool "Symfony\AI\Fixtures\Tool\ToolMisconfigured".');
166166

167167
$toolbox = new Toolbox([new ToolMisconfigured()], new ReflectionToolFactory());
168168

@@ -171,8 +171,8 @@ public function testExecuteWithMisconfiguredTool()
171171

172172
public function testExecuteWithException()
173173
{
174-
self::expectException(ToolExecutionException::class);
175-
self::expectExceptionMessage('Execution of tool "tool_exception" failed with error: Tool error.');
174+
$this->expectException(ToolExecutionException::class);
175+
$this->expectExceptionMessage('Execution of tool "tool_exception" failed with error: Tool error.');
176176

177177
$this->toolbox->execute(new ToolCall('call_1234', 'tool_exception'));
178178
}

src/ai-bundle/tests/Security/IsGrantedToolAttributeListenerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public function testItWillThrowWhenNotGranted(object $tool, Tool $metadata)
5656
{
5757
$this->authChecker->expects($this->once())->method('isGranted')->willReturn(false);
5858

59-
self::expectException(AccessDeniedException::class);
60-
self::expectExceptionMessage(\sprintf('No access to %s tool.', $metadata->name));
59+
$this->expectException(AccessDeniedException::class);
60+
$this->expectExceptionMessage(\sprintf('No access to %s tool.', $metadata->name));
6161
$this->dispatcher->dispatch(new ToolCallArgumentsResolved($tool, $metadata, []));
6262
}
6363

src/platform/tests/Bridge/OpenAi/DallE/Base64ImageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public function testItCreatesBase64Image()
3030

3131
public function testItThrowsExceptionWhenBase64ImageIsEmpty()
3232
{
33-
self::expectException(\InvalidArgumentException::class);
34-
self::expectExceptionMessage('The base64 encoded image generated must be given.');
33+
$this->expectException(\InvalidArgumentException::class);
34+
$this->expectExceptionMessage('The base64 encoded image generated must be given.');
3535

3636
new Base64Image('');
3737
}

src/platform/tests/Bridge/OpenAi/DallE/UrlImageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public function testItCreatesUrlImage()
2929

3030
public function testItThrowsExceptionWhenUrlIsEmpty()
3131
{
32-
self::expectException(\InvalidArgumentException::class);
33-
self::expectExceptionMessage('The image url must be given.');
32+
$this->expectException(\InvalidArgumentException::class);
33+
$this->expectExceptionMessage('The image url must be given.');
3434

3535
new UrlImage('');
3636
}

0 commit comments

Comments
 (0)