Laravel base_path()给出错误-调用未定义的方法baseDir()

问题描述 投票:1回答:1

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

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。

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

class DataCsvSeedTest extends TestCase
{
   public function setUp()
   {
    $baseDir = base_path();
    print "basedir = ". $baseDir;
   }
}
php laravel laravel-5.5
1个回答
6
投票

啊...这是一个testClass,

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.