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:
Tobias Schultze 2016-03-24 00:07:02 +01:00
commit e375161784
4 changed files with 45 additions and 20 deletions

View File

@ -19,7 +19,14 @@ class MergeExtensionConfigurationPassTest extends \PHPUnit_Framework_TestCase
{
$container = $this->getMock(
'Symfony\\Component\\DependencyInjection\\ContainerBuilder',
array('getExtensionConfig', 'loadFromExtension', 'getParameterBag')
array(
'getExtensionConfig',
'loadFromExtension',
'getParameterBag',
'getDefinitions',
'getAliases',
'getExtensions',
)
);
$params = $this->getMock('Symfony\\Component\\DependencyInjection\\ParameterBag\\ParameterBag');

View File

@ -104,9 +104,6 @@ class RouterListenerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(array()));
$context = new RequestContext();
$requestMatcher->expects($this->any())
->method('getContext')
->will($this->returnValue($context));
$listener = new RouterListener($requestMatcher, new RequestContext());
$listener->onKernelRequest($event);

View File

@ -14,6 +14,7 @@ namespace Symfony\Component\HttpKernel\Tests\HttpCache;
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/**
* @group time-sensitive
@ -27,15 +28,11 @@ class HttpCacheTest extends HttpCacheTestCase
->getMock();
// does not implement TerminableInterface
$kernelMock = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\HttpKernelInterface')
->disableOriginalConstructor()
->getMock();
$kernel = new TestKernel();
$httpCache = new HttpCache($kernel, $storeMock);
$httpCache->terminate(Request::create('/'), new Response());
$kernelMock->expects($this->never())
->method('terminate');
$kernel = new HttpCache($kernelMock, $storeMock);
$kernel->terminate(Request::create('/'), new Response());
$this->assertFalse($kernel->terminateCalled, 'terminate() is never called if the kernel class does not implement TerminableInterface');
// implements TerminableInterface
$kernelMock = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Kernel')
@ -1228,3 +1225,17 @@ class HttpCacheTest extends HttpCacheTestCase
$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)
{
}
}

View File

@ -806,13 +806,7 @@ EOF;
public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
{
// does not implement TerminableInterface
$httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')
->disableOriginalConstructor()
->getMock();
$httpKernelMock
->expects($this->never())
->method('terminate');
$httpKernel = new TestKernel();
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->disableOriginalConstructor()
@ -821,11 +815,13 @@ EOF;
$kernel->expects($this->once())
->method('getHttpKernel')
->will($this->returnValue($httpKernelMock));
->willReturn($httpKernel);
$kernel->setIsBooted(true);
$kernel->terminate(Request::create('/'), new Response());
$this->assertFalse($httpKernel->terminateCalled, 'terminate() is never called if the kernel class does not implement TerminableInterface');
// implements TerminableInterface
$httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernel')
->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)
{
}
}