Tutorial by Examples

Reflection is often used as part of software testing, such as for the runtime creation/instantiation of mock objects. It's also great for inspecting the state of an object at any given point in time. Here's an example of using Reflection in a unit test to verify a protected class member contains the...
Feature detection of classes can partly be done with the property_exists and method_exists functions. class MyClass { public $public_field; protected $protected_field; private $private_field; static $static_field; const CONSTANT = 0; public function public_function() {...
Sometimes it's useful to test private & protected methods as well as public ones. class Car { /** * @param mixed $argument * * @return mixed */ protected function drive($argument) { return $argument; } /** * @return bool *...

Page 1 of 1