\Ke\TestUtilsTestMethod

测试方法实例,以 ReflectionMethod ,来传递需要被测试的方法。

Summary

Methods
Properties
Constants
__construct()
isInvokable()
hasExceptions()
addException()
throwLastException()
getExceptions()
newTestItem()
newTestItems()
invoke()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$object
$refMethod
$exceptions
N/A

Properties

$object

$object : null|string|object

Type

null|string|object — 方法的主体,可以是静态类、对象,或为空

$refMethod

$refMethod : \ReflectionMethod

Type

\ReflectionMethod

$exceptions

$exceptions : array

Type

array

Methods

__construct()

__construct(null  $object = null, \ReflectionMethod|null  $method = null, \Throwable|null  $throwable = null) 

TestMethod 构造函数

Parameters

null $object
\ReflectionMethod|null $method
\Throwable|null $throwable

isInvokable()

isInvokable() : boolean

该测试方法是否可被调用

Returns

boolean

hasExceptions()

hasExceptions() : boolean

该测试方法是否有异常状态

Returns

boolean

addException()

addException(\Throwable  $throwable) : $this

添加一个异常

Parameters

\Throwable $throwable

Returns

$this

throwLastException()

throwLastException() 

如果存在异常,则抛出最后一个异常

getExceptions()

getExceptions() : array

取回测试方法的所有异常

Returns

array

newTestItem()

newTestItem(mixed  $excepted, mixed  $args = null, string|null  $message = null) : \Ke\TestUtils\TestItem

生成一个该测试方法的TestItem。

Parameters

mixed $excepted
mixed $args
string|null $message

Returns

\Ke\TestUtils\TestItem

newTestItems()

newTestItems(array  $items, callable|\Closure|null  $filterItemCallback = null) : array

批量生成测试用例

$filterItemCallback($obj, $index, $item)

  • $obj - 该测试方法的主体(对象或类),实际写回调函数时,为了方便产生代码提示,可以自行在参数前补充类名。
  • $index - 对应的$item的索引(键名)
  • $item - 测试用例(TestItem)实例,与 $obj 一样,可以自行补充类名,以提供代码提示。
$testMethod->newTestItems([], function(AnyClass $obj, $index, TestItem $item) {
    $item->excepted = mb_strtolower($item->excepted);
    if ($index === 2) {
        // ...
    }
});

Parameters

array $items

多个测试用例的数组

callable|\Closure|null $filterItemCallback

过滤每一个测试用例的回调函数

Returns

array

invoke()

invoke(array|null  $args) : mixed

调用该测试方法

Parameters

array|null $args

Returns

mixed