1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHPUnitでprivateでstaticなメソッドとプロパティを呼び出すUtility関数

Posted at

こんなのをTestsディレクトリ以下において呼び出せばいい。


<?php
class Test_Utils_Util
{
    /**
     * privateなstaticメソッドを呼び出します
     */
    public static function invoke_private_static_method($class_name, $method_name, $args_arr) 
    {
        $test_class = new ReflectionClass($class_name);
        $method = $test_class->getMethod($method_name);
        $method->setAccessible(true);
        $method->invokeArgs(null, $args);
    }
    
    /**
     * privateなstaticプロパティを呼び出します
     */
    public static function get_private_static_prop($class_name, $prop_name) {
        $test_class = new ReflectionClass($class_name);
        $prop = $test_class->getProperty($prop_name);
        $prop->setAccessible(true);
        return $prop->getValue();
    }
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?