Search code examples
phpmongodbcontinuous-integrationkohana

Using Mango within a unit test in Kohana


So I'm switching our application to use Mango rather than the built in ORM within Kohana. I've switched over all the necessary application code to work as expected, but when our CI server runs through our unit tests, I get a "Class 'Mango' not found" error.

Tests provided are dumbed down, but the style I use in the UnitTest is exactly the same way I use them in a regular GET request. It works when I do a GET, but the unit test fails. Now hopefully unrelated, I cannot reproduce this locally, but can't ever get the unit test to work on our CI server.

My guess is that I'm not loading the module properly, but like I said, it works correctly in the application and only my unit tests are failing (with FATAL ERRORs).

application/classes/Model/User.php

class Model_User extends Mango {

    protected $_fields = array(
        'user_id'       => array('type' => 'string', 'required'=>TRUE),
        'first_name'    => array('type' => 'string', 'required'=>TRUE),
        'last_name'     => array('type' => 'string', 'required'=>TRUE),
    );
}

application/tests/UserTest.php

Class UserTest extends Unittest_TestCase
{
    public function testUserCreation()
    {
        $user_data = array(
            "user_id"       => "1234asdf",
            "first_name"    => "Test",
            "last_name"     => "User",
        );

        $new_user = Mango::factory("User", $user_data);

        $this->assertEquals($user_data, $new_user->as_array());
    }
}

EDIT: Here's a link to the Mango module I've brought in: https://github.com/Wouterrr/MangoDB


Solution

  • If anyone stumbles upon this via google, I solved the issue. It appears as though our applications nginx config handles capitalizations more nicely than the CLI. Upon changing "Mango" to "mango" I saw the error message change to not finding it's parent class (for the same casing reasons). While I imagine I could have just changed all the casing, Kohana has a function for casing issues, so in application/bootstrap.php, you just have to run both of the following:

    spl_autoload_register(array('Kohana', 'auto_load'));
    spl_autoload_register(array('Kohana', 'auto_load_lowercase'));