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);