How to test email in functional test (Symfony2)

折月煮酒 提交于 2019-12-03 13:55:35

The exception is being thrown because getProfile() returns false if the profiler is not enabled. see here.

public function getProfile()
{
    if (!$this->kernel->getContainer()->has('profiler')) {
        return false;
    }

    return $this->kernel->getContainer()->get('profiler')->loadProfileFromResponse($this->response);
}

Furthermore enableProfiler()only enables the profiler if it is registered with the service-container aka enabled. see here.

public function enableProfiler()
{
    if ($this->kernel->getContainer()->has('profiler')) {
        $this->profiler = true;
    }
}

Now you have to make sure the profiler is enabled in the test environment. ( should normally be the default setting )

config_test.yml

framework:
   profiler:
       enabled: true

You could add something like this to your test:

$this->assertEquals($this->kernel->getContainer()->has('profiler'), true);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!