mardi 7 juillet 2015

Undefined method error in ReflectionClass but method exists

I am currently using phpunit for some unit testing. Due to the presence of some protected methods, I had to use a Reflection Class to change the visibility of these methods to public.

The initial methods were called successfully but somehow it gets stuck at a specific method:

Fatal error: Call to undefined method ReflectionClass::create_schema()in
/vagrant/fuelphp/fuel/app/tests/model/repository/jobpost.php on line 54

However, dumping the method via get_method() with var_dump proves that it exists in the class instance:

class ReflectionMethod#2317 (2) {
  public $name =>
  string(13) 'create_schema'
  public $class =>
  string(34) 'Model_Repository_Feed'
}

Then the real confusing bit, I decided to use hasMethod() to see if the method exists:

 52     echo "If this says 1, class exists: ".$this->_target->hasMethod('create_schema');
 53     try {
 54         $this->_target->create_schema();
 55     }

The result when running says, "yes it exists.... but it doesn't":

If this says 1, class exists: 1
Fatal error: Call to undefined method ReflectionClass::create_schema() in /vagrant/fuelphp/fuel/app/tests/model/repository/jobpost.php on line 54

To clarify this method is public and is inherited from an abstract parent class:

public function create_schema() {
    $this->create_schema_exec(self::$_real_schema_name);
  }

How can this issue be solved?





Aucun commentaire:

Enregistrer un commentaire