Use phpstan/phpstan-phpunit

This commit is contained in:
Vincent Langlet
2025-12-21 21:11:29 +01:00
committed by Oskar Stark
parent f12690e77c
commit 9608fd396a
6 changed files with 27 additions and 5 deletions

View File

@@ -62,6 +62,7 @@
},
"require-dev": {
"phpstan/phpstan": "^2.1.17",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^11.5.46",
"symfony/cache": "^7.3|^8.0",

View File

@@ -1,4 +1,5 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- ../../.phpstan/extension.neon
parameters:
@@ -12,6 +13,9 @@ parameters:
ignoreErrors:
-
message: "#^Method .*::test.*\\(\\) has no return type specified\\.$#"
-
message: '#^Call to( static)? method PHPUnit\\Framework\\Assert::.* will always evaluate to true\.$#'
reportUnmatched: false
-
message: '#supportsNormalization\(\) has parameter \$context with no value type specified in iterable type array#'
path: src/*
@@ -20,11 +24,13 @@ parameters:
message: '#getSupportedTypes\(\) return type has no value type specified in iterable type array#'
path: src/*
reportUnmatched: false # only needed for older Symfony versions
-
identifier: missingType.iterableValue
path: tests/*
reportUnmatched: false
-
identifier: 'symfonyAi.forbidNativeException'
path: tests/*
reportUnmatched: false
services:
- # Conditionally enabled by bleeding edge in phpstan/phpstan-phpunit 2.x
class: PHPStan\Type\PHPUnit\DataProviderReturnTypeIgnoreExtension
tags:
- phpstan.ignoreErrorExtension

View File

@@ -36,6 +36,9 @@ final class AudioNormalizerTest extends TestCase
$this->assertSame([Audio::class => true], $this->normalizer->getSupportedTypes(null));
}
/**
* @param array<string, mixed> $expected
*/
#[DataProvider('provideAudioData')]
public function testNormalize(string $data, string $format, array $expected)
{

View File

@@ -23,6 +23,9 @@ use Symfony\AI\Platform\Tool\Tool;
class ToolNormalizerTest extends TestCase
{
/**
* @param array<string, mixed> $expected
*/
#[DataProvider('provideTools')]
public function testNormalize(Tool $tool, array $expected)
{

View File

@@ -33,6 +33,10 @@ use Symfony\AI\Platform\Model;
final class ContractTest extends TestCase
{
/**
* @param object|array<string|int, mixed>|string $input
* @param array<string, mixed>|string $expected
*/
#[DataProvider('providePayloadTestCases')]
public function testCreateRequestPayload(Model $model, array|string|object $input, array|string $expected)
{
@@ -45,7 +49,7 @@ final class ContractTest extends TestCase
/**
* @return iterable<string, array{
* input: array|string|object,
* input: object|array<string|int, mixed>|string,
* expected: array<string, mixed>|string
* }>
*/
@@ -185,6 +189,9 @@ final class ContractTest extends TestCase
return [new Text('This is a custom serializable message.')];
}
/**
* @return array<string, string>
*/
public function jsonSerialize(): array
{
return [

View File

@@ -13,6 +13,7 @@ namespace Symfony\AI\Platform\Tests\Metadata;
use PHPUnit\Framework\Attributes\CoversTrait;
use PHPUnit\Framework\TestCase;
use Symfony\AI\Platform\Metadata\Metadata;
use Symfony\AI\Platform\Metadata\MetadataAwareTrait;
#[CoversTrait(MetadataAwareTrait::class)]
@@ -23,6 +24,7 @@ final class MetadataAwareTraitTest extends TestCase
$result = $this->createTestClass();
$metadata = $result->getMetadata();
$this->assertInstanceOf(Metadata::class, $metadata);
$this->assertCount(0, $metadata);
$metadata->add('key', 'value');