-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTestingWrapper.php
More file actions
47 lines (43 loc) · 1.07 KB
/
TestingWrapper.php
File metadata and controls
47 lines (43 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* Created by PhpStorm.
* User: ryuji
* Date: 15/06/18
* Time: 18:43
*/
/**
* Class TestingWrapper privateやprotectedメソッドをテストできるようにするラッパー
*/
class TestingWrapper {
/**
* @var Instance ラップする元インスタンス
*/
protected $_wrappedInstance;
/**
* constructor
*
* @param Instance $wrappedInstance ラップする元インスタンス
* @return TestingWrapper
*/
public function __construct($wrappedInstance) {
$this->_wrappedInstance = $wrappedInstance;
}
/**
* __call
*
* @param string $methodName メソッド名
* @param array $params パラメータ
* @return mixed
*/
public function __call($methodName, $params) {
if (substr($methodName, 0, 9) === '_testing_') {
$callName = substr($methodName, 9);
$method = new ReflectionMethod($this->_wrappedInstance, $callName);
$method->setAccessible(true);
$result = $method->invokeArgs($this->_wrappedInstance, $params);
return $result;
} else {
return call_user_func_array(array($this->_wrappedInstance, $methodName), $params);
}
}
}