Im using Codeception in Yii2 to accept acceptance tests and there is no way to access my models because namespaces do not work in these tests.
I have it in my tests /_bootstrap.php
require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
$config = require(__DIR__ . '/../console/config/main.php');
$application = new yii\console\Application( $config );
Yii::setAlias('@tests', dirname(__DIR__));
This is in my console / config / main
<?php
$params = array_merge(
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
return [
'id' => 'app-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'console\controllers',
'components' => [
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
],
'params' => $params,
];
<?php
return [
'adminEmail' => 'admin@example.com',
'supportEmail' => 'support@example.com',
'user.passwordResetTokenExpire' => 3600,
];
And this is one of the wannabe tests:
<?php namespace tests\acceptance;
use \AcceptanceTester;
use backend\models\User;
class ListUserCest
{
public function _before(AcceptanceTester $I)
{
}
public function _after(AcceptanceTester $I)
{
}
public function init(AcceptanceTester $I)
{
$this->login($I);
if( User::find()->exists() )
$I->amGoingTo('List Users having at least one');
else
$I->amGoingTo('List Users having any');
}
...
I get this error when running tests:
PHP Fatal error: class 'backend \ models \ User' not found in /var/www/project/tests/acceptance/ListUserCest.php on line 21 Error: class 'backend \ models \ User' not found
Please help me, I tried everything I know.
EDIT
( , vitalik_74) , , \Yii , -, .
, \backend\models\User, Yii:: $app- > (, , ).
User - ActiveRecord , , Labels , getProfile().
<?php
namespace backend\models;
use common\helpers\MathHelper;
use backend\models\AntropometricData;
use Yii;
class User extends \yii\db\ActiveRecord
{
public static function tableName()
{
return 'user';
}
...