functional Codeception test unable to use componets like cache or solr

Hey,

I have set up codeception unit tests, which works on an simple example test.

Now I tried to build an simple functional test, which looks for an headline on an startpage. The test works on an dummy startpage, where I simply echo some HTML code.

But my "real" application page contains memcache-elements and an solr search.

If I run my functional test, like this:


class StartPageCest

{

    public function _before(\FunctionalTester $I)

    {

        $I->amOnPage(['site/index']);

    }

    public function _after(\FunctionalTester $I)

    {

    }

    public function tryToTest(\FunctionalTester $I)

    {

        $I->see('Hallo', 'h2');  

    }

}

I get the Error


[Error] Call to a member function get() on null

on the following line of the actionIndex:


$result = Yii::$app->cache->get('site_index_result');

It looks like, the cache component is not available on codeception runtime. If I remove that line, the test stops with an similar error near the solr call.

My application config is in …config/web.php (basic template) and my test-config includes this application-config:




$config =  yii\helpers\ArrayHelper::merge(

    

        require(__DIR__ . '/web.php'),

      

    [

        'id' => 'app-tests',  

    ]

);


return $config;

Any idea, why caching object is not available during functional codeception test?

Thank you.

Check acceptance.suite.yml, probably you need something like this:

actor: AcceptanceTester
modules:
    enabled:
        - Yii2:
            part: [orm,cache]

For functional/unit tests, replace ‘acceptance’ as you need. I had similar issues when trying to access the DB.