minor #18284 [2.3] fix mocking of some methods (xabbuh)
This PR was merged into the 2.3 branch.
Discussion
----------
[2.3] fix mocking of some methods
| Q | A
| ------------- | ---
| Branch? | 2.3
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? |no
| Tests pass? | yes
| Fixed tickets | items 3, 4, 5, and 7 of https://github.com/sebastianbergmann/phpunit-mock-objects/issues/299#issuecomment-200443756
| License | MIT
| Doc PR |
Commits
-------
542cf6b
[2.3] fix mocking of some methods
This commit is contained in:
commit
e375161784
@ -19,7 +19,14 @@ class MergeExtensionConfigurationPassTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$container = $this->getMock(
|
$container = $this->getMock(
|
||||||
'Symfony\\Component\\DependencyInjection\\ContainerBuilder',
|
'Symfony\\Component\\DependencyInjection\\ContainerBuilder',
|
||||||
array('getExtensionConfig', 'loadFromExtension', 'getParameterBag')
|
array(
|
||||||
|
'getExtensionConfig',
|
||||||
|
'loadFromExtension',
|
||||||
|
'getParameterBag',
|
||||||
|
'getDefinitions',
|
||||||
|
'getAliases',
|
||||||
|
'getExtensions',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
$params = $this->getMock('Symfony\\Component\\DependencyInjection\\ParameterBag\\ParameterBag');
|
$params = $this->getMock('Symfony\\Component\\DependencyInjection\\ParameterBag\\ParameterBag');
|
||||||
|
|
||||||
|
@ -104,9 +104,6 @@ class RouterListenerTest extends \PHPUnit_Framework_TestCase
|
|||||||
->will($this->returnValue(array()));
|
->will($this->returnValue(array()));
|
||||||
|
|
||||||
$context = new RequestContext();
|
$context = new RequestContext();
|
||||||
$requestMatcher->expects($this->any())
|
|
||||||
->method('getContext')
|
|
||||||
->will($this->returnValue($context));
|
|
||||||
|
|
||||||
$listener = new RouterListener($requestMatcher, new RequestContext());
|
$listener = new RouterListener($requestMatcher, new RequestContext());
|
||||||
$listener->onKernelRequest($event);
|
$listener->onKernelRequest($event);
|
||||||
|
@ -14,6 +14,7 @@ namespace Symfony\Component\HttpKernel\Tests\HttpCache;
|
|||||||
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
|
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group time-sensitive
|
* @group time-sensitive
|
||||||
@ -27,15 +28,11 @@ class HttpCacheTest extends HttpCacheTestCase
|
|||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
// does not implement TerminableInterface
|
// does not implement TerminableInterface
|
||||||
$kernelMock = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\HttpKernelInterface')
|
$kernel = new TestKernel();
|
||||||
->disableOriginalConstructor()
|
$httpCache = new HttpCache($kernel, $storeMock);
|
||||||
->getMock();
|
$httpCache->terminate(Request::create('/'), new Response());
|
||||||
|
|
||||||
$kernelMock->expects($this->never())
|
$this->assertFalse($kernel->terminateCalled, 'terminate() is never called if the kernel class does not implement TerminableInterface');
|
||||||
->method('terminate');
|
|
||||||
|
|
||||||
$kernel = new HttpCache($kernelMock, $storeMock);
|
|
||||||
$kernel->terminate(Request::create('/'), new Response());
|
|
||||||
|
|
||||||
// implements TerminableInterface
|
// implements TerminableInterface
|
||||||
$kernelMock = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Kernel')
|
$kernelMock = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Kernel')
|
||||||
@ -1228,3 +1225,17 @@ class HttpCacheTest extends HttpCacheTestCase
|
|||||||
$this->assertNull($this->response->getLastModified());
|
$this->assertNull($this->response->getLastModified());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TestKernel implements HttpKernelInterface
|
||||||
|
{
|
||||||
|
public $terminateCalled = false;
|
||||||
|
|
||||||
|
public function terminate(Request $request, Response $response)
|
||||||
|
{
|
||||||
|
$this->terminateCalled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -806,13 +806,7 @@ EOF;
|
|||||||
public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
|
public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
|
||||||
{
|
{
|
||||||
// does not implement TerminableInterface
|
// does not implement TerminableInterface
|
||||||
$httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')
|
$httpKernel = new TestKernel();
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$httpKernelMock
|
|
||||||
->expects($this->never())
|
|
||||||
->method('terminate');
|
|
||||||
|
|
||||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
|
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
@ -821,11 +815,13 @@ EOF;
|
|||||||
|
|
||||||
$kernel->expects($this->once())
|
$kernel->expects($this->once())
|
||||||
->method('getHttpKernel')
|
->method('getHttpKernel')
|
||||||
->will($this->returnValue($httpKernelMock));
|
->willReturn($httpKernel);
|
||||||
|
|
||||||
$kernel->setIsBooted(true);
|
$kernel->setIsBooted(true);
|
||||||
$kernel->terminate(Request::create('/'), new Response());
|
$kernel->terminate(Request::create('/'), new Response());
|
||||||
|
|
||||||
|
$this->assertFalse($httpKernel->terminateCalled, 'terminate() is never called if the kernel class does not implement TerminableInterface');
|
||||||
|
|
||||||
// implements TerminableInterface
|
// implements TerminableInterface
|
||||||
$httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernel')
|
$httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernel')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
@ -903,3 +899,17 @@ EOF;
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TestKernel implements HttpKernelInterface
|
||||||
|
{
|
||||||
|
public $terminateCalled = false;
|
||||||
|
|
||||||
|
public function terminate()
|
||||||
|
{
|
||||||
|
$this->terminateCalled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user