1 <?php
2
3 namespace Alo\Test;
4
5 use Alo\Exception\TesterException as TE;
6 use ReflectionClass;
7
8 if(!defined('GEN_START')) {
9 http_response_code(404);
10 die();
11 }
12
13 /**
14 * Tests classes for output or return values
15 *
16 * @author Art <a.molcanovas@gmail.com>
17 * @package TestingSuite
18 * @deprecated Since v1.1
19 */
20 class ClassTester extends AbstractTester {
21
22 /**
23 * The object in testing
24 *
25 * @var mixed
26 */
27 protected $obj;
28
29 /**
30 * Instantiates the tester
31 *
32 * @author Art <a.molcanovas@gmail.com>
33 *
34 * @param mixed $obj Optionally, set the object upon instantiation
35 *
36 * @throws TE When the Supplied object or its reflection/name is invalid.
37 */
38 function __construct($obj = null) {
39 parent::__construct();
40 if($obj) {
41 $this->obj($obj);
42 }
43 }
44
45 /**
46 * If no parameter is passed returns the currently set object, otherwise sets it
47 *
48 * @param null|string|ReflectionClass|mixed $obj The object to set. Either an instance of the object, a
49 * ReflectionClass of the object or the object name including the
50 * namespace
51 *
52 * @return mixed|ClassTester $this if a parameter is passed, the currently tester object otherwise
53 * @throws TE When the Supplied object or its reflection/name is invalid.
54 */
55 function obj($obj = null) {
56 if($obj === null) {
57 return $this->obj;
58 } elseif($obj instanceof ReflectionClass) {
59 $obj = $obj->getName();
60 $this->obj = new $obj;
61 } elseif(is_object($obj)) {
62 $this->obj = $obj;
63 } elseif(is_string($obj)) {
64 $this->obj = new $obj;
65 } else {
66 throw new TE('Supplied object or its reflection/name is invalid.', TE::E_CLASS_INVALID);
67 }
68
69 return $this;
70 }
71
72 /**
73 * Returns the callable parameter for call_user_func_array()
74 *
75 * @author Art <a.molcanovas@gmail.com>
76 *
77 * @param string $name Method name
78 *
79 * @return array
80 */
81 protected function getCallable($name) {
82 return [$this->obj, $name];
83 }
84 }