dimanche 24 janvier 2016

modelsManager not set in Phalcon Unittest

I'm integrating PHPUnit in my Phalcon project. I had it running correctly in MAMP, but when I run phpunit on my server, I keep getting some errors.

This is UnitTestCase:

<?php

use \Phalcon\Di;
use \Phalcon\DI\FactoryDefault;
use \Phalcon\Test\UnitTestCase as PhalconTestCase;

use \Phalcon\Mvc\View;
use \Phalcon\Crypt;
use \Phalcon\Mvc\Dispatcher;
use \Phalcon\Mvc\Dispatcher as PhDispatcher;
use \Phalcon\Mvc\Url as UrlResolver;
use \Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
use \Phalcon\Mvc\View\Engine\Volt as VoltEngine;
use \Phalcon\Mvc\Model\Metadata\Files as MetaDataAdapter;
use \Phalcon\Session\Adapter\Files as SessionAdapter;
use \Phalcon\Flash\Direct as Flash;
use \Phalcon\Logger;
use \Phalcon\Events\Manager as EventsManager;
use \Phalcon\Logger\Adapter\File as LoggerFile;
use \Phalcon\Mvc\Model\Manager as ModelsManager;


abstract class UnitTestCase extends PhalconTestCase
{
    /**
     * @var \Voice\Cache
     */
    protected $_cache;

    /**
     * @var \Phalcon\Config
     */
    protected $_config;

    /**
     * @var bool
     */
    private $_loaded = false;

    public function setUp(Phalcon\DiInterface $di = NULL, Phalcon\Config $config = NULL)
    {
        // Load any additional services that might be required during testing
        $di = new FactoryDefault();

        DI::reset();

        $config = include APP_DIR . '/config/config.php';

        /**
         * The URL component is used to generate all kind of urls in the application
         */
        $di->set('url', function () use ($config) {
            $url = new UrlResolver();
            $url->setBaseUri($config->application->baseUri);
            return $url;
        }, true);

        /**
         * Setting up the view component
         */
        $di->set('view', function () use ($config) {

            $view = new View();

            $view->setViewsDir($config->application->viewsDir);

            $view->registerEngines(array(
                '.volt' => function ($view, $di) use ($config) {

                    $volt = new VoltEngine($view, $di);

                    $volt->setOptions(array(
                        'compiledPath' => $config->application->cacheDir . 'volt/',
                        'compiledSeparator' => '_'
                    ));

                    return $volt;
                }
            ));

            return $view;
        }, true);

        ...and some more...

        $di->set(
            'modelsManager',
            function()
            {
                return new \Phalcon\Mvc\Model\Manager();
            }
        );

        parent::setUp($di, $config);

        $this->_loaded = true;
    }

    /**
     * Check if the test case is setup properly
     *
     * @throws \PHPUnit_Framework_IncompleteTestError;
     */
    public function __destruct()
    {
        if (!$this->_loaded) {
            throw new \PHPUnit_Framework_IncompleteTestError('Please run parent::setUp().');
        }
    }
}

So, when I run this on my local machine, this works fine. When I run it on the server, it throws:

Phalcon\Di\Exception: Service 'modelsManager' wasn't found in the dependency injection container

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire