我有一個幫助文件helper.php
,我保留了一些輔助函數。laravel phpunit testcase中的undefined helper函數
//helper.php
function isAuthLiked($authLikedPosts, $post)
{
return !! Auth::check() && $authLikedPosts->contains('id', $post->id);
}
現在在我的測試案例中,我寫道:
$this->assertTrue(isAuthLiked($authrenominations, $post[0]));
當我運行測試時,我得到的錯誤:
Fatal error: Call to undefined function isAuthLiked() in C:\wamp\www\Nom7\tests\integration\UserTest.php on line 304
我已經添加的輔助文件compose.json自動加載。但問題依然存在。
"autoload": {
"classmap": [
"database",
"app/Http/Controllers",
"app/Models"
],
"files":[
"app/helper.php"
],
"psr-4": {
"App\\": "app/",
"Acme\\": "app/Acme/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
],
"files":[
"app/helper.php"
]
},
您可以發佈您的composer.json嗎? – schellingerht
@Schellingerht:已添加。 – user1012181
可以在測試之外使用該功能嗎? – schellingerht