我在Codera上运行Laravel 5中的一些功能测试。调用未定义的方法Session :: has()在Laravel 5 + Codeception功能测试中
下面是一个样本测试
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class HomePageTestCest
{
use WithoutMiddleware;
public function _before(FunctionalTester $I)
{
//some setup to run
}
public function _after(FunctionalTester $I)
{
}
// tests
public function tryToTest(FunctionalTester $I)
{
$I->wantToTest('If i can go to home page without errors');
$I->amOnPage('/');
$I->canSee('WELCOME TO HOMEPAGE');
}
}
但我得到下面的错误运行测试时:
Fatal error: Call to undefined method Session::has() in /var/www/laravel5/storage/framework/views/e7953b3ce9b90e51d4cfdb279790953bbe25dc9a.php on line 225
而且在线路225我有:
<?php if(Session::has('someKey')): ?>
//some html code
<?php endif; ?>
我想问题在于会话驱动程序。我也尝试实施this,但没有任何改变。
希望能得到一些帮助。提前致谢。
写完整的命名空间为:'Illuminate \ Support \ Facades \ Session :: has('something')' – hamedmehryar
是否需要专门为功能测试编写完整的命名空间? –
@hamedmehryar你的解决方案工作,但你能解释为什么我必须定义整个命名空间? –