Skip to content

Commit 83058fb

Browse files
committed
minor #192 Replace test method prefix with #[Test] attribute (OskarStark)
This PR was merged into the main branch. Discussion ---------- Replace test method prefix with `#[Test]` attribute | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | no | Issues | -- | License | MIT Updated all test files that were using the 'test' prefix convention to use the modern PHPUnit #[Test] attribute instead. This brings consistency across the codebase as the majority of tests were already using the attribute syntax. Commits ------- 4c443a8 Replace test method prefix with #[Test] attribute
2 parents c978b59 + 4c443a8 commit 83058fb

File tree

21 files changed

+158
-69
lines changed

21 files changed

+158
-69
lines changed

demo/tests/Blog/LoaderTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use App\Blog\FeedLoader;
1515
use App\Blog\Post;
1616
use PHPUnit\Framework\Attributes\CoversClass;
17+
use PHPUnit\Framework\Attributes\Test;
1718
use PHPUnit\Framework\Attributes\UsesClass;
1819
use PHPUnit\Framework\TestCase;
1920
use Symfony\Component\HttpClient\MockHttpClient;
@@ -23,7 +24,8 @@
2324
#[UsesClass(Post::class)]
2425
final class LoaderTest extends TestCase
2526
{
26-
public function testLoad(): void
27+
#[Test]
28+
public function load(): void
2729
{
2830
$response = MockResponse::fromFile(__DIR__.'/fixtures/blog.rss');
2931
$client = new MockHttpClient($response);

demo/tests/Blog/PostTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313

1414
use App\Blog\Post;
1515
use PHPUnit\Framework\Attributes\CoversClass;
16+
use PHPUnit\Framework\Attributes\Test;
1617
use PHPUnit\Framework\TestCase;
1718
use Symfony\Component\Uid\Uuid;
1819

1920
#[CoversClass(Post::class)]
2021
final class PostTest extends TestCase
2122
{
22-
public function testPostToString(): void
23+
#[Test]
24+
public function postToString(): void
2325
{
2426
$post = new Post(
2527
Uuid::v4(),
@@ -41,7 +43,8 @@ public function testPostToString(): void
4143
self::assertSame($expected, $post->toString());
4244
}
4345

44-
public function testPostToArray(): void
46+
#[Test]
47+
public function postToArray(): void
4548
{
4649
$id = Uuid::v4();
4750
$post = new Post(

demo/tests/SmokeTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\Attributes\CoversNothing;
1515
use PHPUnit\Framework\Attributes\DataProvider;
16+
use PHPUnit\Framework\Attributes\Test;
1617
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1718
use Symfony\UX\LiveComponent\Test\InteractsWithLiveComponents;
1819

@@ -21,7 +22,8 @@ final class SmokeTest extends WebTestCase
2122
{
2223
use InteractsWithLiveComponents;
2324

24-
public function testIndex(): void
25+
#[Test]
26+
public function index(): void
2527
{
2628
$client = static::createClient();
2729
$client->request('GET', '/');
@@ -31,8 +33,9 @@ public function testIndex(): void
3133
self::assertSelectorCount(5, '.card');
3234
}
3335

36+
#[Test]
3437
#[DataProvider('provideChats')]
35-
public function testChats(string $path, string $expectedHeadline): void
38+
public function chats(string $path, string $expectedHeadline): void
3639
{
3740
$client = static::createClient();
3841
$client->request('GET', $path);

src/ai-bundle/tests/Profiler/DataCollectorTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\AI\AIBundle\Tests\Profiler;
1313

1414
use PHPUnit\Framework\Attributes\CoversClass;
15+
use PHPUnit\Framework\Attributes\Test;
1516
use PHPUnit\Framework\Attributes\UsesClass;
1617
use PHPUnit\Framework\TestCase;
1718
use Symfony\AI\Agent\Toolbox\ToolboxInterface;
@@ -32,7 +33,8 @@
3233
#[UsesClass(ResultPromise::class)]
3334
class DataCollectorTest extends TestCase
3435
{
35-
public function testCollectsDataForNonStreamingResponse()
36+
#[Test]
37+
public function collectsDataForNonStreamingResponse()
3638
{
3739
$platform = $this->createMock(PlatformInterface::class);
3840
$traceablePlatform = new TraceablePlatform($platform);
@@ -51,7 +53,8 @@ public function testCollectsDataForNonStreamingResponse()
5153
$this->assertSame('Assistant response', $dataCollector->getPlatformCalls()[0]['result']);
5254
}
5355

54-
public function testCollectsDataForStreamingResponse()
56+
#[Test]
57+
public function collectsDataForStreamingResponse()
5558
{
5659
$platform = $this->createMock(PlatformInterface::class);
5760
$traceablePlatform = new TraceablePlatform($platform);

src/mcp-sdk/tests/Message/ErrorTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313

1414
use PHPUnit\Framework\Attributes\CoversClass;
1515
use PHPUnit\Framework\Attributes\Small;
16+
use PHPUnit\Framework\Attributes\Test;
1617
use PHPUnit\Framework\TestCase;
1718
use Symfony\AI\McpSdk\Message\Error;
1819

1920
#[Small]
2021
#[CoversClass(Error::class)]
2122
final class ErrorTest extends TestCase
2223
{
23-
public function testWithIntegerId(): void
24+
#[Test]
25+
public function withIntegerId(): void
2426
{
2527
$error = new Error(1, -32602, 'Another error occurred');
2628
$expected = [
@@ -35,7 +37,8 @@ public function testWithIntegerId(): void
3537
self::assertSame($expected, $error->jsonSerialize());
3638
}
3739

38-
public function testWithStringId(): void
40+
#[Test]
41+
public function withStringId(): void
3942
{
4043
$error = new Error('abc', -32602, 'Another error occurred');
4144
$expected = [

src/mcp-sdk/tests/Message/FactoryTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\Attributes\CoversClass;
1515
use PHPUnit\Framework\Attributes\Small;
16+
use PHPUnit\Framework\Attributes\Test;
1617
use PHPUnit\Framework\TestCase;
1718
use Symfony\AI\McpSdk\Exception\InvalidInputMessageException;
1819
use Symfony\AI\McpSdk\Message\Factory;
@@ -42,7 +43,8 @@ private function first(iterable $items): mixed
4243
return null;
4344
}
4445

45-
public function testCreateRequest(): void
46+
#[Test]
47+
public function createRequest(): void
4648
{
4749
$json = '{"jsonrpc": "2.0", "method": "test_method", "params": {"foo": "bar"}, "id": 123}';
4850

@@ -54,7 +56,8 @@ public function testCreateRequest(): void
5456
self::assertSame(123, $result->id);
5557
}
5658

57-
public function testCreateNotification(): void
59+
#[Test]
60+
public function createNotification(): void
5861
{
5962
$json = '{"jsonrpc": "2.0", "method": "notifications/test_event", "params": {"foo": "bar"}}';
6063

@@ -65,21 +68,24 @@ public function testCreateNotification(): void
6568
self::assertSame(['foo' => 'bar'], $result->params);
6669
}
6770

68-
public function testInvalidJson(): void
71+
#[Test]
72+
public function invalidJson(): void
6973
{
7074
$this->expectException(\JsonException::class);
7175

7276
$this->first($this->factory->create('invalid json'));
7377
}
7478

75-
public function testMissingMethod(): void
79+
#[Test]
80+
public function missingMethod(): void
7681
{
7782
$result = $this->first($this->factory->create('{"jsonrpc": "2.0", "params": {}, "id": 1}'));
7883
self::assertInstanceOf(InvalidInputMessageException::class, $result);
7984
$this->assertEquals('Invalid JSON-RPC request, missing "method".', $result->getMessage());
8085
}
8186

82-
public function testBatchMissingMethod(): void
87+
#[Test]
88+
public function batchMissingMethod(): void
8389
{
8490
$results = $this->factory->create('[{"jsonrpc": "2.0", "params": {}, "id": 1}, {"jsonrpc": "2.0", "method": "notifications/test_event", "params": {}, "id": 2}]');
8591

src/mcp-sdk/tests/Message/ResponseTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313

1414
use PHPUnit\Framework\Attributes\CoversClass;
1515
use PHPUnit\Framework\Attributes\Small;
16+
use PHPUnit\Framework\Attributes\Test;
1617
use PHPUnit\Framework\TestCase;
1718
use Symfony\AI\McpSdk\Message\Response;
1819

1920
#[Small]
2021
#[CoversClass(Response::class)]
2122
final class ResponseTest extends TestCase
2223
{
23-
public function testWithIntegerId(): void
24+
#[Test]
25+
public function withIntegerId(): void
2426
{
2527
$response = new Response(1, ['foo' => 'bar']);
2628
$expected = [
@@ -32,7 +34,8 @@ public function testWithIntegerId(): void
3234
self::assertSame($expected, $response->jsonSerialize());
3335
}
3436

35-
public function testWithStringId(): void
37+
#[Test]
38+
public function withStringId(): void
3639
{
3740
$response = new Response('abc', ['foo' => 'bar']);
3841
$expected = [

src/mcp-sdk/tests/Server/JsonRpcHandlerTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\Attributes\CoversClass;
1515
use PHPUnit\Framework\Attributes\Small;
16+
use PHPUnit\Framework\Attributes\Test;
1617
use PHPUnit\Framework\Attributes\TestDox;
1718
use PHPUnit\Framework\TestCase;
1819
use Psr\Log\NullLogger;
@@ -26,8 +27,9 @@
2627
#[CoversClass(JsonRpcHandler::class)]
2728
class JsonRpcHandlerTest extends TestCase
2829
{
30+
#[Test]
2931
#[TestDox('Make sure a single notification can be handled by multiple handlers.')]
30-
public function testHandleMultipleNotifications(): void
32+
public function handleMultipleNotifications(): void
3133
{
3234
$handlerA = $this->getMockBuilder(NotificationHandlerInterface::class)
3335
->disableOriginalConstructor()
@@ -57,8 +59,9 @@ public function testHandleMultipleNotifications(): void
5759
iterator_to_array($result);
5860
}
5961

62+
#[Test]
6063
#[TestDox('Make sure a single request can NOT be handled by multiple handlers.')]
61-
public function testHandleMultipleRequests(): void
64+
public function handleMultipleRequests(): void
6265
{
6366
$handlerA = $this->getMockBuilder(RequestHandlerInterface::class)
6467
->disableOriginalConstructor()

src/mcp-sdk/tests/Server/RequestHandler/PromptListHandlerTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\Attributes\CoversClass;
1515
use PHPUnit\Framework\Attributes\Small;
16+
use PHPUnit\Framework\Attributes\Test;
1617
use PHPUnit\Framework\TestCase;
1718
use Symfony\AI\McpSdk\Capability\Prompt\MetadataInterface;
1819
use Symfony\AI\McpSdk\Capability\PromptChain;
@@ -23,7 +24,8 @@
2324
#[CoversClass(PromptListHandler::class)]
2425
class PromptListHandlerTest extends TestCase
2526
{
26-
public function testHandleEmpty(): void
27+
#[Test]
28+
public function handleEmpty(): void
2729
{
2830
$handler = new PromptListHandler(new PromptChain([]));
2931
$message = new Request(1, 'prompts/list', []);
@@ -32,7 +34,8 @@ public function testHandleEmpty(): void
3234
$this->assertEquals(['prompts' => []], $response->result);
3335
}
3436

35-
public function testHandleReturnAll(): void
37+
#[Test]
38+
public function handleReturnAll(): void
3639
{
3740
$item = self::createMetadataItem();
3841
$handler = new PromptListHandler(new PromptChain([$item]));
@@ -42,7 +45,8 @@ public function testHandleReturnAll(): void
4245
$this->assertArrayNotHasKey('nextCursor', $response->result);
4346
}
4447

45-
public function testHandlePagination(): void
48+
#[Test]
49+
public function handlePagination(): void
4650
{
4751
$item = self::createMetadataItem();
4852
$handler = new PromptListHandler(new PromptChain([$item, $item]), 2);

src/mcp-sdk/tests/Server/RequestHandler/ResourceListHandlerTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\Attributes\CoversClass;
1515
use PHPUnit\Framework\Attributes\DataProvider;
1616
use PHPUnit\Framework\Attributes\Small;
17+
use PHPUnit\Framework\Attributes\Test;
1718
use PHPUnit\Framework\TestCase;
1819
use Symfony\AI\McpSdk\Capability\Resource\CollectionInterface;
1920
use Symfony\AI\McpSdk\Capability\Resource\MetadataInterface;
@@ -24,7 +25,8 @@
2425
#[CoversClass(ResourceListHandler::class)]
2526
class ResourceListHandlerTest extends TestCase
2627
{
27-
public function testHandleEmpty(): void
28+
#[Test]
29+
public function handleEmpty(): void
2830
{
2931
$collection = $this->getMockBuilder(CollectionInterface::class)
3032
->disableOriginalConstructor()
@@ -42,8 +44,9 @@ public function testHandleEmpty(): void
4244
/**
4345
* @param iterable<MetadataInterface> $metadataList
4446
*/
47+
#[Test]
4548
#[DataProvider('metadataProvider')]
46-
public function testHandleReturnAll(iterable $metadataList): void
49+
public function handleReturnAll(iterable $metadataList): void
4750
{
4851
$collection = $this->getMockBuilder(CollectionInterface::class)
4952
->disableOriginalConstructor()
@@ -70,7 +73,8 @@ public static function metadataProvider(): array
7073
];
7174
}
7275

73-
public function testHandlePagination(): void
76+
#[Test]
77+
public function handlePagination(): void
7478
{
7579
$item = self::createMetadataItem();
7680
$collection = $this->getMockBuilder(CollectionInterface::class)

0 commit comments

Comments
 (0)