Skip to content

Commit fb18eb1

Browse files
committed
minor #202 Use $this for test assertion calls (chr-hertel)
This PR was merged into the main branch. Discussion ---------- Use `$this` for test assertion calls | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | no | Issues | | License | MIT Streamlining `$this->assert*` instead of `self::assert*` in test cases based on `symfony/symfony`. Commits ------- 679e964 Use $this for test assertion calls
2 parents 5a813e9 + 679e964 commit fb18eb1

File tree

109 files changed

+751
-750
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+751
-750
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
'header_comment' => [
3939
'header' => implode('', $fileHeaderParts),
4040
],
41+
'php_unit_test_case_static_method_calls' => ['call_type' => 'this'],
4142
])
4243
->setRiskyAllowed(true)
4344
->setFinder(

demo/tests/Blog/LoaderTest.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@ public function load(): void
3333
$loader = new FeedLoader($client);
3434
$posts = $loader->load();
3535

36-
self::assertCount(10, $posts);
37-
38-
self::assertSame('A Week of Symfony #936 (2-8 December 2024)', $posts[0]->title);
39-
self::assertSame('https://symfony.com/blog/a-week-of-symfony-936-2-8-december-2024?utm_source=Symfony%20Blog%20Feed&utm_medium=feed', $posts[0]->link);
40-
self::assertStringContainsString('This week, Symfony celebrated the SymfonyCon 2024 Vienna conference with great success.', $posts[0]->description);
41-
self::assertStringContainsString('Select a track for a guided path through 100+ video tutorial courses about Symfony', $posts[0]->content);
42-
self::assertSame('Javier Eguiluz', $posts[0]->author);
43-
self::assertEquals(new \DateTimeImmutable('8.12.2024 09:39:00 +0100'), $posts[0]->date);
44-
45-
self::assertSame('A Week of Symfony #935 (25 November - 1 December 2024)', $posts[1]->title);
46-
self::assertSame('Symfony 7.2 curated new features', $posts[2]->title);
47-
self::assertSame('Symfony 7.2.0 released', $posts[3]->title);
48-
self::assertSame('Symfony 5.4.49 released', $posts[4]->title);
49-
self::assertSame('SymfonyCon Vienna 2024: See you next week!', $posts[5]->title);
50-
self::assertSame('New in Symfony 7.2: Misc. Improvements (Part 2)', $posts[6]->title);
51-
self::assertSame('Symfony 7.1.9 released', $posts[7]->title);
52-
self::assertSame('Symfony 6.4.16 released', $posts[8]->title);
53-
self::assertSame('Symfony 5.4.48 released', $posts[9]->title);
36+
$this->assertCount(10, $posts);
37+
38+
$this->assertSame('A Week of Symfony #936 (2-8 December 2024)', $posts[0]->title);
39+
$this->assertSame('https://symfony.com/blog/a-week-of-symfony-936-2-8-december-2024?utm_source=Symfony%20Blog%20Feed&utm_medium=feed', $posts[0]->link);
40+
$this->assertStringContainsString('This week, Symfony celebrated the SymfonyCon 2024 Vienna conference with great success.', $posts[0]->description);
41+
$this->assertStringContainsString('Select a track for a guided path through 100+ video tutorial courses about Symfony', $posts[0]->content);
42+
$this->assertSame('Javier Eguiluz', $posts[0]->author);
43+
$this->assertEquals(new \DateTimeImmutable('8.12.2024 09:39:00 +0100'), $posts[0]->date);
44+
45+
$this->assertSame('A Week of Symfony #935 (25 November - 1 December 2024)', $posts[1]->title);
46+
$this->assertSame('Symfony 7.2 curated new features', $posts[2]->title);
47+
$this->assertSame('Symfony 7.2.0 released', $posts[3]->title);
48+
$this->assertSame('Symfony 5.4.49 released', $posts[4]->title);
49+
$this->assertSame('SymfonyCon Vienna 2024: See you next week!', $posts[5]->title);
50+
$this->assertSame('New in Symfony 7.2: Misc. Improvements (Part 2)', $posts[6]->title);
51+
$this->assertSame('Symfony 7.1.9 released', $posts[7]->title);
52+
$this->assertSame('Symfony 6.4.16 released', $posts[8]->title);
53+
$this->assertSame('Symfony 5.4.48 released', $posts[9]->title);
5454
}
5555
}

demo/tests/Blog/PostTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function postToString(): void
4040
This is a test post.
4141
TEXT;
4242

43-
self::assertSame($expected, $post->toString());
43+
$this->assertSame($expected, $post->toString());
4444
}
4545

