【发布时间】:2016-08-04 14:30:37
【问题描述】:
我在 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 您的解决方案有效,但您能解释一下为什么我必须定义整个命名空间吗??
-
可能
Session未列在app.php配置文件的aliases数组中。 -
不,我检查并列出了它。 Config::get() 也一样。
标签: php session laravel-5.2 codeception php-5.6