Skip to content

Commit e375161

Browse files
committed
minor symfony#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 sebastianbergmann/phpunit-mock-objects#299 (comment) | License | MIT | Doc PR | Commits ------- 542cf6b [2.3] fix mocking of some methods
2 parents a5965fb + 542cf6b commit e375161

File tree

4 files changed

+45
-20
lines changed

4 files changed

+45
-20
lines changed

src/Symfony/Component/HttpKernel/Tests/DependencyInjection/MergeExtensionConfigurationPassTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ public function testAutoloadMainExtension()
1919
{
2020
$container = $this->getMock(
2121
'Symfony\\Component\\DependencyInjection\\ContainerBuilder',
22-
array('getExtensionConfig', 'loadFromExtension', 'getParameterBag')
22+
array(
23+
'getExtensionConfig',
24+
'loadFromExtension',
25+
'getParameterBag',
26+
'getDefinitions',
27+
'getAliases',
28+
'getExtensions',
29+
)
2330
);
2431
$params = $this->getMock('Symfony\\Component\\DependencyInjection\\ParameterBag\\ParameterBag');
2532

src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ public function testSubRequestWithDifferentMethod()
104104
->will($this->returnValue(array()));
105105

106106
$context = new RequestContext();
107-
$requestMatcher->expects($this->any())
108-
->method('getContext')
109-
->will($this->returnValue($context));
110107

111108
$listener = new RouterListener($requestMatcher, new RequestContext());
112109
$listener->onKernelRequest($event);

src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\Response;
17+
use Symfony\Component\HttpKernel\HttpKernelInterface;
1718

1819
/**
1920
* @group time-sensitive
@@ -27,15 +28,11 @@ public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
2728
->getMock();
2829

2930
// does not implement TerminableInterface
30-
$kernelMock = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\HttpKernelInterface')
31-
->disableOriginalConstructor()
32-
->getMock();
33-
34-
$kernelMock->expects($this->never())
35-
->method('terminate');
31+
$kernel = new TestKernel();
32+
$httpCache = new HttpCache($kernel, $storeMock);
33+
$httpCache->terminate(Request::create('/'), new Response());
3634

37-
$kernel = new HttpCache($kernelMock, $storeMock);
38-
$kernel->terminate(Request::create('/'), new Response());
35+
$this->assertFalse($kernel->terminateCalled, 'terminate() is never called if the kernel class does not implement TerminableInterface');
3936

4037
// implements TerminableInterface
4138
$kernelMock = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Kernel')
@@ -1228,3 +1225,17 @@ public function testEsiCacheRemoveValidationHeadersIfEmbeddedResponses()
12281225
$this->assertNull($this->response->getLastModified());
12291226
}
12301227
}
1228+
1229+
class TestKernel implements HttpKernelInterface
1230+
{
1231+
public $terminateCalled = false;
1232+
1233+
public function terminate(Request $request, Response $response)
1234+
{
1235+
$this->terminateCalled = true;
1236+
}
1237+
1238+
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
1239+
{
1240+
}
1241+
}

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -806,13 +806,7 @@ public function testTerminateReturnsSilentlyIfKernelIsNotBooted()
806806
public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
807807
{
808808
// does not implement TerminableInterface
809-
$httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')
810-
->disableOriginalConstructor()
811-
->getMock();
812-
813-
$httpKernelMock
814-
->expects($this->never())
815-
->method('terminate');
809+
$httpKernel = new TestKernel();
816810

817811
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
818812
->disableOriginalConstructor()
@@ -821,11 +815,13 @@ public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
821815

822816
$kernel->expects($this->once())
823817
->method('getHttpKernel')
824-
->will($this->returnValue($httpKernelMock));
818+
->willReturn($httpKernel);
825819

826820
$kernel->setIsBooted(true);
827821
$kernel->terminate(Request::create('/'), new Response());
828822

823+
$this->assertFalse($httpKernel->terminateCalled, 'terminate() is never called if the kernel class does not implement TerminableInterface');
824+
829825
// implements TerminableInterface
830826
$httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernel')
831827
->disableOriginalConstructor()
@@ -903,3 +899,17 @@ protected function getKernelForInvalidLocateResource()
903899
;
904900
}
905901
}
902+
903+
class TestKernel implements HttpKernelInterface
904+
{
905+
public $terminateCalled = false;
906+
907+
public function terminate()
908+
{
909+
$this->terminateCalled = true;
910+
}
911+
912+
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
913+
{
914+
}
915+
}

0 commit comments

Comments
 (0)