Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Unit Testing and Model Inheritance
  • I'm running Fuel 1.5, using the 1.5 orm package to run my models. I implemented a controller test in app/tests/controller, but when I tried to run my test with php oil test, I get the following error:

    $ php oil test
    [...]
    Tests Running...This may take a few moments.
    [...]
    PHP Fatal error:  Access level to Fuel\Core\Model_Crud::primary_key() must be public (as in class Orm\Model) in /[...]/fuel/core/classes/model/crud.php on line 15
    PHP Stack trace:[...]

    Trying to debug it, I went into /fuel/core/classes/model/crud.php (Model_Crud). I noticed that when I change 'extends \Model' to 'extends Model', my unit tests work as expected.

    It seems that Fuel is deciding somewhere in the Fuel/Core namespace that '\Model' maps to orm\Model instead of Fuel/Core/Model. Is there a way I can fix this and run my unit tests without editing core code?
  • I find this very odd.

    FuelPHP aliases all core classes to the global namespace (hence the use of the \ prefix everywhere), but the ORM package namespace isn't.

    So all I can think of is something in your code somewhere that does this. Do you have the ORM package loaded?
  • Yes, the package is loaded in Fuel/app/config/config.php. 

    return array(
    [...], 
    'always_load => array(
    'packages' => array(
    'orm',
    [...]
    ), 
    [...]
    ), 
    [...]
    );
  • What does

    class_exist('Model', false)

    return before you define your model tests?

    If it returns true, you can use this to check which file defines the class:

    $class = new ReflectionClass('Model');
    var_dump($class->getFileName());

    It could be that a previous test in the run has defined a class called 'Model', which collides with your tests.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion