Working with codeception and laravel

こ雲淡風輕ζ 提交于 2019-12-06 14:48:38

You'll have to choose if you want WebDriver or Laravel4 as your "browser", unfortunately you cannot have both and this might be the source of your problems. If you need Javascript, you probably will need to keep WebDriver and loose some Laravel functionalities, but not much, in my opinion. And if you really need Laravel, this is a helper I created to get it inside _support/FunctionalHelper:

public function getLaravel4()
{
    if ( ! isset($this->laravel4))
    {
        $this->laravel4 = (new \Codeception\Module\Laravel4());

        $this->laravel4->kernel = app();
    }

    return $this->laravel4;
}

So in your test you just need to:

$L = $I->getLaravel4();

But, remember, since Laravel is not your browser, things like:

$L->amOnRoute('login');

Will not work, but you'll be able to do things not related to browsing, like:

$L->seeRecord('users', [
    'email' => 'a@b.com',
    'first_name' => 'a',
    'last_name' => 'b'
]);

Also, you can boot laravel on your _bootstrap file:

include __DIR__ . '/../vendor/autoload.php';
$app = require_once __DIR__ . '/../bootstrap/start.php';
$app->boot();

And have direct access to the IoC container:

$app = app();

$app['config']->get('...');

Or even Facades:

DB::table('users')->...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!