use_phpdoc_methods_without_call = true; $this->addFile( 'somefile.php', 'getString(); $child->setInteger(4); /** @psalm-suppress MixedAssignment */ $b = $child->setString(5); $c = $child->getBool("hello"); $d = $child->getArray(); $e = $child->getCallable();' ); $this->analyzeFile('somefile.php', new Context()); } /** * @return void */ public function testCannotOverrideParentClassRetunTypeWhenIgnoringPhpDocMethod() { Config::getInstance()->use_phpdoc_methods_without_call = false; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); $this->assertSame('ParentClass', (string) $context->vars_in_scope['$child']); } /** * @return void */ public function testOverrideParentClassRetunType() { Config::getInstance()->use_phpdoc_methods_without_call = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); $this->assertSame('Child', (string) $context->vars_in_scope['$child']); } /** * @return array */ public function providerFileCheckerValidCodeParse() { return [ 'validSimpleAnnotations' => [ 'getString(); $child->setInteger(4); /** @psalm-suppress MixedAssignment */ $b = $child->setString(5); $c = $child->getBool("hello"); $d = $child->getArray(); $child->setArray(["boo"]); $e = $child->getCallable(); $child->setMixed("hello"); $child->setMixed(4); $child->setImplicitMixed("hello"); $child->setImplicitMixed(4);', 'assertions' => [ '$a' => 'string', '$b' => 'mixed', '$c' => 'bool', '$d' => 'array', '$e' => 'callable():string', ], ], 'validAnnotationWithDefault' => [ 'setArray(["boo"]); $child->setArray(["boo"], 8);', ], 'validAnnotationWithVariadic' => [ 'setInts(1, 2, 3, 4);', ], 'validUnionAnnotations' => [ 'setBool("hello", true); $c = $child->setBool("hello", "true"); $child->setAnotherArray(["boo"]);', 'assertions' => [ '$b' => 'bool', '$c' => 'bool', ], ], 'namespacedValidAnnotations' => [ 'setBool("hello", true); $c = $child->setBool("hello", "true");', ], 'globalMethod' => [ ' [ 'getString();', 'error_message' => 'UndefinedMethod', ], 'annotationWithBadDocblock' => [ ' 'InvalidDocblock', ], 'annotationWithByRefParam' => [ ' 'InvalidDocblock', ], 'annotationWithSealed' => [ 'getString(); $child->foo();', 'error_message' => 'UndefinedMethod - src/somefile.php:14 - Method Child::foo does not exist', ], 'annotationInvalidArg' => [ 'setString("five");', 'error_message' => 'InvalidScalarArgument', ], 'unionAnnotationInvalidArg' => [ 'setBool("hello", 5);', 'error_message' => 'InvalidScalarArgument', ], 'validAnnotationWithInvalidVariadicCall' => [ 'setInts([1, 2, 3]);', 'error_message' => 'InvalidArgument', ], ]; } }