Laravel base_path()给出错误-调用未定义的方法baseDir() [英] Laravel base_path() gives error - Call to undefined method baseDir()

查看:329
本文介绍了Laravel base_path()给出错误-调用未定义的方法baseDir()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个测试器类,我正在尝试使用全局帮助器方法 base_path(),但是出现以下错误:

I have a tester class and I'm trying to use the global helper method base_path(), but I get the error below:

Error: Call to undefined method Illuminate\Container\Container::basePath()
/myproject/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:182
/myproject/tests/Feature/DataCsvSeedTest.php:31
/myproject/vendor/phpunit/phpunit/src/TextUI/Command.php:195
/myproject/vendor/phpunit/phpunit/src/TextUI/Command.php:148

类似Laravel中的helper.php调用basePath(),但找不到它.我是否缺少全局助手功能的名称空间或其他设置?使用Laravel 5.5.

Looks like helper.php in Laravel calls basePath(), and can't find it. Am I missing a namespace or some other setting for the global helper functions? Using Laravel 5.5.

<?php    
namespace Tests\Feature;
use Tests\TestCase;

class DataCsvSeedTest extends TestCase
{
   public function setUp()
   {
    $baseDir = base_path();
    print "basedir = ". $baseDir;
   }
}

推荐答案

啊...这是一个testClass,

Ah... This is a testClass,

class DataCsvSeedTest extends TestCase
{
   public function setUp()
   {
     parent::setUp();

     $baseDir = base_path();
     print "basedir = ". $baseDir;
   }
}

当您重载 setUp()方法时,请不要忘记调用 parent :: Setup(),它将引导应用程序.

when you are overriding setUp() method don't forget to call the parent::Setup(), which will bootstrap the application.

这篇关于Laravel base_path()给出错误-调用未定义的方法baseDir()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