我在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你的解決方案工作,但你能解釋爲什麼我必須定義整個命名空間? –