From 2d8241916732ee7d7b8edb523104ef9853ff9a67 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 8 Jun 2016 22:06:05 +0200 Subject: [PATCH] Test method output --- src/Method.php | 2 +- tests/MethodTest.php | 47 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/Method.php b/src/Method.php index d64eb60..ac02640 100644 --- a/src/Method.php +++ b/src/Method.php @@ -250,7 +250,7 @@ class Method /** * Get the parameters and format them correctly * - * @param $method + * @param \ReflectionMethod $method * @return array */ public function getParameters($method) diff --git a/tests/MethodTest.php b/tests/MethodTest.php index 69dba1b..6f1976e 100644 --- a/tests/MethodTest.php +++ b/tests/MethodTest.php @@ -9,11 +9,50 @@ class ExampleTest extends \PHPUnit_Framework_TestCase */ public function testCanInstantiate() { - $class = new \ReflectionClass(Method::class); - $method = new \ReflectionMethod(Method::class, 'getDocComment'); + $reflectionClass = new \ReflectionClass(ExampleClass::class); + $reflectionMethod = $reflectionClass->getMethod('setName'); - $obj = new Method($method, 'Method', $class); + $method = new Method($reflectionMethod, 'Example', $reflectionClass); - $this->assertInstanceOf(Method::class, $obj); + $this->assertInstanceOf(Method::class, $method); + } + + /** + * Test the output of a class + */ + public function testOutput() + { + $reflectionClass = new \ReflectionClass(ExampleClass::class); + $reflectionMethod = $reflectionClass->getMethod('setName'); + + $method = new Method($reflectionMethod, 'Example', $reflectionClass); + + $output = '/** + * + * + * @param string $last + * @param string $first + * @static + */'; + $this->assertEquals($output, $method->getDocComment('')); + $this->assertEquals('setName', $method->getName()); + $this->assertEquals('\\'.ExampleClass::class, $method->getDeclaringClass()); + $this->assertEquals('$last, $first', $method->getParams(true)); + $this->assertEquals(['$last', '$first'], $method->getParams(false)); + $this->assertEquals('$last, $first = \'Barry\'', $method->getParamsWithDefault(true)); + $this->assertEquals(['$last', '$first = \'Barry\''], $method->getParamsWithDefault(false)); + $this->assertEquals(true, $method->shouldReturn()); + } +} + +class ExampleClass +{ + /** + * @param string $last + * @param string $first + */ + public function setName($last, $first = 'Barry') + { + return; } } \ No newline at end of file