apiframework / test
测试编写工具。
0.0.1
2014-07-07 10:57 UTC
Requires
- php: >=5.3.0
Suggests
- apiframework/test: Test writing utilities.
This package is not auto-updated.
Last update: 2024-09-24 05:46:02 UTC
README
测试编写工具
Apiframework\Test\ProtectedReflection
允许轻松测试受保护的方法和属性。
invokeMethod - 执行受保护的方法
class Robot { protected $cache = []; public function addToCache($key, $value) { $this->cache[$key] = $value; } protected function helloTwo($one, $two) { return "hello $one $two"; } } $robot = new Robot; $protected = (new Apiframework\Test\ProtectedReflectionFactory)->build($robot); // Accepts an array of arguments equal to the amount of arguments of the method $helloTwo = $protected->invokeMethod("helloTwo", ['varOne', 'varTwo']); var_dump($helloTwo);
输出
string(19) "hello varOne varTwo"
getProperty - 获取类的受保护属性
$protected->invokeMethod("addToCache", ['david', 'bowie']); $cache = $protected->getProperty("cache"); var_dump($cache);
输出
array(1) {
'david' =>
string(5) "bowie"
}
setProperty - 设置受保护属性
$protected->setProperty("cache", ['fab' => 'four']); $cache = $protected->getProperty("cache"); var_dump($cache);
输出
array(1) {
'fab' =>
string(4) "four"
}