From 5f69d7d3c064afd2f585cd3f739e5867c6295027 Mon Sep 17 00:00:00 2001 From: Gert de Pagter Date: Tue, 15 Oct 2019 19:54:05 +0200 Subject: [PATCH] Add an auto review test for the annotations (#133) And also fix the one issue found by the test --- src/Assert.php | 2 ++ tests/ProjectCodeTest.php | 44 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/Assert.php b/src/Assert.php index 09e69ab1..4c9a334f 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -247,6 +247,8 @@ public static function integer($value, $message = '') * * @param mixed $value * @param string $message + * + * @throws InvalidArgumentException */ public static function integerish($value, $message = '') { diff --git a/tests/ProjectCodeTest.php b/tests/ProjectCodeTest.php index bce516c7..ef869ea8 100644 --- a/tests/ProjectCodeTest.php +++ b/tests/ProjectCodeTest.php @@ -77,20 +77,58 @@ public function testIsInReadme($method) ); } + /** + * @dataProvider provideMethods + * + * @param ReflectionMethod $method + */ + public function testHasThrowsAnnotation($method) + { + $doc = $method->getDocComment(); + + $this->assertNotFalse( + $doc, + sprintf( + 'Expected a doc comment on the "%s" method, but none found', + $method->getName() + ) + ); + + $this->assertContains( + '@throws InvalidArgumentException', + $doc, + sprintf( + 'Expected method "%s" to have an @throws InvalidArgumentException annotation, but none found', + $method->getName() + ) + ); + + } + /** * @return array */ public function providesMethodNames() + { + return array_map(function($value) { + return array($value->getName()); + }, $this->getMethods()); + } + + /** + * @return array + */ + public function provideMethods() { return array_map(function($value) { return array($value); - }, $this->getMethodNames()); + }, $this->getMethods()); } /** * @return array */ - private function getMethodNames() + private function getMethods() { static $methods; @@ -108,7 +146,7 @@ private function getMethodNames() if (strpos($methodName, '__') === 0) { continue; } - $methods[] = $methodName; + $methods[] = $rcMethod; } return $methods;