Skip to content

Commit

Permalink
Test method output
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh committed Jun 8, 2016
1 parent 0e84805 commit 2d82419
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function shouldReturn()
/**
* Get the parameters and format them correctly
*
* @param $method
* @param \ReflectionMethod $method
* @return array
*/
public function getParameters($method)
Expand Down
47 changes: 43 additions & 4 deletions tests/MethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 2d82419

Please sign in to comment.