From d9be1b4cc49dccd283e8fa89c44a43c789399538 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 25 Mar 2016 10:13:40 +0100 Subject: [PATCH] fix mocks * check for existance of `setMetadataFactory()` method (this is needed for tests run with deps=high as the method was removed in Symfony 3.0) * fix mock testing the `EngineInterface` as the `stream()` method cannot be mocked when it is does not exist in the mocked interface --- phpunit | 2 +- .../Validator/ValidatorExtensionTest.php | 9 ++++--- .../Tests/Firewall/SwitchUserListenerTest.php | 2 +- .../Templating/Tests/DelegatingEngineTest.php | 25 ++++++++++++++++--- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/phpunit b/phpunit index 413e7d0ba4..d2da42616d 100755 --- a/phpunit +++ b/phpunit @@ -11,7 +11,7 @@ */ // Please update when phpunit needs to be reinstalled with fresh deps: -// Cache-Id-Version: 2016-03-23 14:50 UTC +// Cache-Id-Version: 2016-03-25 09:45 UTC use Symfony\Component\Process\ProcessUtils; diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php index 63bf5913a1..74a1705622 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Form\Tests\Extension\Validator; use Symfony\Component\Form\Extension\Validator\ValidatorExtension; +use Symfony\Component\Validator\ValidatorInterface; class ValidatorExtensionTest extends \PHPUnit_Framework_TestCase { @@ -38,9 +39,11 @@ class ValidatorExtensionTest extends \PHPUnit_Framework_TestCase ->method('addPropertyConstraint') ->with('children', $this->isInstanceOf('Symfony\Component\Validator\Constraints\Valid')); - $validator - ->expects($this->never()) - ->method('getMetadataFactory'); + if ($validator instanceof ValidatorInterface) { + $validator + ->expects($this->never()) + ->method('getMetadataFactory'); + } $extension = new ValidatorExtension($validator); $guesser = $extension->loadTypeGuesser(); diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php index bcba3c29f7..f43b564322 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php @@ -55,7 +55,7 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase $this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue(null)); $this->event->expects($this->never())->method('setResponse'); - $this->securityContext->expects($this->never())->method('setToken'); + $this->tokenStorage->expects($this->never())->method('setToken'); $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager); $listener->handle($this->event); diff --git a/src/Symfony/Component/Templating/Tests/DelegatingEngineTest.php b/src/Symfony/Component/Templating/Tests/DelegatingEngineTest.php index 3d7f2d0573..368723c884 100644 --- a/src/Symfony/Component/Templating/Tests/DelegatingEngineTest.php +++ b/src/Symfony/Component/Templating/Tests/DelegatingEngineTest.php @@ -66,10 +66,7 @@ class DelegatingEngineTest extends \PHPUnit_Framework_TestCase */ public function testStreamRequiresStreamingEngine() { - $engine = $this->getEngineMock('template.php', true); - $engine->expects($this->never())->method('stream'); - - $delegatingEngine = new DelegatingEngine(array($engine)); + $delegatingEngine = new DelegatingEngine(array(new TestEngine())); $delegatingEngine->stream('template.php', array('foo' => 'bar')); } @@ -155,3 +152,23 @@ class DelegatingEngineTest extends \PHPUnit_Framework_TestCase interface MyStreamingEngine extends StreamingEngineInterface, EngineInterface { } + +class TestEngine implements EngineInterface +{ + public function render($name, array $parameters = array()) + { + } + + public function exists($name) + { + } + + public function supports($name) + { + return true; + } + + public function stream() + { + } +}