diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index b4da5e23..a424acee 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -31,8 +31,6 @@ ->setRules([ '@Symfony' => true, '@Symfony:risky' => true, - 'protected_to_private' => false, - 'declare_strict_types' => false, 'header_comment' => ['header' => $fileHeader], 'php_unit_test_case_static_method_calls' => ['call_type' => 'this'], ]) diff --git a/examples/client/http_client_communication.php b/examples/client/http_client_communication.php index 987b190c..f5a39ea9 100644 --- a/examples/client/http_client_communication.php +++ b/examples/client/http_client_communication.php @@ -1,5 +1,14 @@ discoverer = new Discoverer(); } - public function testDiscoversAllElementTypesCorrectlyFromFixtureFiles() + public function testDiscoversAllElementTypesCorrectlyFromFixtureFiles(): void { $discovery = $this->discoverer->discover(__DIR__, ['Fixtures']); @@ -105,7 +105,7 @@ public function testDiscoversAllElementTypesCorrectlyFromFixtureFiles() $this->assertEquals([InvocableResourceTemplateFixture::class, '__invoke'], $templates['invokable://user-profile/{userId}']->handler); } - public function testDoesNotDiscoverElementsFromExcludedDirectories() + public function testDoesNotDiscoverElementsFromExcludedDirectories(): void { $discovery = $this->discoverer->discover(__DIR__, ['Fixtures']); $this->assertArrayHasKey('hidden_subdir_tool', $discovery->getTools()); @@ -114,14 +114,14 @@ public function testDoesNotDiscoverElementsFromExcludedDirectories() $this->assertArrayNotHasKey('hidden_subdir_tool', $discovery->getTools()); } - public function testHandlesEmptyDirectoriesOrDirectoriesWithNoPhpFiles() + public function testHandlesEmptyDirectoriesOrDirectoriesWithNoPhpFiles(): void { $discovery = $this->discoverer->discover(__DIR__, ['EmptyDir']); $this->assertTrue($discovery->isEmpty()); } - public function testCorrectlyInfersNamesAndDescriptionsFromMethodsOrClassesIfNotSetInAttribute() + public function testCorrectlyInfersNamesAndDescriptionsFromMethodsOrClassesIfNotSetInAttribute(): void { $discovery = $this->discoverer->discover(__DIR__, ['Fixtures']); @@ -138,7 +138,7 @@ public function testCorrectlyInfersNamesAndDescriptionsFromMethodsOrClassesIfNot $this->assertEquals('An invokable calculator tool.', $tools['InvokableCalculator']->tool->description); } - public function testDiscoversEnhancedCompletionProvidersWithValuesAndEnumAttributes() + public function testDiscoversEnhancedCompletionProvidersWithValuesAndEnumAttributes(): void { $discovery = $this->discoverer->discover(__DIR__, ['Fixtures']); diff --git a/tests/Unit/Capability/Discovery/DocBlockParserTest.php b/tests/Unit/Capability/Discovery/DocBlockParserTest.php index a99a9caf..a2a832ad 100644 --- a/tests/Unit/Capability/Discovery/DocBlockParserTest.php +++ b/tests/Unit/Capability/Discovery/DocBlockParserTest.php @@ -29,7 +29,7 @@ protected function setUp(): void $this->parser = new DocBlockParser(); } - public function testGetDescriptionReturnsCorrectDescription() + public function testGetDescriptionReturnsCorrectDescription(): void { $method = new \ReflectionMethod(DocBlockTestFixture::class, 'methodWithSummaryAndDescription'); $docComment = $method->getDocComment() ?: null; @@ -43,7 +43,7 @@ public function testGetDescriptionReturnsCorrectDescription() $this->assertEquals('Simple summary line.', $this->parser->getDescription($docBlock2)); } - public function testGetParamTagsReturnsStructuredParamInfo() + public function testGetParamTagsReturnsStructuredParamInfo(): void { $method = new \ReflectionMethod(DocBlockTestFixture::class, 'methodWithParams'); $docComment = $method->getDocComment() ?: null; @@ -94,7 +94,7 @@ public function testGetParamTagsReturnsStructuredParamInfo() $this->assertEquals('object param', $this->parser->getParamDescription($params['$param6'])); } - public function testGetTagsByNameReturnsSpecificTags() + public function testGetTagsByNameReturnsSpecificTags(): void { $method = new \ReflectionMethod(DocBlockTestFixture::class, 'methodWithMultipleTags'); $docComment = $method->getDocComment() ?: null; @@ -116,7 +116,7 @@ public function testGetTagsByNameReturnsSpecificTags() $this->assertEmpty($nonExistentTags); } - public function testHandlesMethodWithNoDocblockGracefully() + public function testHandlesMethodWithNoDocblockGracefully(): void { $method = new \ReflectionMethod(DocBlockTestFixture::class, 'methodWithNoDocBlock'); $docComment = $method->getDocComment() ?: null; diff --git a/tests/Unit/Capability/Discovery/Fixtures/NonDiscoverableClass.php b/tests/Unit/Capability/Discovery/Fixtures/NonDiscoverableClass.php index 21b84c64..eb42d0a7 100644 --- a/tests/Unit/Capability/Discovery/Fixtures/NonDiscoverableClass.php +++ b/tests/Unit/Capability/Discovery/Fixtures/NonDiscoverableClass.php @@ -25,7 +25,7 @@ interface MyDiscoverableInterface trait MyDiscoverableTrait { - public function traitMethod() + public function traitMethod(): void { } } diff --git a/tests/Unit/Capability/Discovery/Fixtures/SubDir/HiddenTool.php b/tests/Unit/Capability/Discovery/Fixtures/SubDir/HiddenTool.php index c519b0bc..8053aa6e 100644 --- a/tests/Unit/Capability/Discovery/Fixtures/SubDir/HiddenTool.php +++ b/tests/Unit/Capability/Discovery/Fixtures/SubDir/HiddenTool.php @@ -16,7 +16,7 @@ class HiddenTool { #[McpTool(name: 'hidden_subdir_tool')] - public function run() + public function run(): void { } } diff --git a/tests/Unit/Capability/Discovery/HandlerResolverTest.php b/tests/Unit/Capability/Discovery/HandlerResolverTest.php index 53188bf7..6a87a0b3 100644 --- a/tests/Unit/Capability/Discovery/HandlerResolverTest.php +++ b/tests/Unit/Capability/Discovery/HandlerResolverTest.php @@ -17,7 +17,7 @@ class HandlerResolverTest extends TestCase { - public function testResolvesClosuresToReflectionFunction() + public function testResolvesClosuresToReflectionFunction(): void { $closure = static function (string $input): string { return "processed: $input"; @@ -29,7 +29,7 @@ public function testResolvesClosuresToReflectionFunction() $this->assertEquals('string', $returnType->getName()); } - public function testResolvesValidArrayHandler() + public function testResolvesValidArrayHandler(): void { $handler = [ValidHandlerClass::class, 'publicMethod']; $resolved = HandlerResolver::resolve($handler); @@ -38,7 +38,7 @@ public function testResolvesValidArrayHandler() $this->assertEquals(ValidHandlerClass::class, $resolved->getDeclaringClass()->getName()); } - public function testResolvesValidInvokableClassStringHandler() + public function testResolvesValidInvokableClassStringHandler(): void { $handler = ValidInvokableClass::class; $resolved = HandlerResolver::resolve($handler); @@ -47,7 +47,7 @@ public function testResolvesValidInvokableClassStringHandler() $this->assertEquals(ValidInvokableClass::class, $resolved->getDeclaringClass()->getName()); } - public function testResolvesStaticMethodsForManualRegistration() + public function testResolvesStaticMethodsForManualRegistration(): void { $handler = [ValidHandlerClass::class, 'staticMethod']; $resolved = HandlerResolver::resolve($handler); @@ -56,84 +56,84 @@ public function testResolvesStaticMethodsForManualRegistration() $this->assertTrue($resolved->isStatic()); } - public function testThrowsForInvalidArrayHandlerFormatCount() + public function testThrowsForInvalidArrayHandlerFormatCount(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("Invalid array handler format. Expected [ClassName::class, 'methodName']."); HandlerResolver::resolve([ValidHandlerClass::class]); /* @phpstan-ignore argument.type */ } - public function testThrowsForInvalidArrayHandlerFormatTypes() + public function testThrowsForInvalidArrayHandlerFormatTypes(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("Invalid array handler format. Expected [ClassName::class, 'methodName']."); HandlerResolver::resolve([ValidHandlerClass::class, 123]); /* @phpstan-ignore argument.type */ } - public function testThrowsForNonExistentClassInArrayHandler() + public function testThrowsForNonExistentClassInArrayHandler(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Handler class "NonExistentClass" not found'); HandlerResolver::resolve(['NonExistentClass', 'method']); } - public function testThrowsForNonExistentMethodInArrayHandler() + public function testThrowsForNonExistentMethodInArrayHandler(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Handler method "nonExistentMethod" not found in class'); HandlerResolver::resolve([ValidHandlerClass::class, 'nonExistentMethod']); } - public function testThrowsForNonExistentClassInStringHandler() + public function testThrowsForNonExistentClassInStringHandler(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid handler format. Expected Closure, [ClassName::class, \'methodName\'] or InvokableClassName::class string.'); HandlerResolver::resolve('NonExistentInvokableClass'); } - public function testThrowsForNonInvokableClassStringHandler() + public function testThrowsForNonInvokableClassStringHandler(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invokable handler class "Mcp\Tests\Unit\Capability\Discovery\NonInvokableClass" must have a public "__invoke" method.'); HandlerResolver::resolve(NonInvokableClass::class); } - public function testThrowsForProtectedMethodHandler() + public function testThrowsForProtectedMethodHandler(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('must be public'); HandlerResolver::resolve([ValidHandlerClass::class, 'protectedMethod']); } - public function testThrowsForPrivateMethodHandler() + public function testThrowsForPrivateMethodHandler(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('must be public'); HandlerResolver::resolve([ValidHandlerClass::class, 'privateMethod']); } - public function testThrowsForConstructorAsHandler() + public function testThrowsForConstructorAsHandler(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('cannot be a constructor or destructor'); HandlerResolver::resolve([ValidHandlerClass::class, '__construct']); } - public function testThrowsForDestructorAsHandler() + public function testThrowsForDestructorAsHandler(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('cannot be a constructor or destructor'); HandlerResolver::resolve([ValidHandlerClass::class, '__destruct']); } - public function testThrowsForAbstractMethodHandler() + public function testThrowsForAbstractMethodHandler(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Handler method "Mcp\Tests\Unit\Capability\Discovery\AbstractHandlerClass::abstractMethod" must be abstract.'); HandlerResolver::resolve([AbstractHandlerClass::class, 'abstractMethod']); } - public function testResolvesClosuresWithDifferentSignatures() + public function testResolvesClosuresWithDifferentSignatures(): void { $noParams = static function () { return 'test'; @@ -152,7 +152,7 @@ public function testResolvesClosuresWithDifferentSignatures() $this->assertTrue(HandlerResolver::resolve($variadic)->isVariadic()); } - public function testDistinguishesBetweenClosuresAndCallableArrays() + public function testDistinguishesBetweenClosuresAndCallableArrays(): void { $closure = static function () { return 'closure'; diff --git a/tests/Unit/Capability/Discovery/SchemaGeneratorTest.php b/tests/Unit/Capability/Discovery/SchemaGeneratorTest.php index 5089e7d7..299e9854 100644 --- a/tests/Unit/Capability/Discovery/SchemaGeneratorTest.php +++ b/tests/Unit/Capability/Discovery/SchemaGeneratorTest.php @@ -26,7 +26,7 @@ protected function setUp(): void $this->schemaGenerator = new SchemaGenerator(new DocBlockParser()); } - public function testGeneratesEmptyPropertiesObjectForMethodWithNoParameters() + public function testGeneratesEmptyPropertiesObjectForMethodWithNoParameters(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'noParams'); $schema = $this->schemaGenerator->generate($method); @@ -37,7 +37,7 @@ public function testGeneratesEmptyPropertiesObjectForMethodWithNoParameters() $this->assertArrayNotHasKey('required', $schema); } - public function testInfersBasicTypesFromPhpTypeHints() + public function testInfersBasicTypesFromPhpTypeHints(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'typeHintsOnly'); $schema = $this->schemaGenerator->generate($method); @@ -49,7 +49,7 @@ public function testInfersBasicTypesFromPhpTypeHints() $this->assertEqualsCanonicalizing(['name', 'age', 'active', 'tags'], $schema['required']); } - public function testInfersTypesAndDescriptionsFromDocBlockTags() + public function testInfersTypesAndDescriptionsFromDocBlockTags(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'docBlockOnly'); $schema = $this->schemaGenerator->generate($method); @@ -60,7 +60,7 @@ public function testInfersTypesAndDescriptionsFromDocBlockTags() $this->assertEqualsCanonicalizing(['username', 'count', 'enabled', 'data'], $schema['required']); } - public function testUsesPhpTypeHintsForTypeAndDocBlockForDescriptions() + public function testUsesPhpTypeHintsForTypeAndDocBlockForDescriptions(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'typeHintsWithDocBlock'); $schema = $this->schemaGenerator->generate($method); @@ -70,7 +70,7 @@ public function testUsesPhpTypeHintsForTypeAndDocBlockForDescriptions() $this->assertEqualsCanonicalizing(['email', 'score', 'verified'], $schema['required']); } - public function testUsesCompleteSchemaDefinitionFromMethodLevelSchemaAttribute() + public function testUsesCompleteSchemaDefinitionFromMethodLevelSchemaAttribute(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'methodLevelCompleteDefinition'); $schema = $this->schemaGenerator->generate($method); @@ -92,7 +92,7 @@ public function testUsesCompleteSchemaDefinitionFromMethodLevelSchemaAttribute() ], $schema); } - public function testGeneratesSchemaFromMethodLevelSchemaAttributeWithProperties() + public function testGeneratesSchemaFromMethodLevelSchemaAttributeWithProperties(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'methodLevelWithProperties'); $schema = $this->schemaGenerator->generate($method); @@ -104,7 +104,7 @@ public function testGeneratesSchemaFromMethodLevelSchemaAttributeWithProperties( $this->assertEqualsCanonicalizing(['age', 'username', 'email'], $schema['required']); } - public function testGeneratesSchemaForSingleArrayArgumentFromMethodLevelSchemaAttribute() + public function testGeneratesSchemaForSingleArrayArgumentFromMethodLevelSchemaAttribute(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'methodLevelArrayArgument'); $schema = $this->schemaGenerator->generate($method); @@ -124,7 +124,7 @@ public function testGeneratesSchemaForSingleArrayArgumentFromMethodLevelSchemaAt $this->assertEquals(['profiles'], $schema['required']); } - public function testGeneratesSchemaFromIndividualParameterLevelSchemaAttributes() + public function testGeneratesSchemaFromIndividualParameterLevelSchemaAttributes(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'parameterLevelOnly'); $schema = $this->schemaGenerator->generate($method); @@ -143,7 +143,7 @@ public function testGeneratesSchemaFromIndividualParameterLevelSchemaAttributes( $this->assertEqualsCanonicalizing(['recipientId', 'messageBody'], $schema['required']); } - public function testAppliesStringConstraintsFromParameterLevelSchemaAttributes() + public function testAppliesStringConstraintsFromParameterLevelSchemaAttributes(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'parameterStringConstraints'); $schema = $this->schemaGenerator->generate($method); @@ -153,7 +153,7 @@ public function testAppliesStringConstraintsFromParameterLevelSchemaAttributes() $this->assertEqualsCanonicalizing(['email', 'password', 'regularString'], $schema['required']); } - public function testAppliesNumericConstraintsFromParameterLevelSchemaAttributes() + public function testAppliesNumericConstraintsFromParameterLevelSchemaAttributes(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'parameterNumericConstraints'); $schema = $this->schemaGenerator->generate($method); @@ -163,7 +163,7 @@ public function testAppliesNumericConstraintsFromParameterLevelSchemaAttributes( $this->assertEqualsCanonicalizing(['age', 'rating', 'count'], $schema['required']); } - public function testAppliesArrayConstraintsFromParameterLevelSchemaAttributes() + public function testAppliesArrayConstraintsFromParameterLevelSchemaAttributes(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'parameterArrayConstraints'); $schema = $this->schemaGenerator->generate($method); @@ -172,7 +172,7 @@ public function testAppliesArrayConstraintsFromParameterLevelSchemaAttributes() $this->assertEqualsCanonicalizing(['tags', 'scores'], $schema['required']); } - public function testMergesMethodLevelAndParameterLevelSchemaAttributes() + public function testMergesMethodLevelAndParameterLevelSchemaAttributes(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'methodAndParameterLevel'); $schema = $this->schemaGenerator->generate($method); @@ -181,7 +181,7 @@ public function testMergesMethodLevelAndParameterLevelSchemaAttributes() $this->assertEqualsCanonicalizing(['settingKey', 'newValue'], $schema['required']); } - public function testCombinesPhpTypeHintsDocBlockDescriptionsAndParameterLevelSchemaConstraints() + public function testCombinesPhpTypeHintsDocBlockDescriptionsAndParameterLevelSchemaConstraints(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'typeHintDocBlockAndParameterSchema'); $schema = $this->schemaGenerator->generate($method); @@ -190,7 +190,7 @@ public function testCombinesPhpTypeHintsDocBlockDescriptionsAndParameterLevelSch $this->assertEqualsCanonicalizing(['username', 'priority'], $schema['required']); } - public function testGeneratesCorrectSchemaForEnumParameters() + public function testGeneratesCorrectSchemaForEnumParameters(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'enumParameters'); $schema = $this->schemaGenerator->generate($method); @@ -202,7 +202,7 @@ public function testGeneratesCorrectSchemaForEnumParameters() $this->assertEqualsCanonicalizing(['stringEnum', 'intEnum', 'unitEnum'], $schema['required']); } - public function testGeneratesCorrectSchemaForArrayTypeDeclarations() + public function testGeneratesCorrectSchemaForArrayTypeDeclarations(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'arrayTypeScenarios'); $schema = $this->schemaGenerator->generate($method); @@ -218,7 +218,7 @@ public function testGeneratesCorrectSchemaForArrayTypeDeclarations() $this->assertEqualsCanonicalizing(['genericArray', 'stringArray', 'intArray', 'mixedMap', 'objectLikeArray', 'nestedObjectArray'], $schema['required']); } - public function testHandlesNullableTypeHintsAndOptionalParameters() + public function testHandlesNullableTypeHintsAndOptionalParameters(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'nullableAndOptional'); $schema = $this->schemaGenerator->generate($method); @@ -230,7 +230,7 @@ public function testHandlesNullableTypeHintsAndOptionalParameters() $this->assertEqualsCanonicalizing(['nullableString'], $schema['required']); } - public function testGeneratesSchemaForPhpUnionTypes() + public function testGeneratesSchemaForPhpUnionTypes(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'unionTypes'); $schema = $this->schemaGenerator->generate($method); @@ -239,7 +239,7 @@ public function testGeneratesSchemaForPhpUnionTypes() $this->assertEqualsCanonicalizing(['stringOrInt', 'multiUnion'], $schema['required']); } - public function testRepresentsVariadicStringParametersAsArrayOfStrings() + public function testRepresentsVariadicStringParametersAsArrayOfStrings(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'variadicStrings'); $schema = $this->schemaGenerator->generate($method); @@ -247,7 +247,7 @@ public function testRepresentsVariadicStringParametersAsArrayOfStrings() $this->assertArrayNotHasKey('required', $schema); } - public function testAppliesItemConstraintsToVariadicParameters() + public function testAppliesItemConstraintsToVariadicParameters(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'variadicWithConstraints'); $schema = $this->schemaGenerator->generate($method); @@ -255,7 +255,7 @@ public function testAppliesItemConstraintsToVariadicParameters() $this->assertArrayNotHasKey('required', $schema); } - public function testHandlesMixedTypeHintsOmittingExplicitType() + public function testHandlesMixedTypeHintsOmittingExplicitType(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'mixedTypes'); $schema = $this->schemaGenerator->generate($method); @@ -264,7 +264,7 @@ public function testHandlesMixedTypeHintsOmittingExplicitType() $this->assertEqualsCanonicalizing(['anyValue'], $schema['required']); } - public function testGeneratesSchemaForComplexNestedObjectAndArrayStructures() + public function testGeneratesSchemaForComplexNestedObjectAndArrayStructures(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'complexNestedSchema'); $schema = $this->schemaGenerator->generate($method); @@ -303,7 +303,7 @@ public function testGeneratesSchemaForComplexNestedObjectAndArrayStructures() $this->assertEquals(['order'], $schema['required']); } - public function testTypePrecedenceParameterSchemaOverridesDocBlockOverridesPhpTypeHint() + public function testTypePrecedenceParameterSchemaOverridesDocBlockOverridesPhpTypeHint(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'typePrecedenceTest'); $schema = $this->schemaGenerator->generate($method); @@ -313,7 +313,7 @@ public function testTypePrecedenceParameterSchemaOverridesDocBlockOverridesPhpTy $this->assertEqualsCanonicalizing(['numericString', 'stringWithConstraints', 'arrayWithItems'], $schema['required']); } - public function testGeneratesEmptyPropertiesObjectForMethodWithNoParametersEvenWithMethodLevelSchema() + public function testGeneratesEmptyPropertiesObjectForMethodWithNoParametersEvenWithMethodLevelSchema(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'noParamsWithSchema'); $schema = $this->schemaGenerator->generate($method); @@ -322,7 +322,7 @@ public function testGeneratesEmptyPropertiesObjectForMethodWithNoParametersEvenW $this->assertArrayNotHasKey('required', $schema); } - public function testInfersParameterTypeAsAnyIfOnlyConstraintsAreGiven() + public function testInfersParameterTypeAsAnyIfOnlyConstraintsAreGiven(): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'parameterSchemaInferredType'); $schema = $this->schemaGenerator->generate($method); @@ -340,7 +340,7 @@ public static function methodsWithForbiddenParameter(): array } #[DataProvider('methodsWithForbiddenParameter')] - public function testGenerateWithForbiddenParameterNames(string $methodName) + public function testGenerateWithForbiddenParameterNames(string $methodName): void { $method = new \ReflectionMethod(SchemaGeneratorFixture::class, $methodName); $this->expectException(InvalidArgumentException::class); diff --git a/tests/Unit/Capability/Discovery/SchemaValidatorTest.php b/tests/Unit/Capability/Discovery/SchemaValidatorTest.php index 7e8a2072..9464dcac 100644 --- a/tests/Unit/Capability/Discovery/SchemaValidatorTest.php +++ b/tests/Unit/Capability/Discovery/SchemaValidatorTest.php @@ -26,7 +26,7 @@ protected function setUp(): void // --- Basic Validation Tests --- - public function testValidDataPassesValidation() + public function testValidDataPassesValidation(): void { $schema = $this->getSimpleSchema(); $data = $this->getValidData(); @@ -36,7 +36,7 @@ public function testValidDataPassesValidation() $this->assertEmpty($errors); } - public function testInvalidTypeGeneratesTypeError() + public function testInvalidTypeGeneratesTypeError(): void { $schema = $this->getSimpleSchema(); $data = $this->getValidData(); @@ -50,7 +50,7 @@ public function testInvalidTypeGeneratesTypeError() $this->assertStringContainsString('Expected `integer`', $errors[0]['message']); } - public function testMissingRequiredPropertyGeneratesRequiredError() + public function testMissingRequiredPropertyGeneratesRequiredError(): void { $schema = $this->getSimpleSchema(); $data = $this->getValidData(); @@ -62,7 +62,7 @@ public function testMissingRequiredPropertyGeneratesRequiredError() $this->assertStringContainsString('Missing required properties: `name`', $errors[0]['message']); } - public function testAdditionalPropertyGeneratesAdditionalPropertiesError() + public function testAdditionalPropertyGeneratesAdditionalPropertiesError(): void { $schema = $this->getSimpleSchema(); $data = $this->getValidData(); @@ -77,7 +77,7 @@ public function testAdditionalPropertyGeneratesAdditionalPropertiesError() // --- Keyword Constraint Tests --- - public function testEnumConstraintViolation() + public function testEnumConstraintViolation(): void { $schema = ['type' => 'string', 'enum' => ['A', 'B']]; $data = 'C'; @@ -88,7 +88,7 @@ public function testEnumConstraintViolation() $this->assertStringContainsString('must be one of the allowed values: "A", "B"', $errors[0]['message']); } - public function testMinimumConstraintViolation() + public function testMinimumConstraintViolation(): void { $schema = ['type' => 'integer', 'minimum' => 10]; $data = 5; @@ -99,7 +99,7 @@ public function testMinimumConstraintViolation() $this->assertStringContainsString('must be greater than or equal to 10', $errors[0]['message']); } - public function testMaxLengthConstraintViolation() + public function testMaxLengthConstraintViolation(): void { $schema = ['type' => 'string', 'maxLength' => 5]; $data = 'toolong'; @@ -110,7 +110,7 @@ public function testMaxLengthConstraintViolation() $this->assertStringContainsString('Maximum string length is 5, found 7', $errors[0]['message']); } - public function testPatternConstraintViolation() + public function testPatternConstraintViolation(): void { $schema = ['type' => 'string', 'pattern' => '^[a-z]+$']; $data = '123'; @@ -121,7 +121,7 @@ public function testPatternConstraintViolation() $this->assertStringContainsString('does not match the required pattern: `^[a-z]+$`', $errors[0]['message']); } - public function testMinItemsConstraintViolation() + public function testMinItemsConstraintViolation(): void { $schema = ['type' => 'array', 'minItems' => 2]; $data = ['one']; @@ -132,7 +132,7 @@ public function testMinItemsConstraintViolation() $this->assertStringContainsString('Array should have at least 2 items, 1 found', $errors[0]['message']); } - public function testUniqueItemsConstraintViolation() + public function testUniqueItemsConstraintViolation(): void { $schema = ['type' => 'array', 'uniqueItems' => true]; $data = ['a', 'b', 'a']; @@ -144,7 +144,7 @@ public function testUniqueItemsConstraintViolation() } // --- Nested Structures and Pointers --- - public function testNestedObjectValidationErrorPointer() + public function testNestedObjectValidationErrorPointer(): void { $schema = [ 'type' => 'object', @@ -164,7 +164,7 @@ public function testNestedObjectValidationErrorPointer() $this->assertEquals('/user/id', $errors[0]['pointer']); } - public function testArrayItemValidationErrorPointer() + public function testArrayItemValidationErrorPointer(): void { $schema = [ 'type' => 'array', @@ -178,7 +178,7 @@ public function testArrayItemValidationErrorPointer() } // --- Data Conversion Tests --- - public function testValidatesDataPassedAsStdClassObject() + public function testValidatesDataPassedAsStdClassObject(): void { $schema = $this->getSimpleSchema(); $dataObj = json_decode(json_encode($this->getValidData())); // Convert to stdClass @@ -187,7 +187,7 @@ public function testValidatesDataPassedAsStdClassObject() $this->assertEmpty($errors); } - public function testValidatesDataWithNestedAssociativeArraysCorrectly() + public function testValidatesDataWithNestedAssociativeArraysCorrectly(): void { $schema = [ 'type' => 'object', @@ -207,7 +207,7 @@ public function testValidatesDataWithNestedAssociativeArraysCorrectly() } // --- Edge Cases --- - public function testHandlesInvalidSchemaStructureGracefully() + public function testHandlesInvalidSchemaStructureGracefully(): void { $schema = ['type' => 'object', 'properties' => ['name' => ['type' => 123]]]; // Invalid type value $data = ['name' => 'test']; @@ -218,7 +218,7 @@ public function testHandlesInvalidSchemaStructureGracefully() $this->assertStringContainsString('Schema validation process failed', $errors[0]['message']); } - public function testHandlesEmptyDataObjectAgainstSchemaRequiringProperties() + public function testHandlesEmptyDataObjectAgainstSchemaRequiringProperties(): void { $schema = $this->getSimpleSchema(); // Requires name, age etc. $data = []; // Empty data @@ -229,7 +229,7 @@ public function testHandlesEmptyDataObjectAgainstSchemaRequiringProperties() $this->assertEquals('required', $errors[0]['keyword']); } - public function testHandlesEmptySchemaAllowsAnything() + public function testHandlesEmptySchemaAllowsAnything(): void { $schema = []; // Empty schema object/array implies no constraints $data = ['anything' => [1, 2], 'goes' => true]; @@ -241,7 +241,7 @@ public function testHandlesEmptySchemaAllowsAnything() $this->assertStringContainsString('Invalid schema', $errors[0]['message']); } - public function testValidatesSchemaWithStringFormatConstraintsFromSchemaAttribute() + public function testValidatesSchemaWithStringFormatConstraintsFromSchemaAttribute(): void { $emailSchema = (new Schema(format: 'email'))->toArray(); @@ -256,7 +256,7 @@ public function testValidatesSchemaWithStringFormatConstraintsFromSchemaAttribut $this->assertStringContainsString('email', $invalidErrors[0]['message']); } - public function testValidatesSchemaWithStringLengthConstraintsFromSchemaAttribute() + public function testValidatesSchemaWithStringLengthConstraintsFromSchemaAttribute(): void { $passwordSchema = (new Schema(minLength: 8, pattern: '^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$'))->toArray(); @@ -275,7 +275,7 @@ public function testValidatesSchemaWithStringLengthConstraintsFromSchemaAttribut $this->assertEquals('pattern', $noDigitErrors[0]['keyword']); } - public function testValidatesSchemaWithNumericConstraintsFromSchemaAttribute() + public function testValidatesSchemaWithNumericConstraintsFromSchemaAttribute(): void { $ageSchema = (new Schema(minimum: 18, maximum: 120))->toArray(); @@ -294,7 +294,7 @@ public function testValidatesSchemaWithNumericConstraintsFromSchemaAttribute() $this->assertEquals('maximum', $tooHighErrors[0]['keyword']); } - public function testValidatesSchemaWithArrayConstraintsFromSchemaAttribute() + public function testValidatesSchemaWithArrayConstraintsFromSchemaAttribute(): void { $tagsSchema = (new Schema(uniqueItems: true, minItems: 2))->toArray(); @@ -313,7 +313,7 @@ public function testValidatesSchemaWithArrayConstraintsFromSchemaAttribute() $this->assertEquals('minItems', $tooFewErrors[0]['keyword']); } - public function testValidatesSchemaWithObjectConstraintsFromSchemaAttribute() + public function testValidatesSchemaWithObjectConstraintsFromSchemaAttribute(): void { $userSchema = (new Schema( properties: [ @@ -363,7 +363,7 @@ public function testValidatesSchemaWithObjectConstraintsFromSchemaAttribute() $this->assertEquals('minimum', $ageErrors[0]['keyword']); } - public function testValidatesSchemaWithNestedConstraintsFromSchemaAttribute() + public function testValidatesSchemaWithNestedConstraintsFromSchemaAttribute(): void { $orderSchema = (new Schema( properties: [ diff --git a/tests/Unit/Capability/Logger/ClientLoggerTest.php b/tests/Unit/Capability/Logger/ClientLoggerTest.php index aa0dc486..6a443b71 100644 --- a/tests/Unit/Capability/Logger/ClientLoggerTest.php +++ b/tests/Unit/Capability/Logger/ClientLoggerTest.php @@ -22,7 +22,7 @@ */ final class ClientLoggerTest extends TestCase { - public function testLog() + public function testLog(): void { $session = $this->getMockBuilder(Session::class) ->disableOriginalConstructor() @@ -39,7 +39,7 @@ public function testLog() $logger->notice('test'); } - public function testLogFilter() + public function testLogFilter(): void { $session = $this->getMockBuilder(Session::class) ->disableOriginalConstructor() @@ -56,7 +56,7 @@ public function testLogFilter() $logger->debug('test'); } - public function testLogFilterSameLevel() + public function testLogFilterSameLevel(): void { $session = $this->getMockBuilder(Session::class) ->disableOriginalConstructor() @@ -73,7 +73,7 @@ public function testLogFilterSameLevel() $logger->info('test'); } - public function testLogWithInvalidLevel() + public function testLogWithInvalidLevel(): void { $session = $this->getMockBuilder(Session::class) ->disableOriginalConstructor() diff --git a/tests/Unit/Schema/Elicitation/BooleanSchemaDefinitionTest.php b/tests/Unit/Schema/Elicitation/BooleanSchemaDefinitionTest.php index b6fc6f07..fefea478 100644 --- a/tests/Unit/Schema/Elicitation/BooleanSchemaDefinitionTest.php +++ b/tests/Unit/Schema/Elicitation/BooleanSchemaDefinitionTest.php @@ -1,7 +1,5 @@ assertSame('any', $icon->sizes[0]); } - public function testConstructorWithMultipleSizes() + public function testConstructorWithMultipleSizes(): void { $icon = new Icon('https://example.com/icon.png', 'image/png', ['48x48', '96x96']); @@ -34,14 +34,14 @@ public function testConstructorWithMultipleSizes() $this->assertSame(['48x48', '96x96'], $icon->sizes); } - public function testConstructorWithAnySizes() + public function testConstructorWithAnySizes(): void { $icon = new Icon('https://example.com/icon.svg', 'image/png', ['any']); $this->assertSame(['any'], $icon->sizes); } - public function testConstructorWithNullOptionalFields() + public function testConstructorWithNullOptionalFields(): void { $icon = new Icon('https://example.com/icon.png'); @@ -50,35 +50,35 @@ public function testConstructorWithNullOptionalFields() $this->assertNull($icon->sizes); } - public function testInvalidSizesFormatThrowsException() + public function testInvalidSizesFormatThrowsException(): void { $this->expectException(InvalidArgumentException::class); new Icon('https://example.com/icon.png', 'image/png', ['invalid-size']); } - public function testInvalidPixelSizesFormatThrowsException() + public function testInvalidPixelSizesFormatThrowsException(): void { $this->expectException(InvalidArgumentException::class); new Icon('https://example.com/icon.png', 'image/png', ['180x48x48']); } - public function testEmptySrcThrowsException() + public function testEmptySrcThrowsException(): void { $this->expectException(InvalidArgumentException::class); new Icon('', 'image/png', ['48x48']); } - public function testInvalidSrcThrowsException() + public function testInvalidSrcThrowsException(): void { $this->expectException(InvalidArgumentException::class); new Icon('not-a-url', 'image/png', ['48x48']); } - public function testValidDataUriSrc() + public function testValidDataUriSrc(): void { $dataUri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA'; $icon = new Icon($dataUri, 'image/png', ['48x48']); diff --git a/tests/Unit/Schema/JsonRpc/NotificationTest.php b/tests/Unit/Schema/JsonRpc/NotificationTest.php index af98671c..0d7d7c48 100644 --- a/tests/Unit/Schema/JsonRpc/NotificationTest.php +++ b/tests/Unit/Schema/JsonRpc/NotificationTest.php @@ -16,7 +16,7 @@ final class NotificationTest extends TestCase { - public function testMetaIsLoopedThrough() + public function testMetaIsLoopedThrough(): void { $notificationImplementation = new class extends Notification { public static function getMethod(): string diff --git a/tests/Unit/Schema/JsonRpc/RequestTest.php b/tests/Unit/Schema/JsonRpc/RequestTest.php index 86e01d3d..f400a904 100644 --- a/tests/Unit/Schema/JsonRpc/RequestTest.php +++ b/tests/Unit/Schema/JsonRpc/RequestTest.php @@ -16,7 +16,7 @@ final class RequestTest extends TestCase { - public function testMetaAndIdAreLoopedThrough() + public function testMetaAndIdAreLoopedThrough(): void { $requestImplementation = new class extends Request { public static function getMethod(): string diff --git a/tests/Unit/Schema/Request/CreateSamplingMessageRequestTest.php b/tests/Unit/Schema/Request/CreateSamplingMessageRequestTest.php index 77ea7945..57f790a7 100644 --- a/tests/Unit/Schema/Request/CreateSamplingMessageRequestTest.php +++ b/tests/Unit/Schema/Request/CreateSamplingMessageRequestTest.php @@ -20,7 +20,7 @@ final class CreateSamplingMessageRequestTest extends TestCase { - public function testConstructorWithValidSetOfMessages() + public function testConstructorWithValidSetOfMessages(): void { $messages = [ new SamplingMessage(Role::User, new TextContent('My name is George.')), @@ -34,7 +34,7 @@ public function testConstructorWithValidSetOfMessages() $this->assertSame(150, $request->maxTokens); } - public function testConstructorWithInvalidSetOfMessages() + public function testConstructorWithInvalidSetOfMessages(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Messages must be instance of SamplingMessage.'); diff --git a/tests/Unit/Schema/Request/ElicitRequestTest.php b/tests/Unit/Schema/Request/ElicitRequestTest.php index 06cee6a9..5421e3d7 100644 --- a/tests/Unit/Schema/Request/ElicitRequestTest.php +++ b/tests/Unit/Schema/Request/ElicitRequestTest.php @@ -1,7 +1,5 @@ assertNotEquals($session1->getId()->toRfc4122(), $session2->getId()->toRfc4122()); } - public function testAll() + public function testAll(): void { $store = $this->getMockBuilder(InMemorySessionStore::class) ->disableOriginalConstructor() @@ -289,7 +289,7 @@ public function testAll() $this->assertEquals(['foo' => 'bar'], $result); } - public function testSaveBeforeReadInitializesData() + public function testSaveBeforeReadInitializesData(): void { $store = new InMemorySessionStore(); $session = new Session($store); @@ -298,7 +298,7 @@ public function testSaveBeforeReadInitializesData() $this->assertTrue($session->save()); } - public function testAllReturnsEmptyArrayForNullPayload() + public function testAllReturnsEmptyArrayForNullPayload(): void { $store = $this->getMockBuilder(InMemorySessionStore::class) ->disableOriginalConstructor()