php-sdk/tests/Unit/Schema/Request/CreateSamplingMessageRequestTest.php
Mateu Aguiló Bosch 73e4cc2456
style: apply php-cs-fixer and PHPStan fixes (#289)
* style: apply php-cs-fixer to test files

Addresses drift flagged by the default PHP-CS-Fixer config — mostly
adds missing `: void` return types on pre-existing test methods.

No behavioural changes.

* fix: resolve phpstan errors surfaced by qa

- Drop the obsolete `Method ::test*() has no return type specified`
  ignore rule — every test method now declares a return type, so
  the pattern never matches and phpstan reports it as unmatched.
- Remove `?? []` from two reads of `CallToolRequest::$arguments`;
  the property is typed `array` (non-nullable), so the coalesce is
  a no-op that phpstan flags.

---------

Co-authored-by: DDEV User <nobody@example.com>
2026-04-20 20:49:15 +02:00

51 lines
1.7 KiB
PHP

<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Tests\Unit\Schema\Request;
use Mcp\Exception\InvalidArgumentException;
use Mcp\Schema\Content\SamplingMessage;
use Mcp\Schema\Content\TextContent;
use Mcp\Schema\Enum\Role;
use Mcp\Schema\Request\CreateSamplingMessageRequest;
use PHPUnit\Framework\TestCase;
final class CreateSamplingMessageRequestTest extends TestCase
{
public function testConstructorWithValidSetOfMessages(): void
{
$messages = [
new SamplingMessage(Role::User, new TextContent('My name is George.')),
new SamplingMessage(Role::Assistant, new TextContent('Hi George, nice to meet you!')),
new SamplingMessage(Role::User, new TextContent('What is my name?')),
];
$request = new CreateSamplingMessageRequest($messages, 150);
$this->assertCount(3, $request->messages);
$this->assertSame(150, $request->maxTokens);
}
public function testConstructorWithInvalidSetOfMessages(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Messages must be instance of SamplingMessage.');
$messages = [
new SamplingMessage(Role::User, new TextContent('My name is George.')),
new SamplingMessage(Role::Assistant, new TextContent('Hi George, nice to meet you!')),
new TextContent('What is my name?'),
];
/* @phpstan-ignore argument.type */
new CreateSamplingMessageRequest($messages, 150);
}
}