Reputation: 1244
I'm trying to test a service which takes the Symfony\Component\HttpKernel\Kernel
as a dependency.
This is what i do in order to mock the kernel.
$this->kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
$this->kernel->expects($this->any())
->method('getEnvironment')
->will($this->returnValue('dev'));
When i run the test, i get something as the following error.
Fatal error: Cannot redeclare static foo\foo\WebTestCase::$kernel as non static foo\foo\MyTest::$kernel in ...
Any ideas why?
Upvotes: 0
Views: 844
Reputation: 3900
Read the error message carefully. WebTestCase::$kernel
is a static variable, which means you cannot access it with $this
. An attempt to override it as an instance variable causes this error.
Besides, WebTestCase
class is not meant to be a base class for unit tests where you mock the kernel. It's a class that facilitates writing functional tests, which is why the real kernel is injected into this static variable. If you want to write a unit test and mock the kernel, use the usual TestCase
class from PHPUnit.
Upvotes: 2