markTestSkipped('Cannot run test, base class "SoapClient" does not exist!'); return; } $this->addFile( 'somefile.php', ' $arguments * @param array $options default null * @param array|SoapHeader $input_headers default null * @param array $output_headers default null * @return mixed */ public function __soapCall( $function_name, $arguments, $options = [], $input_headers = [], &$output_headers = [] ) { return $_GET["foo"]; } }' ); $this->analyzeFile('somefile.php', new Context()); } /** * @return void */ public function testExtendSoapClientWithNoDocblockTypes() { if (class_exists('SoapClient') === false) { $this->markTestSkipped('Cannot run test, base class "SoapClient" does not exist!'); return; } $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', new Context()); } /** * @return void */ public function testExtendSoapClientWithParamType() { if (class_exists('SoapClient') === false) { $this->markTestSkipped('Cannot run test, base class "SoapClient" does not exist!'); return; } $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', new Context()); } public function testMismatchingCovariantReturnIn73(): void { $this->expectExceptionMessage('MethodSignatureMismatch'); $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer->setPhpVersion('7.3'); $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', new Context()); } public function testMismatchingCovariantReturnIn74(): void { $this->project_analyzer->setPhpVersion('7.4'); $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', new Context()); } public function testMismatchingCovariantReturnIn73WithSelf(): void { $this->expectExceptionMessage('MethodSignatureMismatch'); $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer->setPhpVersion('7.3'); $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', new Context()); } public function testMismatchingCovariantReturnIn74WithSelf(): void { $this->project_analyzer->setPhpVersion('7.4'); $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', new Context()); } public function testMismatchingCovariantParamIn73(): void { $this->expectExceptionMessage('MethodSignatureMismatch'); $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer->setPhpVersion('7.3'); $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', new Context()); } public function testMismatchingCovariantParamIn74(): void { $this->project_analyzer->setPhpVersion('7.4'); $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', new Context()); } /** * @return void */ public function testExtendDocblockParamTypeWithWrongDocblockParam() { $this->expectExceptionMessage('ImplementedParamTypeMismatch'); $this->expectException(\Psalm\Exception\CodeException::class); if (class_exists('SoapClient') === false) { $this->markTestSkipped('Cannot run test, base class "SoapClient" does not exist!'); return; } $this->addFile( 'somefile.php', ' $options default null * @param array $input_headers default null * @param array $output_headers default null * @return mixed */ public function __soapCall( $function_name, $arguments, $options = [], $input_headers = [], &$output_headers = [] ) { } }' ); $this->analyzeFile('somefile.php', new Context()); } public function testExtendDocblockParamTypeWithWrongParam() : void { $this->expectException(\Psalm\Exception\CodeException::class); $this->expectExceptionMessage('MethodSignatureMismatch'); if (class_exists('SoapClient') === false) { $this->markTestSkipped('Cannot run test, base class "SoapClient" does not exist!'); return; } $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', new Context()); } /** * @return iterable,error_levels?:string[]}> */ public function providerValidCodeParse(): iterable { return [ 'privateArgs' => [ ' [ 'foo(null);', ], 'nullableSubclassParamWithDefault' => [ 'foo();', ], 'allowSubclassesForNonInheritedMethodParams' => [ 'bar(); }', ], 'allowNoReturnInSubclassWithNullableReturnType' => [ ' [ ' [ ' [ '$b' => 'B', ], ], 'allowSomeCovariance' => [ ' [ ' [ 'id, ] = (array) \unserialize($serialized); } public function serialize() : string { return serialize([$this->id]); } }', ], 'clashWithCallMapClass' => [ ' [ ' [ ' [ ' [ ' [ ' [ 'boo(new A()); (new Z())->boo(new A());', ], 'allowMixedExtensionOfIteratorAggregate' => [ ' [ 'f(); (new C)->f("b"); (new C)->f("b", 3); (new C)->f("b", 3, 0.5); (new C)->f("b", 3, 0.5, 0.8);', ], 'allowLessSpecificDocblockTypeOnParent' => [ 'getTargets();', [ '$a' => 'string', ], ], 'parentIsKnown' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' */ public function providerInvalidCodeParse(): iterable { return [ 'oneParam' => [ ' 'Argument 1 of C::foo has wrong name $c, expecting $i as defined by I::foo', ], 'moreArguments' => [ ' 'Method B::fooFoo has more required parameters than parent method A::fooFoo', ], 'fewerArguments' => [ ' 'Method B::fooFoo has fewer parameters than parent method A::fooFoo', ], 'differentArgumentTypes' => [ ' 'Argument 2 of B::fooFoo has wrong type \'int\', expecting \'bool\' as defined ' . 'by A::fooFoo', ], 'differentArgumentNames' => [ ' 'ParamNameMismatch', ], 'nonNullableSubclassParam' => [ ' 'Argument 1 of B::foo has wrong type \'string\', expecting \'null|string\' as', ], 'misplacedRequiredParam' => [ ' 'TooFewArguments', ], 'clasginByRef' => [ ' 'MethodSignatureMismatch', ], 'disallowSubclassesForNonInheritedMethodParams' => [ 'bar(); } }', 'error_message' => 'MoreSpecificImplementedParamType', ], 'preventVoidToNullConversionSignature' => [ ' 'MethodSignatureMismatch', ], 'abstractExtendsNonAbstractWithMethod' => [ ' 'MethodSignatureMismatch', ], 'traitReturnTypeMismatch' => [ ' 'MethodSignatureMismatch', ], 'abstractTraitMethodWithDifferentReturnType' => [ ' 'TraitMethodSignatureMismatch', ], 'traitMoreParams' => [ ' 'MethodSignatureMismatch', ], 'abstractTraitMethodWithDifferentParamType' => [ ' 'TraitMethodSignatureMismatch', ], 'mustOmitReturnType' => [ ' 'MethodSignatureMustOmitReturnType', ], 'requireParam' => [ ' 'MethodSignatureMismatch - src' . DIRECTORY_SEPARATOR . 'somefile.php:6:27 - Method C::foo has more required', ], 'inheritParamTypes' => [ 'foo(new stdClass);', 'error_message' => 'InvalidArgument', ], 'interfaceHasFewerConstructorArgs' => [ ' 'ConstructorSignatureMismatch', ], 'enforceParameterInheritanceWithInheritDoc' => [ 'boo(new A());', 'error_message' => 'ArgumentTypeCoercion', ], 'enforceParameterInheritanceWithCapitalizedInheritDoc' => [ 'boo(new A());', 'error_message' => 'ArgumentTypeCoercion', ], 'warnAboutMismatchingClassParamDoc' => [ ' 'MismatchingDocblockParamType', ], 'warnAboutMismatchingInterfaceParamDoc' => [ ' 'MismatchingDocblockParamType', ], 'interfaceInsertDocblockTypes' => [ ' */ public function getFoos() : array; } class A implements I { public function getFoos() : array { return [new Bar()]; } }', 'error_message' => 'InvalidReturnStatement', ], 'classInsertDocblockTypesFromParent' => [ ' */ public function getFoos() : array { return [new Foo()]; } } class A extends B { public function getFoos() : array { return [new Bar()]; } }', 'error_message' => 'InvalidReturnStatement', ], 'preventInterfaceOverload' => [ ' $f * @psalm-suppress ParamNameMismatch */ public function f($f): void {} }', 'error_message' => 'MethodSignatureMismatch', ['MoreSpecificImplementedParamType'], ], 'preventOneOfUnionMoreSpecific' => [ ' 'MoreSpecificImplementedParamType', ], 'preventImplementingSerializableWithWrongDocblockType' => [ ' 'ImplementedParamTypeMismatch', ], 'returnsParentWithNoParent' => [ ' 'InvalidParent', ], 'returnsParentWithNoParentAndInvalidParentSuppressed' => [ ' 'InvalidReturnType', ['InvalidParent'], ], // not sure how to handle it 'SKIPPED-returnsParentWithNoParentAndInvalidParentSuppressedMismatchingReturn' => [ ' 'InvalidReturnType', ['InvalidParent'], ], 'regularMethodMismatchFromParentUse' => [ ' 'MethodSignatureMismatch', ], 'regularMethodMismatchFromChildUse' => [ ' 'MethodSignatureMismatch', ], 'traitMethodAccessLevel' => [ ' 'TraitMethodSignatureMismatch', ], 'abstractClassReturnMismatch' => [ ' 'MethodSignatureMismatch', ], 'abstractClassParamMismatch' => [ ' 'MethodSignatureMismatch', ], 'preventTraitMatchIn73' => [ ' 'MethodSignatureMismatch', [], false, '7.3' ], 'inconsistentConstructorExplicitParentConstructorArgCount' => [ ' 'ConstructorSignatureMismatch', ], 'inconsistentConstructorExplicitParentConstructorType' => [ ' 'ConstructorSignatureMismatch', ], 'inconsistentConstructorImplicitParentConstructor' => [ ' 'ConstructorSignatureMismatch', ], 'inheritDocblockReturnFromInterface' => [ ' 'InvalidReturnType', ], 'disableNamedArgumentsInDescendant' => [ ' 'MethodSignatureMismatch', ], ]; } }