snowair/think-phpunit

请问如何测试controller 中的private,protected方法呢?

Closed this issue · 1 comments

xnzj commented

namespace Home\Controller;

$method = new \ReflectionMethod('ArticleController', 'category');
$method->setAccessible(true);
我使用反射老是提示
ReflectionException: Class ArticleController does not exist

xnzj commented

已经找到方法了
public function testCategory()
{
$A = new ArticleController();
$method = new \ReflectionMethod($A, 'category');
$method->setAccessible(true);
$res = $method->invoke($A, 1);
$this->assertCount(25,$res);
}