Skip to content
Permalink
Browse files

Fix throws docblock inheritance (#1945)

  • Loading branch information...
smelesh authored and muglug committed Jul 13, 2019
1 parent 7f0dcae commit ee1387473f8060c2f01a4928bc4062f24ef0524c
Showing with 72 additions and 0 deletions.
  1. +1 −0 src/Psalm/Internal/Codebase/Populator.php
  2. +71 −0 tests/ThrowsAnnotationTest.php
@@ -307,6 +307,7 @@ private function populateOverriddenMethods(
&& $method_storage->inheritdoc
&& $declaring_method_storage->throws
) {
$method_storage->throws = $declaring_method_storage->throws;
}
if (count($storage->overridden_method_ids[$method_name]) === 1
@@ -407,4 +407,75 @@ function bar(int $x, int $y) : void {
$this->analyzeFile('somefile.php', $context);
}
/**
* @return void
*/
public function testDocumentedThrowInInterfaceWithInheritDocblock()
{
Config::getInstance()->check_for_throws_docblock = true;
$this->addFile(
'somefile.php',
'<?php
interface Foo
{
/**
* @throws \InvalidArgumentException
*/
public function test(): void;
}
class Bar implements Foo
{
/**
* {@inheritdoc}
*/
public function test(): void
{
throw new \InvalidArgumentException();
}
}
'
);
$context = new Context();
$this->analyzeFile('somefile.php', $context);
}
/**
* @return void
*/
public function testDocumentedThrowInInterfaceWithoutInheritDocblock()
{
$this->expectExceptionMessage('MissingThrowsDocblock');
$this->expectException(\Psalm\Exception\CodeException::class);
Config::getInstance()->check_for_throws_docblock = true;
$this->addFile(
'somefile.php',
'<?php
interface Foo
{
/**
* @throws \InvalidArgumentException
*/
public function test(): void;
}
class Bar implements Foo
{
public function test(): void
{
throw new \InvalidArgumentException();
}
}
'
);
$context = new Context();
$this->analyzeFile('somefile.php', $context);
}
}

0 comments on commit ee13874

Please sign in to comment.
You can’t perform that action at this time.