Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing alias @tests #22

Closed
pana1990 opened this issue Jul 27, 2017 · 8 comments

Comments

Projects
None yet
2 participants
@pana1990
Copy link
Contributor

commented Jul 27, 2017

I'm having some drawbacks with fixtures, if i set alias @tests it fix.

How reproduce issue :

1º create migrate post and run
2º create model of post
3º create fixture of post
4º execute yii fixture Post // this raise exception unfound namespace

@pana1990

This comment has been minimized.

Copy link
Contributor Author

commented Jul 30, 2017

@tonydspaniard this issue is not fixed yet. why do you close it?

@tonydspaniard tonydspaniard reopened this Jul 30, 2017

@tonydspaniard

This comment has been minimized.

Copy link
Member

commented Jul 30, 2017

@pana1990 speed reviewing...

@tonydspaniard

This comment has been minimized.

Copy link
Member

commented Jul 30, 2017

@pana1990 when you create a new migration, you should run composer update as it heavily relies on composer autoloader. Have you done the composer update so it recreates its class names?

@pana1990

This comment has been minimized.

Copy link
Contributor Author

commented Jul 31, 2017

i think that the problem is missing @tests alias.

i am going to try again explain the problem :

1º i create fresh project with composer.
2º i create the following migration :

<?php

use yii\db\Migration;

/**
 * Handles the creation of table `post`.
 */
class m170731_035905_create_post_table extends Migration
{
    /**
     * @inheritdoc
     */
    public function up()
    {
        $this->createTable('post', [
            'id' => $this->primaryKey(),
            'title' => $this->string(),
            'content' => $this->text(),
        ]);
    }

    /**
     * @inheritdoc
     */
    public function down()
    {
        $this->dropTable('post');
    }
}

3º run yii migrate // it works.
4º i create the following fixture in tests/fixtures/PostFixture.php

<?php

namespace tests\fixtures;

class PostFixture extends ActiveFixture
{
    public $modelClass = 'app\models\Post';
}

5º i create data to postfixture in tests/fixtures/data/post.php

<?php

return [
    [
        'id' => 1,
        'title' => 'title 1',
        'content' => 'content 1',
    ],
    [
        'id' => 2,
        'title' => 'title 2',
        'content' => 'content 2',
    ],
];

6º i config controllerMap to custom my namespace fixture in config/console/app.php

'controllerMap' => [
        'fixture' => [
            'class' => 'yii\console\controllers\FixtureController',
            'namespace' => 'tests\fixtures',
        ],
    ]

7º i run yii fixture "*" and this command fails :
fails

if i add the following alias it works :

<?php

use SideKit\Config\ConfigKit;
/*
 * --------------------------------------------------------------------------
 * Register custom Yii aliases
 * --------------------------------------------------------------------------
 *
 * As we have changed the structure. Modify default Yii aliases here.
 */
Yii::setAlias('@tests', ConfigKit::config()->getBasePath() . DIRECTORY_SEPARATOR . '../tests');
Yii::setAlias('@root', ConfigKit::config()->getRootPath());
Yii::setAlias('@web', ConfigKit::config()->getBasePath() . DIRECTORY_SEPARATOR . '../public');

Maybe it's better include this alias in config console, can i send pr to fix this issue?

@tonydspaniard

This comment has been minimized.

Copy link
Member

commented Jul 31, 2017

@pana1990 you are totally correct. I don't think the @tests alias could damage anyhow the rest of the app. So I think bootstrap/aliases.php is the best place to add it. Please, proceed (do not forget to add that change on CHANGE_LOG.

Thanks you for your work on this template.

@tonydspaniard

This comment has been minimized.

Copy link
Member

commented Jul 31, 2017

On another note, shouldn't you be using $ ./tests/bin/yii instead?

@pana1990

This comment has been minimized.

Copy link
Contributor Author

commented Jul 31, 2017

if i want to seed my dev db i need to use yii, isn't it?

@tonydspaniard

This comment has been minimized.

Copy link
Member

commented Jul 31, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.