Codeception / YiiBridge

Wrapper classes required to run Yii functional tests with Codeception
MIT License
21 stars 18 forks source link

Class 'CMap' not found in config/test.php on line 3 #8

Closed ua2004 closed 9 years ago

ua2004 commented 9 years ago

I installed Codeception 1.8 and YiiBridge following the instructions. This is my index-test.php:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Definitions
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
defined('YII_DEBUG') or define('YII_DEBUG',true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

// Load the config files
$config = require __DIR__.DS.'protected'.DS.'config'.DS.'test.php';

// Load Yii and Composer extensions
require_once __DIR__.DS.'vendor'.DS.'yiisoft'.DS.'yii'.DS.'framework'.DS.'yii.php';
require_once __DIR__.DS.'vendor'.DS.'autoload.php';

// Return for Codeception
return array(
    'class' => 'CWebApplication',
    'config' => $config,
);

Here is config/test.php:

<?php

return CMap::mergeArray(
    require(dirname(__FILE__).'/main.php'),
    array(
        'components'=>array(
            'request' => array(
                'class' => 'CodeceptionHttpRequest'
            ),
            'fixture'=>array(
                'class'=>'system.test.CDbFixtureManager',
            ),
            /* uncomment the following to provide test database connection
            'db'=>array(
                'connectionString'=>'DSN for test database',
            ),
            */
        ),
    )
);

Of course, I have imported CodeceptionHttpRequest class in config/main.test. But whenever I run any tests (unit or acceptance) I get the following error:

Fatal error: Class 'CMap' not found in config/test.php on line 3
ua2004 commented 9 years ago

OK, I simply took line 11 in index-test.php and inserted it after line 15:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Definitions
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
defined('YII_DEBUG') or define('YII_DEBUG',true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

// Load Yii and Composer extensions
require_once __DIR__.DS.'vendor'.DS.'yiisoft'.DS.'yii'.DS.'framework'.DS.'yii.php';
require_once __DIR__.DS.'vendor'.DS.'autoload.php';

// Load the config files
$config = require __DIR__.DS.'protected'.DS.'config'.DS.'test.php';

// Return for Codeception
return array(
    'class' => 'CWebApplication',
    'config' => $config,
);

Now CMap class is loaded automatically before config/test.php file is included.