dpchen2004
2018-01-26 09:42
浏览 171
已采纳

找不到环境变量:运行phpunit时出现“DATABASE_URL”[重复]

This question already has an answer here:

I have implemented a simple test to check whether a page is displayed in my application:

namespace App\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class MyControllerTest extends WebTestCase
{
    public function testMyAction()
    {
        $client = static::createClient();
        $client->request('GET', '/');
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
    }
}

When I run php vendor/phpunit/phpunit/phpunit, I get the following error message:

1) App\Tests\Controller\MyControllerTest::testMyAction
Symfony\Component\DependencyInjection\Exception\EnvNotFoundException:
Environment variable not found: "DATABASE_URL".

Yet, this variable is available in .env. How can I solve this?

</div>

图片转代码服务由CSDN问答提供 功能建议

此问题已经存在 这里有一个答案:

  • Symfony4:Doctrine2工作但PHPUnit测试中没有连接(内核启动) 1回答

    我已经实施了 检查页面是否显示在我的应用程序中的简单测试:

      namespace App \ Tests \ Controller; 
     
    use Symfony \ Bundle \ FrameworkBundle \ Test \ WebTestCase; 
      
    class MyControllerTest扩展了WebTestCase 
     {
    公共函数testMyAction()
     {
     $ client = static :: createClient(); 
     $ client-&gt; request('GET','/'); 
      $ this-&gt; assertEquals(200,$ client-&gt; get  Response() - &gt; getStatusCode()); 
    } 
    } 
       
     
     

    当我运行php vendor / phpunit / phpunit / phpunit时,我得到以下内容 错误消息:

      1)App \ Tests \ Controller \ MyControllerTest :: testMyAction 
    Symfony \ Component \ DependencyInjection \ Exception \ EnvNotFoundException:
    找不到环境变量:“DATABASE_URL”。  
       
     
     

    然而,此变量在 .env 中可用。 我怎么解决这个问题?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题