4646
#[Test]
@@ -67,6 +67,6 @@ public function postToArray(): void
6767
'date' => '2024-12-08',
6868
];
6969

70-
self::assertSame($expected, $post->toArray());
70+
$this->assertSame($expected, $post->toArray());
7171
}
7272
}

src/agent/tests/InputProcessor/ModelOverrideInputProcessorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function processInputWithValidModelOption(): void
4343
$processor = new ModelOverrideInputProcessor();
4444
$processor->processInput($input);
4545

46-
self::assertSame($claude, $input->model);
46+
$this->assertSame($claude, $input->model);
4747
}
4848

4949
#[Test]
@@ -55,7 +55,7 @@ public function processInputWithoutModelOption(): void
5555
$processor = new ModelOverrideInputProcessor();
5656
$processor->processInput($input);
5757

58-
self::assertSame($gpt, $input->model);
58+
$this->assertSame($gpt, $input->model);
5959
}
6060

6161
#[Test]

src/agent/tests/InputProcessor/SystemPromptInputProcessorTest.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ public function processInputAddsSystemMessageWhenNoneExists(): void
5353
$processor->processInput($input);
5454

5555
$messages = $input->messages->getMessages();
56-
self::assertCount(2, $messages);
57-
self::assertInstanceOf(SystemMessage::class, $messages[0]);
58-
self::assertInstanceOf(UserMessage::class, $messages[1]);
59-
self::assertSame('This is a system prompt', $messages[0]->content);
56+
$this->assertCount(2, $messages);
57+
$this->assertInstanceOf(SystemMessage::class, $messages[0]);
58+
$this->assertInstanceOf(UserMessage::class, $messages[1]);
59+
$this->assertSame('This is a system prompt', $messages[0]->content);
6060
}
6161

6262
#[Test]
@@ -72,10 +72,10 @@ public function processInputDoesNotAddSystemMessageWhenOneExists(): void
7272
$processor->processInput($input);
7373

7474
$messages = $input->messages->getMessages();
75-
self::assertCount(2, $messages);
76-
self::assertInstanceOf(SystemMessage::class, $messages[0]);
77-
self::assertInstanceOf(UserMessage::class, $messages[1]);
78-
self::assertSame('This is already a system prompt', $messages[0]->content);
75+
$this->assertCount(2, $messages);
76+
$this->assertInstanceOf(SystemMessage::class, $messages[0]);
77+
$this->assertInstanceOf(UserMessage::class, $messages[1]);
78+
$this->assertSame('This is already a system prompt', $messages[0]->content);
7979
}
8080

8181
#[Test]
@@ -100,10 +100,10 @@ public function execute(ToolCall $toolCall): mixed
100100
$processor->processInput($input);
101101

102102
$messages = $input->messages->getMessages();
103-
self::assertCount(2, $messages);
104-
self::assertInstanceOf(SystemMessage::class, $messages[0]);
105-
self::assertInstanceOf(UserMessage::class, $messages[1]);
106-
self::assertSame('This is a system prompt', $messages[0]->content);
103+
$this->assertCount(2, $messages);
104+
$this->assertInstanceOf(SystemMessage::class, $messages[0]);
105+
$this->assertInstanceOf(UserMessage::class, $messages[1]);
106+
$this->assertSame('This is a system prompt', $messages[0]->content);
107107
}
108108

109109
#[Test]
@@ -139,10 +139,10 @@ public function execute(ToolCall $toolCall): mixed
139139
$processor->processInput($input);
140140

