Test method output

This commit is contained in:
Barry vd. Heuvel
2016-06-08 22:06:05 +02:00
parent 0e84805e37
commit 2d82419167
2 changed files with 44 additions and 5 deletions
+1 -1
View File
@@ -250,7 +250,7 @@ class Method
/** /**
* Get the parameters and format them correctly * Get the parameters and format them correctly
* *
* @param $method * @param \ReflectionMethod $method
* @return array * @return array
*/ */
public function getParameters($method) public function getParameters($method)
+43 -4
View File
@@ -9,11 +9,50 @@ class ExampleTest extends \PHPUnit_Framework_TestCase
*/ */
public function testCanInstantiate() public function testCanInstantiate()
{ {
$class = new \ReflectionClass(Method::class); $reflectionClass = new \ReflectionClass(ExampleClass::class);
$method = new \ReflectionMethod(Method::class, 'getDocComment'); $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;
} }
} }