PHP Classes

File: tests/Wingu/OctopusCore/EventDispatcher/Tests/TestCase.php

Recommend this page to a friend!
  Classes of Protung Dragos   PHP Event Dispatcher   tests/Wingu/OctopusCore/EventDispatcher/Tests/TestCase.php   Download  
File: tests/Wingu/OctopusCore/EventDispatcher/Tests/TestCase.php
Role: Unit test script
Content type: text/plain
Description:
Class: PHP Event Dispatcher
Register events and call registered listeners
Author: By
Last change: Initial commit
Date: 2 years ago
Size: 1,727 bytes
 

Contents

Class file image Download
<?php

namespace Wingu\OctopusCore\EventDispatcher\Tests;

/**
 * Base class for test cases.
 */
abstract class TestCase extends \PHPUnit_Framework_TestCase {

   
/**
     * This is a helper method to call a private/protected method on an object.
     *
     * @param Object $obj The object with the method.
     * @param string $methodName The name of the method.
     * @param array $args The arguments for the method.
     * @return mixed
     */
   
public function callMethod($obj, $methodName, array $args = array()) {
       
$class = new \ReflectionClass($obj);
       
$method = $class->getMethod($methodName);
       
$method->setAccessible(true);
        return
$method->invokeArgs($obj, $args);
    }

   
/**
     * This is a helper method to set the value of a private/protected property on an object.
     *
     * @param Object $obj The object with the property.
     * @param string $property The name of the property to set.
     * @param mixed $value The value to set.
     */
   
public function setProperty($obj, $property, $value) {
       
$class = new \ReflectionClass($obj);
       
$property = $class->getProperty($property);
       
$property->setAccessible(true);
       
$property->setValue($obj, $value);
    }

   
/**
     * This is a helper method to get the value of a private/protected property on an object.
     *
     * @param Object $obj The object with the property.
     * @param string $property The name of the property to get.
     * @return mixed
     */
   
public function getProperty($obj, $property) {
       
$class = new \ReflectionClass($obj);
       
$property = $class->getProperty($property);
       
$property->setAccessible(true);
        return
$property->getValue($obj);
    }

}