Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7994 from aszenz/4.x
Adds support for fixing missing throws doc block
- Loading branch information
Showing
5 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<?php | ||
|
||
namespace Psalm\Tests\FileManipulation; | ||
|
||
class ThrowsBlockAdditionTest extends FileManipulationTestCase | ||
{ | ||
/** | ||
* @return array<string,array{string,string,string,string[],bool}> | ||
*/ | ||
public function providerValidCodeParse(): array | ||
{ | ||
return [ | ||
'addThrowsAnnotationToFunction' => [ | ||
'<?php | ||
function foo(string $s): string { | ||
if("" === $s) { | ||
throw new \InvalidArgumentException(); | ||
} | ||
return $s; | ||
}', | ||
'<?php | ||
/** | ||
* @throws InvalidArgumentException | ||
*/ | ||
function foo(string $s): string { | ||
if("" === $s) { | ||
throw new \InvalidArgumentException(); | ||
} | ||
return $s; | ||
}', | ||
'7.4', | ||
['MissingThrowsDocblock'], | ||
true, | ||
], | ||
'addMultipleThrowsAnnotationToFunction' => [ | ||
'<?php | ||
function foo(string $s): string { | ||
if("" === $s) { | ||
throw new \InvalidArgumentException(); | ||
} | ||
if("" === \trim($s)) { | ||
throw new \DomainException(); | ||
} | ||
return $s; | ||
}', | ||
'<?php | ||
/** | ||
* @throws InvalidArgumentException|DomainException | ||
*/ | ||
function foo(string $s): string { | ||
if("" === $s) { | ||
throw new \InvalidArgumentException(); | ||
} | ||
if("" === \trim($s)) { | ||
throw new \DomainException(); | ||
} | ||
return $s; | ||
}', | ||
'7.4', | ||
['MissingThrowsDocblock'], | ||
true, | ||
], | ||
'preservesExistingThrowsAnnotationToFunction' => [ | ||
'<?php | ||
/** | ||
* @throws InvalidArgumentException|DomainException | ||
*/ | ||
function foo(string $s): string { | ||
if("" === $s) { | ||
throw new \Exception(); | ||
} | ||
return $s; | ||
}', | ||
'<?php | ||
/** | ||
* @throws InvalidArgumentException|DomainException | ||
* @throws Exception | ||
*/ | ||
function foo(string $s): string { | ||
if("" === $s) { | ||
throw new \Exception(); | ||
} | ||
return $s; | ||
}', | ||
'7.4', | ||
['MissingThrowsDocblock'], | ||
true, | ||
], | ||
'doesNotAddDuplicateThrows' => [ | ||
'<?php | ||
/** | ||
* @throws InvalidArgumentException | ||
*/ | ||
function foo(string $s): string { | ||
if("" === $s) { | ||
throw new \InvalidArgumentException(); | ||
} | ||
if("" === \trim($s)) { | ||
throw new \DomainException(); | ||
} | ||
return $s; | ||
}', | ||
'<?php | ||
/** | ||
* @throws InvalidArgumentException | ||
* @throws DomainException | ||
*/ | ||
function foo(string $s): string { | ||
if("" === $s) { | ||
throw new \InvalidArgumentException(); | ||
} | ||
if("" === \trim($s)) { | ||
throw new \DomainException(); | ||
} | ||
return $s; | ||
}', | ||
'7.4', | ||
['MissingThrowsDocblock'], | ||
true, | ||
], | ||
]; | ||
} | ||
} |