mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
Test method output
This commit is contained in:
+1
-1
@@ -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
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user