Functional Test Alias


(Scottix) #1

Hi I am trying to create a functional test and failing with one on my images not parsing alias properly.

But all our pages uses aliases and if it can find one then it throws an error.




    <?= Html::img('@tater/img/logo.png', [

        'alt' => 'Tater logo',

    ]);?>






1) loginCept: 

 Test  codeception/functional/pages/loginCept.php

                                                                           

  [yii\base\InvalidParamException] Invalid path alias: @tater/img/logo.png  



Is there anyway to ignore the alias?

Since the output is text only. We don’t need to test the path.


(Jboehnke) #2

Where do you define the path alias @tater?


(Scottix) #3

I have a behavior that registers the asset, actually I think I found the problem.

Since the test stubs the AssetManager class it never publishes the files. This in turn never sets baseUrl in the asset. When I set the alias it is actually NULL.




Yii::setAlias('@tater', $tater_asset->baseUrl);



I can do a work around, but this is poor coding methodology.




        if(YII_ENV_TEST) {

            $tater_asset->baseUrl = '@web/assets/tater';

        }

        Yii::setAlias('@tater', $tater_asset->baseUrl);



Actually after reading some things about the latest versions of codeception it almost feels a little broken with yii2 at the moment. Some more documentation and fixes on how to do proper testing would be appreciative, they seem a bit light and un-intuitive at the moment.