AloFramework documentation
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download

Namespaces

  • Alo
    • Cache
    • Controller
    • Db
    • Exception
    • Session
    • Statics
    • Test
    • Validators
  • Controller
  • None
  • PHP

Classes

  • AbstractTester
  • ClassTester
  • FunctionTester
 1 <?php
 2 
 3    namespace Alo\Test;
 4 
 5    use \ReflectionClass;
 6    use Alo\Exception\TesterException as TE;
 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     */
19    class ClassTester extends AbstractTester {
20 
21       /**
22        * The object in testing
23        *
24        * @var mixed
25        */
26       protected $obj;
27 
28       /**
29        * Instantiates the tester
30        *
31        * @author Art <a.molcanovas@gmail.com>
32        * @param mixed $obj Optionally, set the object upon instantiation
33        */
34       function __construct($obj = null) {
35          parent::__construct();
36          if ($obj) {
37             $this->obj($obj);
38          }
39       }
40 
41       /**
42        * If no parameter is passed returns the currently set object, otherwise sets it
43        *
44        * @param null|string|ReflectionClass|mixed $obj The object to set. Either an instance of the object, a
45        *                                               ReflectionClass of the object or the object name including the
46        *                                               namespace
47        * @return mixed|ClassTester $this if a parameter is passed, the currently tester object otherwise
48        * @throws TE When the Supplied object or its reflection/name is invalid.
49        */
50       function obj($obj = null) {
51          if ($obj === null) {
52             return $this->obj;
53          } elseif ($obj instanceof ReflectionClass) {
54             $obj = $obj->getName();
55             $this->obj = new $obj;
56          } elseif (is_object($obj)) {
57             $this->obj = $obj;
58          } elseif (is_string($obj)) {
59             $this->obj = new $obj;
60          } else {
61             throw new TE('Supplied object or its reflection/name is invalid.', TE::E_CLASS_INVALID);
62          }
63 
64          return $this;
65       }
66 
67       /**
68        * Returns the callable parameter for call_user_func_array()
69        *
70        * @author Art <a.molcanovas@gmail.com>
71        * @param string $name Method name
72        * @return array
73        */
74       protected function getCallable($name) {
75          return [$this->obj, $name];
76       }
77    }
AloFramework documentation API documentation generated by ApiGen 2.8.0