Skip to content

Commit

Permalink
[2.3] fix mocking of some methods
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Mar 23, 2016
1 parent a5965fb commit 542cf6b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 20 deletions.
Expand Up @@ -19,7 +19,14 @@ public function testAutoloadMainExtension()
{
$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');

Expand Down
Expand Up @@ -104,9 +104,6 @@ public function testSubRequestWithDifferentMethod()
->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);
Expand Down
27 changes: 19 additions & 8 deletions src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;

/**
* @group time-sensitive
Expand All @@ -27,15 +28,11 @@ public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
->getMock();

// does not implement TerminableInterface
$kernelMock = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\HttpKernelInterface')
->disableOriginalConstructor()
->getMock();

$kernelMock->expects($this->never())
->method('terminate');
$kernel = new TestKernel();
$httpCache = new HttpCache($kernel, $storeMock);
$httpCache->terminate(Request::create('/'), new Response());

$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')
Expand Down Expand Up @@ -1228,3 +1225,17 @@ public function testEsiCacheRemoveValidationHeadersIfEmbeddedResponses()
$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)
{
}
}
26 changes: 18 additions & 8 deletions src/Symfony/Component/HttpKernel/Tests/KernelTest.php
Expand Up @@ -806,13 +806,7 @@ public function testTerminateReturnsSilentlyIfKernelIsNotBooted()
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()
Expand All @@ -821,11 +815,13 @@ public function testTerminateDelegatesTerminationOnlyForTerminableInterface()

$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()
Expand Down Expand Up @@ -903,3 +899,17 @@ protected function getKernelForInvalidLocateResource()
;
}
}

class TestKernel implements HttpKernelInterface
{
public $terminateCalled = false;

public function terminate()
{
$this->terminateCalled = true;
}

public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
{
}
}

0 comments on commit 542cf6b

Please sign in to comment.