141141
$messages = $input->messages->getMessages();
142-
self::assertCount(2, $messages);
143-
self::assertInstanceOf(SystemMessage::class, $messages[0]);
144-
self::assertInstanceOf(UserMessage::class, $messages[1]);
145-
self::assertSame(<<<PROMPT
142+
$this->assertCount(2, $messages);
143+
$this->assertInstanceOf(SystemMessage::class, $messages[0]);
144+
$this->assertInstanceOf(UserMessage::class, $messages[1]);
145+
$this->assertSame(<<<PROMPT
146146
This is a system prompt
147147
148148
# Available tools
@@ -180,10 +180,10 @@ public function execute(ToolCall $toolCall): mixed
180180
$processor->processInput($input);
181181

182182
$messages = $input->messages->getMessages();
183-
self::assertCount(2, $messages);
184-
self::assertInstanceOf(SystemMessage::class, $messages[0]);
185-
self::assertInstanceOf(UserMessage::class, $messages[1]);
186-
self::assertSame(<<<PROMPT
183+
$this->assertCount(2, $messages);
184+
$this->assertInstanceOf(SystemMessage::class, $messages[0]);
185+
$this->assertInstanceOf(UserMessage::class, $messages[1]);
186+
$this->assertSame(<<<PROMPT
187187
My dynamic system prompt.
188188
189189
# Available tools

src/agent/tests/Memory/EmbeddingProviderTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ public function itIsDoingNothingWithEmptyMessageBag(): void
5353

5454
$embeddingProvider = new EmbeddingProvider(
5555
$platform,
56-
self::createStub(Model::class),
56+
$this->createStub(Model::class),
5757
$vectorStore,
5858
);
5959

6060
$embeddingProvider->loadMemory(new Input(
61-
self::createStub(Model::class),
61+
$this->createStub(Model::class),
6262
new MessageBag(),
6363
[],
6464
));
@@ -75,12 +75,12 @@ public function itIsDoingNothingWithoutUserMessageInBag(): void
7575

7676
$embeddingProvider = new EmbeddingProvider(
7777
$platform,
78-
self::createStub(Model::class),
78+
$this->createStub(Model::class),
7979
$vectorStore,
8080
);
8181

8282
$embeddingProvider->loadMemory(new Input(
83-
self::createStub(Model::class),
83+
$this->createStub(Model::class),
8484
new MessageBag(Message::forSystem('This is a system message')),
8585
[],
8686
));
@@ -97,12 +97,12 @@ public function itIsDoingNothingWhenUserMessageHasNoTextContent(): void
9797

9898
$embeddingProvider = new EmbeddingProvider(
9999
$platform,
100-
self::createStub(Model::class),
100+
$this->createStub(Model::class),
101101
$vectorStore,
102102
);
103103

104104
$embeddingProvider->loadMemory(new Input(
105-
self::createStub(Model::class),
105+
$this->createStub(Model::class),
106106
new MessageBag(Message::ofUser(new ImageUrl('foo.jpg'))),
107107
[],
108108
));
@@ -114,7 +114,7 @@ public function itIsNotCreatingMemoryWhenNoVectorsFound(): void
114114
$vectorResult = new VectorResult($vector = new Vector([0.1, 0.2], 2));
115115
$resultPromise = new ResultPromise(
116116
static fn () => $vectorResult,
117-
self::createStub(RawResultInterface::class),
117+
$this->createStub(RawResultInterface::class),
118118
);
119119

120120
$platform = $this->createMock(PlatformInterface::class);
@@ -130,17 +130,17 @@ public function itIsNotCreatingMemoryWhenNoVectorsFound(): void
130130

131131
$embeddingProvider = new EmbeddingProvider(
132132
$platform,
133-
self::createStub(Model::class),
133+
$this->createStub(Model::class),
134134
$vectorStore,
135135
);
136136

137137
$memory = $embeddingProvider->loadMemory(new Input(
138-
self::createStub(Model::class),
138+
$this->createStub(Model::class),
139139
new MessageBag(Message::ofUser(new Text('Have we talked about the weather?'))),
140140
[],
141141
));
142142

143-
self::assertCount(0, $memory);
143+
$this->assertCount(0, $memory);
144144
}
145145

146146
#[Test]
@@ -149,7 +149,7 @@ public function itIsCreatingMemoryWithFoundVectors(): void
149149
$vectorResult = new VectorResult($vector = new Vector([0.1, 0.2], 2));
150150
$resultPromise = new ResultPromise(
151151
static fn () => $vectorResult,
152-
self::createStub(RawResultInterface::class),
152+
$this->createStub(RawResultInterface::class),
153153
);
154154

155155
$platform = $this->createMock(PlatformInterface::class);
@@ -168,18 +168,18 @@ public function itIsCreatingMemoryWithFoundVectors(): void
168168

169169
$embeddingProvider = new EmbeddingProvider(
170170
$platform,
171-
self::createStub(Model::class),
171+
$this->createStub(Model::class),
172172
$vectorStore,
173173
);
174174

175175
$memory = $embeddingProvider->loadMemory(new Input(
176-
self::createStub(Model::class),
176+
$this->createStub(Model::class),
177177
new MessageBag(Message::ofUser(new Text('Have we talked about the weather?'))),
178178
[],
179179
));
180180

181-
self::assertCount(1, $memory);
182-
self::assertSame(
181+
$this->assertCount(1, $memory);
182+
$this->assertSame(
183183
<<<MARKDOWN
184184
## Dynamic memories fitting user message
185185

src/agent/tests/Memory/MemoryInputProcessorTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,29 @@ final class MemoryInputProcessorTest extends TestCase
3838
public function itIsDoingNothingOnInactiveMemory(): void
3939
{
4040
$memoryProvider = $this->createMock(MemoryProviderInterface::class);
41-
$memoryProvider->expects($this->never())->method(self::anything());
41+
$memoryProvider->expects($this->never())->method($this->anything());
4242

4343
$memoryInputProcessor = new MemoryInputProcessor($memoryProvider);
4444
$memoryInputProcessor->processInput($input = new Input(
45-
self::createStub(Model::class),
45+
$this->createStub(Model::class),
4646
new MessageBag(),
4747
['use_memory' => false]
4848
));
4949

50-
self::assertArrayNotHasKey('use_memory', $input->getOptions());
50+
$this->assertArrayNotHasKey('use_memory', $input->getOptions());
5151
}
5252

5353
#[Test]
5454
public function itIsDoingNothingWhenThereAreNoProviders(): void
5555
{
5656
$memoryInputProcessor = new MemoryInputProcessor();
5757
$memoryInputProcessor->processInput($input = new Input(
58-
self::createStub(Model::class),
58+
$this->createStub(Model::class),
5959
new MessageBag(),
6060
['use_memory' => true]
6161
));
6262

63-
self::assertArrayNotHasKey('use_memory', $input->getOptions());
63+
$this->assertArrayNotHasKey('use_memory', $input->getOptions());
6464
}
6565

6666
#[Test]
@@ -82,13 +82,13 @@ public function itIsAddingMemoryToSystemPrompt(): void
8282
);
8383

8484
$memoryInputProcessor->processInput($input = new Input(
85-
self::createStub(Model::class),
85+
$this->createStub(Model::class),
8686
new MessageBag(Message::forSystem('You are a helpful and kind assistant.')),
8787
[]
8888
));
8989

90-
self::assertArrayNotHasKey('use_memory', $input->getOptions());
91-
self::assertSame(
90+
$this->assertArrayNotHasKey('use_memory', $input->getOptions());
91+
$this->assertSame(
9292
<<<MARKDOWN
9393
You are a helpful and kind assistant.
9494
@@ -115,13 +115,13 @@ public function itIsAddingMemoryToSystemPromptEvenItIsEmpty(): void
115115
$memoryInputProcessor = new MemoryInputProcessor($firstMemoryProvider);
116116

117117
$memoryInputProcessor->processInput($input = new Input(
118-
self::createStub(Model::class),
118+
$this->createStub(Model::class),
119119
new MessageBag(),
120120
[]
121121
));
122122

123-
self::assertArrayNotHasKey('use_memory', $input->getOptions());
124-
self::assertSame(
123+
$this->assertArrayNotHasKey('use_memory', $input->getOptions());
124+
$this->assertSame(
125125
<<<MARKDOWN
126126
# Conversation Memory
127127
This is the memory I have found for this conversation. The memory has more weight to answer user input,
@@ -146,13 +146,13 @@ public function itIsAddingMultipleMemoryFromSingleProviderToSystemPrompt(): void
146146
$memoryInputProcessor = new MemoryInputProcessor($firstMemoryProvider);
147147

148148
$memoryInputProcessor->processInput($input = new Input(
149-
self::createStub(Model::class),
149+
$this->createStub(Model::class),
150150
new MessageBag(),
151151
[]
152152
));
153153

154-
self::assertArrayNotHasKey('use_memory', $input->getOptions());
155-
self::assertSame(
154+
$this->assertArrayNotHasKey('use_memory', $input->getOptions());
155+
$this->assertSame(
156156
<<<MARKDOWN
157157
# Conversation Memory
158158
This is the memory I have found for this conversation. The memory has more weight to answer user input,
@@ -178,12 +178,12 @@ public function itIsNotAddingAnythingIfMemoryWasEmpty(): void
178178
$memoryInputProcessor = new MemoryInputProcessor($firstMemoryProvider);
179179

180180
$memoryInputProcessor->processInput($input = new Input(
181-
self::createStub(Model::class),
181+
$this->createStub(Model::class),
182182
new MessageBag(),
183183
[]
184184
));
185185

186-
self::assertArrayNotHasKey('use_memory', $input->getOptions());
187-
self::assertNull($input->messages->getSystemMessage()?->content);
186+
$this->assertArrayNotHasKey('use_memory', $input->getOptions());
187+
$this->assertNull($input->messages->getSystemMessage()?->content);
188188
}
189189
}

0 commit comments

Comments
 (0)