fixed obsolete getMock() usage

This commit is contained in:
Fabien Potencier 2016-12-19 16:48:05 +01:00
parent 84e75a78b3
commit 0f9a7287c3
37 changed files with 184 additions and 204 deletions

View File

@ -180,12 +180,12 @@ class EntityUserProviderTest extends \PHPUnit_Framework_TestCase
public function testLoadUserByUserNameShouldLoadUserWhenProperInterfaceProvided()
{
$repository = $this->getMock('\Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface');
$repository = $this->getMockBuilder('\Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface')->getMock();
$repository->expects($this->once())
->method('loadUserByUsername')
->with('name')
->willReturn(
$this->getMock('\Symfony\Component\Security\Core\User\UserInterface')
$this->getMockBuilder('\Symfony\Component\Security\Core\User\UserInterface')->getMock()
);
$provider = new EntityUserProvider(
@ -201,7 +201,7 @@ class EntityUserProviderTest extends \PHPUnit_Framework_TestCase
*/
public function testLoadUserByUserNameShouldDeclineInvalidInterface()
{
$repository = $this->getMock('\Symfony\Component\Security\Core\User\AdvancedUserInterface');
$repository = $this->getMockBuilder('\Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock();
$provider = new EntityUserProvider(
$this->getManager($this->getObjectManager($repository)),

View File

@ -33,12 +33,12 @@ class ControllerTest extends TestCase
$requestStack = new RequestStack();
$requestStack->push($request);
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
return new Response($request->getRequestFormat().'--'.$request->getLocale());
}));
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->at(0))->method('get')->will($this->returnValue($requestStack));
$container->expects($this->at(1))->method('get')->will($this->returnValue($kernel));
@ -84,7 +84,7 @@ class ControllerTest extends TestCase
*/
public function testGetUserWithEmptyContainer()
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container
->expects($this->once())
->method('has')
@ -104,13 +104,13 @@ class ControllerTest extends TestCase
*/
private function getContainerWithTokenStorage($token = null)
{
$tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage');
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage')->getMock();
$tokenStorage
->expects($this->once())
->method('getToken')
->will($this->returnValue($token));
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container
->expects($this->once())
->method('has')
@ -128,10 +128,10 @@ class ControllerTest extends TestCase
public function testIsGranted()
{
$authorizationChecker = $this->getMock('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface');
$authorizationChecker = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface')->getMock();
$authorizationChecker->expects($this->once())->method('isGranted')->willReturn(true);
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->at(0))->method('has')->will($this->returnValue(true));
$container->expects($this->at(1))->method('get')->will($this->returnValue($authorizationChecker));
@ -146,10 +146,10 @@ class ControllerTest extends TestCase
*/
public function testdenyAccessUnlessGranted()
{
$authorizationChecker = $this->getMock('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface');
$authorizationChecker = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface')->getMock();
$authorizationChecker->expects($this->once())->method('isGranted')->willReturn(false);
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->at(0))->method('has')->will($this->returnValue(true));
$container->expects($this->at(1))->method('get')->will($this->returnValue($authorizationChecker));
@ -164,7 +164,7 @@ class ControllerTest extends TestCase
$twig = $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock();
$twig->expects($this->once())->method('render')->willReturn('bar');
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->at(0))->method('has')->will($this->returnValue(false));
$container->expects($this->at(1))->method('has')->will($this->returnValue(true));
$container->expects($this->at(2))->method('get')->will($this->returnValue($twig));
@ -180,7 +180,7 @@ class ControllerTest extends TestCase
$twig = $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock();
$twig->expects($this->once())->method('render')->willReturn('bar');
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->at(0))->method('has')->will($this->returnValue(false));
$container->expects($this->at(1))->method('has')->will($this->returnValue(true));
$container->expects($this->at(2))->method('get')->will($this->returnValue($twig));
@ -195,7 +195,7 @@ class ControllerTest extends TestCase
{
$twig = $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock();
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->at(0))->method('has')->will($this->returnValue(false));
$container->expects($this->at(1))->method('has')->will($this->returnValue(true));
$container->expects($this->at(2))->method('get')->will($this->returnValue($twig));
@ -208,10 +208,10 @@ class ControllerTest extends TestCase
public function testRedirectToRoute()
{
$router = $this->getMock('Symfony\Component\Routing\RouterInterface');
$router = $this->getMockBuilder('Symfony\Component\Routing\RouterInterface')->getMock();
$router->expects($this->once())->method('generate')->willReturn('/foo');
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->at(0))->method('get')->will($this->returnValue($router));
$controller = new TestController();
@ -226,10 +226,10 @@ class ControllerTest extends TestCase
public function testAddFlash()
{
$flashBag = new FlashBag();
$session = $this->getMock('Symfony\Component\HttpFoundation\Session\Session');
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')->getMock();
$session->expects($this->once())->method('getFlashBag')->willReturn($flashBag);
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->at(0))->method('has')->will($this->returnValue(true));
$container->expects($this->at(1))->method('get')->will($this->returnValue($session));
@ -249,10 +249,10 @@ class ControllerTest extends TestCase
public function testIsCsrfTokenValid()
{
$tokenManager = $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface');
$tokenManager = $this->getMockBuilder('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')->getMock();
$tokenManager->expects($this->once())->method('isTokenValid')->willReturn(true);
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->at(0))->method('has')->will($this->returnValue(true));
$container->expects($this->at(1))->method('get')->will($this->returnValue($tokenManager));
@ -264,10 +264,10 @@ class ControllerTest extends TestCase
public function testGenerateUrl()
{
$router = $this->getMock('Symfony\Component\Routing\RouterInterface');
$router = $this->getMockBuilder('Symfony\Component\Routing\RouterInterface')->getMock();
$router->expects($this->once())->method('generate')->willReturn('/foo');
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->at(0))->method('get')->will($this->returnValue($router));
$controller = new Controller();
@ -288,10 +288,10 @@ class ControllerTest extends TestCase
public function testRenderViewTemplating()
{
$templating = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
$templating = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')->getMock();
$templating->expects($this->once())->method('render')->willReturn('bar');
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->at(0))->method('has')->willReturn(true);
$container->expects($this->at(1))->method('get')->will($this->returnValue($templating));
@ -303,10 +303,10 @@ class ControllerTest extends TestCase
public function testRenderTemplating()
{
$templating = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
$templating = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')->getMock();
$templating->expects($this->once())->method('renderResponse')->willReturn(new Response('bar'));
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->at(0))->method('has')->willReturn(true);
$container->expects($this->at(1))->method('get')->will($this->returnValue($templating));
@ -318,9 +318,9 @@ class ControllerTest extends TestCase
public function testStreamTemplating()
{
$templating = $this->getMock('Symfony\Component\Routing\RouterInterface');
$templating = $this->getMockBuilder('Symfony\Component\Routing\RouterInterface')->getMock();
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->at(0))->method('has')->willReturn(true);
$container->expects($this->at(1))->method('get')->will($this->returnValue($templating));
@ -339,12 +339,12 @@ class ControllerTest extends TestCase
public function testCreateForm()
{
$form = $this->getMock('Symfony\Component\Form\FormInterface');
$form = $this->getMockBuilder('Symfony\Component\Form\FormInterface')->getMock();
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
$formFactory = $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock();
$formFactory->expects($this->once())->method('create')->willReturn($form);
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->at(0))->method('get')->will($this->returnValue($formFactory));
$controller = new Controller();
@ -355,12 +355,12 @@ class ControllerTest extends TestCase
public function testCreateFormBuilder()
{
$formBuilder = $this->getMock('Symfony\Component\Form\FormBuilderInterface');
$formBuilder = $this->getMockBuilder('Symfony\Component\Form\FormBuilderInterface')->getMock();
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
$formFactory = $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock();
$formFactory->expects($this->once())->method('createBuilder')->willReturn($formBuilder);
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->at(0))->method('get')->will($this->returnValue($formFactory));
$controller = new Controller();
@ -371,9 +371,9 @@ class ControllerTest extends TestCase
public function testGetDoctrine()
{
$doctrine = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
$doctrine = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->at(0))->method('has')->will($this->returnValue(true));
$container->expects($this->at(1))->method('get')->will($this->returnValue($doctrine));

View File

@ -24,11 +24,8 @@ class ConfigCachePassTest extends \PHPUnit_Framework_TestCase
'checker_3' => array(),
);
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');
$container = $this->getMock(
'Symfony\Component\DependencyInjection\ContainerBuilder',
array('findTaggedServiceIds', 'getDefinition', 'hasDefinition')
);
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'getDefinition', 'hasDefinition'))->getMock();
$container->expects($this->atLeastOnce())
->method('findTaggedServiceIds')
@ -52,11 +49,8 @@ class ConfigCachePassTest extends \PHPUnit_Framework_TestCase
public function testThatCheckersCanBeMissing()
{
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');
$container = $this->getMock(
'Symfony\Component\DependencyInjection\ContainerBuilder',
array('findTaggedServiceIds')
);
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();
$container->expects($this->atLeastOnce())
->method('findTaggedServiceIds')

View File

@ -30,7 +30,7 @@ class PropertyInfoPassTest extends \PHPUnit_Framework_TestCase
new Reference('n3'),
);
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder', array('findTaggedServiceIds'));
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();
$container->expects($this->any())
->method('findTaggedServiceIds')
@ -51,7 +51,7 @@ class PropertyInfoPassTest extends \PHPUnit_Framework_TestCase
public function testReturningEmptyArrayWhenNoService()
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder', array('findTaggedServiceIds'));
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();
$container->expects($this->any())
->method('findTaggedServiceIds')

View File

@ -19,19 +19,17 @@ class UnusedTagsPassTest extends \PHPUnit_Framework_TestCase
{
$pass = new UnusedTagsPass();
$formatter = $this->getMock('Symfony\Component\DependencyInjection\Compiler\LoggingFormatter');
$formatter = $this->getMockBuilder('Symfony\Component\DependencyInjection\Compiler\LoggingFormatter')->getMock();
$formatter
->expects($this->at(0))
->method('format')
->with($pass, 'Tag "kenrel.event_subscriber" was defined on service(s) "foo", "bar", but was never used. Did you mean "kernel.event_subscriber"?')
;
$compiler = $this->getMock('Symfony\Component\DependencyInjection\Compiler\Compiler');
$compiler = $this->getMockBuilder('Symfony\Component\DependencyInjection\Compiler\Compiler')->getMock();
$compiler->expects($this->once())->method('getLoggingFormatter')->will($this->returnValue($formatter));
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder',
array('findTaggedServiceIds', 'getCompiler', 'findUnusedTags', 'findTags')
);
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'getCompiler', 'findUnusedTags', 'findTags'))->getMock();
$container->expects($this->once())->method('getCompiler')->will($this->returnValue($compiler));
$container->expects($this->once())
->method('findTags')

View File

@ -17,7 +17,7 @@ class TemplateIteratorTest extends TestCase
{
public function testGetIterator()
{
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')->getMock();
$bundle->expects($this->any())->method('getName')->will($this->returnValue('BarBundle'));
$bundle->expects($this->any())->method('getPath')->will($this->returnValue(__DIR__.'/Fixtures/templates/BarBundle'));

View File

@ -33,7 +33,7 @@ class ExportCommandTest extends \PHPUnit_Framework_TestCase
;
$helperSet = new HelperSet();
$helper = $this->getMock('Symfony\Component\Console\Helper\FormatterHelper');
$helper = $this->getMockBuilder('Symfony\Component\Console\Helper\FormatterHelper')->getMock();
$helper->expects($this->any())->method('formatSection');
$helperSet->set($helper, 'formatter');
@ -56,7 +56,7 @@ class ExportCommandTest extends \PHPUnit_Framework_TestCase
$profiler->expects($this->once())->method('loadProfile')->with('TOKEN')->will($this->returnValue($profile));
$helperSet = new HelperSet();
$helper = $this->getMock('Symfony\Component\Console\Helper\FormatterHelper');
$helper = $this->getMockBuilder('Symfony\Component\Console\Helper\FormatterHelper')->getMock();
$helper->expects($this->any())->method('formatSection');
$helperSet->set($helper, 'formatter');

View File

@ -32,7 +32,7 @@ class ImportCommandTest extends \PHPUnit_Framework_TestCase
$profiler->expects($this->once())->method('import')->will($this->returnValue(new Profile('TOKEN')));
$helperSet = new HelperSet();
$helper = $this->getMock('Symfony\Component\Console\Helper\FormatterHelper');
$helper = $this->getMockBuilder('Symfony\Component\Console\Helper\FormatterHelper')->getMock();
$helper->expects($this->any())->method('formatSection');
$helperSet->set($helper, 'formatter');

View File

@ -44,7 +44,7 @@ class ResourceCheckerConfigCacheTest extends \PHPUnit_Framework_TestCase
public function testCacheIsNotFreshIfEmpty()
{
$checker = $this->getMock('\Symfony\Component\Config\ResourceCheckerInterface')
$checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock()
->expects($this->never())->method('supports');
/* If there is nothing in the cache, it needs to be filled (and thus it's not fresh).
@ -75,7 +75,7 @@ class ResourceCheckerConfigCacheTest extends \PHPUnit_Framework_TestCase
public function testIsFreshWithchecker()
{
$checker = $this->getMock('\Symfony\Component\Config\ResourceCheckerInterface');
$checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock();
$checker->expects($this->once())
->method('supports')
@ -93,7 +93,7 @@ class ResourceCheckerConfigCacheTest extends \PHPUnit_Framework_TestCase
public function testIsNotFreshWithchecker()
{
$checker = $this->getMock('\Symfony\Component\Config\ResourceCheckerInterface');
$checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock();
$checker->expects($this->once())
->method('supports')
@ -111,7 +111,7 @@ class ResourceCheckerConfigCacheTest extends \PHPUnit_Framework_TestCase
public function testCacheIsNotFreshWhenUnserializeFails()
{
$checker = $this->getMock('\Symfony\Component\Config\ResourceCheckerInterface');
$checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock();
$cache = new ResourceCheckerConfigCache($this->cacheFile, array($checker));
$cache->write('foo', array(new FileResource(__FILE__)));

View File

@ -435,7 +435,7 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
$bootLogger->log($expectedLog[0], $expectedLog[1], $expectedLog[2]);
$mockLogger = $this->getMock('Psr\Log\LoggerInterface');
$mockLogger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$mockLogger->expects($this->once())
->method('log')
->with(LogLevel::WARNING, 'Foo message', $expectedLog[2]);

View File

@ -75,7 +75,7 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
public function testGetListenerPriorityReturnsZeroWhenWrappedMethodDoesNotExist()
{
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
$traceableEventDispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
$traceableEventDispatcher->addListener('foo', function () {}, 123);
$listeners = $traceableEventDispatcher->getListeners('foo');

View File

@ -19,7 +19,7 @@ class TrimListenerTest extends \PHPUnit_Framework_TestCase
public function testTrim()
{
$data = ' Foo! ';
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
$form = $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
$event = new FormEvent($form, $data);
$filter = new TrimListener();
@ -31,7 +31,7 @@ class TrimListenerTest extends \PHPUnit_Framework_TestCase
public function testTrimSkipNonStrings()
{
$data = 1234;
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
$form = $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
$event = new FormEvent($form, $data);
$filter = new TrimListener();

View File

@ -18,17 +18,17 @@ class DependencyInjectionExtensionTest extends \PHPUnit_Framework_TestCase
{
public function testGetTypeExtensions()
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$typeExtension1 = $this->getMock('Symfony\Component\Form\FormTypeExtensionInterface');
$typeExtension1 = $this->getMockBuilder('Symfony\Component\Form\FormTypeExtensionInterface')->getMock();
$typeExtension1->expects($this->any())
->method('getExtendedType')
->willReturn('test');
$typeExtension2 = $this->getMock('Symfony\Component\Form\FormTypeExtensionInterface');
$typeExtension2 = $this->getMockBuilder('Symfony\Component\Form\FormTypeExtensionInterface')->getMock();
$typeExtension2->expects($this->any())
->method('getExtendedType')
->willReturn('test');
$typeExtension3 = $this->getMock('Symfony\Component\Form\FormTypeExtensionInterface');
$typeExtension3 = $this->getMockBuilder('Symfony\Component\Form\FormTypeExtensionInterface')->getMock();
$typeExtension3->expects($this->any())
->method('getExtendedType')
->willReturn('other');
@ -61,9 +61,9 @@ class DependencyInjectionExtensionTest extends \PHPUnit_Framework_TestCase
*/
public function testThrowExceptionForInvalidExtendedType()
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$typeExtension = $this->getMock('Symfony\Component\Form\FormTypeExtensionInterface');
$typeExtension = $this->getMockBuilder('Symfony\Component\Form\FormTypeExtensionInterface')->getMock();
$typeExtension->expects($this->any())
->method('getExtendedType')
->willReturn('unmatched');

View File

@ -109,7 +109,7 @@ class FormValidatorTest extends AbstractConstraintValidatorTest
public function testValidateIfParentWithCascadeValidation()
{
$object = $this->getMock('\stdClass');
$object = $this->getMockBuilder('\stdClass')->getMock();
$parent = $this->getBuilder('parent', null, array('cascade_validation' => true))
->setCompound(true)
@ -131,7 +131,7 @@ class FormValidatorTest extends AbstractConstraintValidatorTest
public function testValidateIfChildWithValidConstraint()
{
$object = $this->getMock('\stdClass');
$object = $this->getMockBuilder('\stdClass')->getMock();
$parent = $this->getBuilder('parent')
->setCompound(true)

View File

@ -54,10 +54,10 @@ class ValidationListenerTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$this->factory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
$this->validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
$this->violationMapper = $this->getMock('Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapperInterface');
$this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
$this->factory = $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock();
$this->validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\ValidatorInterface')->getMock();
$this->violationMapper = $this->getMockBuilder('Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapperInterface')->getMock();
$this->listener = new ValidationListener($this->validator, $this->violationMapper);
$this->message = 'Message';
$this->messageTemplate = 'Message template';
@ -87,7 +87,7 @@ class ValidationListenerTest extends \PHPUnit_Framework_TestCase
private function getMockForm()
{
return $this->getMock('Symfony\Component\Form\Test\FormInterface');
return $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
}
// More specific mapping tests can be found in ViolationMapperTest
@ -183,7 +183,7 @@ class ValidationListenerTest extends \PHPUnit_Framework_TestCase
public function testValidatorInterfaceSinceSymfony25()
{
// Mock of ValidatorInterface since apiVersion 2.5
$validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
$validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\ValidatorInterface')->getMock();
$listener = new ValidationListener($validator, $this->violationMapper);
$this->assertAttributeSame($validator, 'validator', $listener);
@ -195,7 +195,7 @@ class ValidationListenerTest extends \PHPUnit_Framework_TestCase
public function testValidatorInterfaceUntilSymfony24()
{
// Mock of ValidatorInterface until apiVersion 2.4
$validator = $this->getMock('Symfony\Component\Validator\ValidatorInterface');
$validator = $this->getMockBuilder('Symfony\Component\Validator\ValidatorInterface')->getMock();
$listener = new ValidationListener($validator, $this->violationMapper);
$this->assertAttributeSame($validator, 'validator', $listener);

View File

@ -20,7 +20,7 @@ abstract class TypeTestCase extends BaseTypeTestCase
protected function setUp()
{
$this->validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
$this->validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\ValidatorInterface')->getMock();
$metadata = $this->getMockBuilder('Symfony\Component\Validator\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
$this->validator->expects($this->once())->method('getMetadataFor')->will($this->returnValue($metadata));

View File

@ -56,8 +56,8 @@ class ValidatorExtensionTest extends \PHPUnit_Framework_TestCase
*/
public function test2Dot4ValidationApi()
{
$factory = $this->getMock('Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface');
$validator = $this->getMock('Symfony\Component\Validator\ValidatorInterface');
$factory = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface')->getMock();
$validator = $this->getMockBuilder('Symfony\Component\Validator\ValidatorInterface')->getMock();
$metadata = $this->getMockBuilder('Symfony\Component\Validator\Mapping\ClassMetadata')
->disableOriginalConstructor()
->getMock();

View File

@ -51,7 +51,7 @@ class ValidatorTypeGuesserTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->metadata = new ClassMetadata(self::TEST_CLASS);
$this->metadataFactory = $this->getMock('Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface');
$this->metadataFactory = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface')->getMock();
$this->metadataFactory->expects($this->any())
->method('getMetadataFor')
->with(self::TEST_CLASS)

View File

@ -26,7 +26,7 @@ class FormFactoryBuilderTest extends \PHPUnit_Framework_TestCase
$this->registry = $factory->getProperty('registry');
$this->registry->setAccessible(true);
$this->guesser = $this->getMock('Symfony\Component\Form\FormTypeGuesserInterface');
$this->guesser = $this->getMockBuilder('Symfony\Component\Form\FormTypeGuesserInterface')->getMock();
$this->type = new LegacyFooType();
}

View File

@ -63,9 +63,9 @@ class FormRegistryTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->resolvedTypeFactory = $this->getMock('Symfony\Component\Form\ResolvedFormTypeFactory');
$this->guesser1 = $this->getMock('Symfony\Component\Form\FormTypeGuesserInterface');
$this->guesser2 = $this->getMock('Symfony\Component\Form\FormTypeGuesserInterface');
$this->resolvedTypeFactory = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormTypeFactory')->getMock();
$this->guesser1 = $this->getMockBuilder('Symfony\Component\Form\FormTypeGuesserInterface')->getMock();
$this->guesser2 = $this->getMockBuilder('Symfony\Component\Form\FormTypeGuesserInterface')->getMock();
$this->extension1 = new TestExtension($this->guesser1);
$this->extension2 = new TestExtension($this->guesser2);
$this->registry = new FormRegistry(array(
@ -305,7 +305,7 @@ class FormRegistryTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expectedGuesser, $this->registry->getTypeGuesser());
$registry = new FormRegistry(
array($this->getMock('Symfony\Component\Form\FormExtensionInterface')),
array($this->getMockBuilder('Symfony\Component\Form\FormExtensionInterface')->getMock()),
$this->resolvedTypeFactory
);

View File

@ -69,9 +69,9 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$this->factory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
$this->dataMapper = $this->getMock('Symfony\Component\Form\DataMapperInterface');
$this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
$this->factory = $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock();
$this->dataMapper = $this->getMockBuilder('Symfony\Component\Form\DataMapperInterface')->getMock();
$this->parentType = $this->getMockFormType();
$this->type = $this->getMockFormType();
$this->extension1 = $this->getMockFormTypeExtension();
@ -127,7 +127,7 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
{
$givenOptions = array('a' => 'a_custom', 'c' => 'c_custom');
$resolvedOptions = array('a' => 'a_custom', 'b' => 'b_default', 'c' => 'c_custom', 'd' => 'd_default');
$optionsResolver = $this->getMock('Symfony\Component\OptionsResolver\OptionsResolverInterface');
$optionsResolver = $this->getMockBuilder('Symfony\Component\OptionsResolver\OptionsResolverInterface')->getMock();
$this->resolvedType = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormType')
->setConstructorArgs(array($this->type, array($this->extension1, $this->extension2), $this->parentResolvedType))
@ -155,7 +155,7 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
{
$givenOptions = array('data_class' => 'Foo');
$resolvedOptions = array('data_class' => '\stdClass');
$optionsResolver = $this->getMock('Symfony\Component\OptionsResolver\OptionsResolverInterface');
$optionsResolver = $this->getMockBuilder('Symfony\Component\OptionsResolver\OptionsResolverInterface')->getMock();
$this->resolvedType = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormType')
->setConstructorArgs(array($this->type, array($this->extension1, $this->extension2), $this->parentResolvedType))
@ -194,7 +194,7 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
};
$options = array('a' => 'Foo', 'b' => 'Bar');
$builder = $this->getMock('Symfony\Component\Form\Test\FormBuilderInterface');
$builder = $this->getMockBuilder('Symfony\Component\Form\Test\FormBuilderInterface')->getMock();
// First the form is built for the super type
$this->parentType->expects($this->once())
@ -224,7 +224,7 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
public function testCreateView()
{
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
$form = $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
$view = $this->resolvedType->createView($form);
@ -234,8 +234,8 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
public function testCreateViewWithParent()
{
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
$parentView = $this->getMock('Symfony\Component\Form\FormView');
$form = $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
$parentView = $this->getMockBuilder('Symfony\Component\Form\FormView')->getMock();
$view = $this->resolvedType->createView($form, $parentView);
@ -246,8 +246,8 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
public function testBuildView()
{
$options = array('a' => '1', 'b' => '2');
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
$view = $this->getMock('Symfony\Component\Form\FormView');
$form = $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
$view = $this->getMockBuilder('Symfony\Component\Form\FormView')->getMock();
$test = $this;
$i = 0;
@ -290,8 +290,8 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
public function testFinishView()
{
$options = array('a' => '1', 'b' => '2');
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
$view = $this->getMock('Symfony\Component\Form\FormView');
$form = $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
$view = $this->getMockBuilder('Symfony\Component\Form\FormView')->getMock();
$test = $this;
$i = 0;
@ -393,7 +393,7 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
public function testBlockPrefixDefaultsToNameIfSet()
{
// Type without getBlockPrefix() method
$type = $this->getMock('Symfony\Component\Form\FormTypeInterface');
$type = $this->getMockBuilder('Symfony\Component\Form\FormTypeInterface')->getMock();
$type->expects($this->once())
->method('getName')
@ -431,7 +431,7 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
*/
private function getMockFormType($typeClass = 'Symfony\Component\Form\AbstractType')
{
return $this->getMock($typeClass, array('getName', 'getBlockPrefix', 'configureOptions', 'finishView', 'buildView', 'buildForm'));
return $this->getMockBuilder($typeClass)->setMethods(array('getName', 'getBlockPrefix', 'configureOptions', 'finishView', 'buildView', 'buildForm'))->getMock();
}
/**
@ -439,7 +439,7 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
*/
private function getMockFormTypeExtension()
{
return $this->getMock('Symfony\Component\Form\AbstractTypeExtension', array('getExtendedType', 'configureOptions', 'finishView', 'buildView', 'buildForm'));
return $this->getMockBuilder('Symfony\Component\Form\AbstractTypeExtension')->setMethods(array('getExtendedType', 'configureOptions', 'finishView', 'buildView', 'buildForm'))->getMock();
}
/**
@ -447,7 +447,7 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
*/
private function getMockFormFactory()
{
return $this->getMock('Symfony\Component\Form\FormFactoryInterface');
return $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock();
}
/**

View File

@ -23,11 +23,7 @@ class ProcessFailedExceptionTest extends \PHPUnit_Framework_TestCase
*/
public function testProcessFailedExceptionThrowsException()
{
$process = $this->getMock(
'Symfony\Component\Process\Process',
array('isSuccessful'),
array('php')
);
$process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(array('isSuccessful'))->setConstructorArgs(array('php'))->getMock();
$process->expects($this->once())
->method('isSuccessful')
->will($this->returnValue(true));
@ -53,11 +49,7 @@ class ProcessFailedExceptionTest extends \PHPUnit_Framework_TestCase
$errorOutput = 'FATAL: Unexpected error';
$workingDirectory = getcwd();
$process = $this->getMock(
'Symfony\Component\Process\Process',
array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled', 'getWorkingDirectory'),
array($cmd)
);
$process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled', 'getWorkingDirectory'))->setConstructorArgs(array($cmd));
$process->expects($this->once())
->method('isSuccessful')
->will($this->returnValue(false));
@ -105,11 +97,7 @@ class ProcessFailedExceptionTest extends \PHPUnit_Framework_TestCase
$exitText = 'General error';
$workingDirectory = getcwd();
$process = $this->getMock(
'Symfony\Component\Process\Process',
array('isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput', 'getWorkingDirectory'),
array($cmd)
);
$process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(array('isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput', 'getWorkingDirectory'))->setConstructorArgs(array($cmd))->getMock();
$process->expects($this->once())
->method('isSuccessful')
->will($this->returnValue(false));

View File

@ -20,8 +20,8 @@ class RouteCollectionBuilderTest extends \PHPUnit_Framework_TestCase
{
public function testImport()
{
$resolvedLoader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
$resolver = $this->getMock('Symfony\Component\Config\Loader\LoaderResolverInterface');
$resolvedLoader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$resolver = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderResolverInterface')->getMock();
$resolver->expects($this->once())
->method('resolve')
->with('admin_routing.yml', 'yaml')
@ -38,7 +38,7 @@ class RouteCollectionBuilderTest extends \PHPUnit_Framework_TestCase
->with('admin_routing.yml', 'yaml')
->will($this->returnValue($expectedCollection));
$loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
$loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$loader->expects($this->any())
->method('getResolver')
->will($this->returnValue($resolver));
@ -89,7 +89,7 @@ class RouteCollectionBuilderTest extends \PHPUnit_Framework_TestCase
$importedCollection->add('imported_route1', new Route('/imported/foo1'));
$importedCollection->add('imported_route2', new Route('/imported/foo2'));
$loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
$loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
// make this loader able to do the import - keeps mocking simple
$loader->expects($this->any())
->method('supports')
@ -252,7 +252,7 @@ class RouteCollectionBuilderTest extends \PHPUnit_Framework_TestCase
public function testFlushSetsPrefixedWithMultipleLevels()
{
$loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
$loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$routes = new RouteCollectionBuilder($loader);
$routes->add('homepage', 'MainController::homepageAction', 'homepage');

View File

@ -20,14 +20,14 @@ class AnonymousAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$provider = $this->getProvider('foo');
$this->assertTrue($provider->supports($this->getSupportedToken('foo')));
$this->assertFalse($provider->supports($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')));
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
}
public function testAuthenticateWhenTokenIsNotSupported()
{
$provider = $this->getProvider('foo');
$this->assertNull($provider->authenticate($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')));
$this->assertNull($provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
}
/**
@ -50,7 +50,7 @@ class AnonymousAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
protected function getSupportedToken($secret)
{
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken', array('getSecret'), array(), '', false);
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken')->setMethods(array('getSecret'))->disableOriginalConstructor()->getMock();
$token->expects($this->any())
->method('getSecret')
->will($this->returnValue($secret))

View File

@ -27,9 +27,9 @@ class LdapBindAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
*/
public function testEmptyPasswordShouldThrowAnException()
{
$userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
$ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
$ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
$reflection = new \ReflectionMethod($provider, 'checkAuthentication');
@ -44,14 +44,14 @@ class LdapBindAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
*/
public function testBindFailureShouldThrowAnException()
{
$userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
$ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
$userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
$ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
$ldap
->expects($this->once())
->method('bind')
->will($this->throwException(new ConnectionException()))
;
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
$reflection = new \ReflectionMethod($provider, 'checkAuthentication');
@ -62,15 +62,15 @@ class LdapBindAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
public function testRetrieveUser()
{
$userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
$userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
$userProvider
->expects($this->once())
->method('loadUserByUsername')
->with('foo')
;
$ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
$ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
$reflection = new \ReflectionMethod($provider, 'retrieveUser');

View File

@ -22,14 +22,14 @@ class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$provider = $this->getProvider();
$this->assertTrue($provider->supports($this->getSupportedToken()));
$this->assertFalse($provider->supports($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')));
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
}
public function testAuthenticateWhenTokenIsNotSupported()
{
$provider = $this->getProvider();
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
$this->assertNull($provider->authenticate($token));
}
@ -49,7 +49,7 @@ class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
*/
public function testAuthenticateWhenPreChecksFails()
{
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
$userChecker->expects($this->once())
->method('checkPreAuth')
->will($this->throwException(new DisabledException()));
@ -61,7 +61,7 @@ class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
public function testAuthenticate()
{
$user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
$user->expects($this->exactly(2))
->method('getRoles')
->will($this->returnValue(array('ROLE_FOO')));
@ -80,14 +80,14 @@ class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
protected function getSupportedToken($user = null, $secret = 'test')
{
if (null === $user) {
$user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
$user
->expects($this->any())
->method('getRoles')
->will($this->returnValue(array()));
}
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken', array('getProviderKey'), array($user, 'foo', $secret));
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken')->setMethods(array('getProviderKey'))->setConstructorArgs(array($user, 'foo', $secret))->getMock();
$token
->expects($this->once())
->method('getProviderKey')
@ -99,7 +99,7 @@ class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
protected function getProvider($userChecker = null, $key = 'test')
{
if (null === $userChecker) {
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
}
return new RememberMeAuthenticationProvider($userChecker, $key, 'foo');

View File

@ -21,7 +21,7 @@ class VoterTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
$this->token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
}
public function getTests()

View File

@ -24,7 +24,7 @@ class LdapUserProviderTest extends \PHPUnit_Framework_TestCase
*/
public function testLoadUserByUsernameFailsIfCantConnectToLdap()
{
$ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
$ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
$ldap
->expects($this->once())
->method('bind')
@ -40,7 +40,7 @@ class LdapUserProviderTest extends \PHPUnit_Framework_TestCase
*/
public function testLoadUserByUsernameFailsIfNoLdapEntries()
{
$ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
$ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
$ldap
->expects($this->once())
->method('escape')
@ -56,7 +56,7 @@ class LdapUserProviderTest extends \PHPUnit_Framework_TestCase
*/
public function testLoadUserByUsernameFailsIfMoreThanOneLdapEntry()
{
$ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
$ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
$ldap
->expects($this->once())
->method('escape')
@ -78,7 +78,7 @@ class LdapUserProviderTest extends \PHPUnit_Framework_TestCase
public function testSuccessfulLoadUserByUsername()
{
$ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
$ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
$ldap
->expects($this->once())
->method('escape')

View File

@ -31,8 +31,8 @@ class GuardAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
public function testHandleSuccess()
{
$authenticator = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
$authenticateToken = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
$authenticator = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
$authenticateToken = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
$providerKey = 'my_firewall';
$credentials = array('username' => 'weaverryan', 'password' => 'all_your_base');
@ -81,8 +81,8 @@ class GuardAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
public function testHandleSuccessStopsAfterResponseIsSet()
{
$authenticator1 = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
$authenticator2 = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
$authenticator1 = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
$authenticator2 = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
// mock the first authenticator to fail, and set a Response
$authenticator1
@ -111,8 +111,8 @@ class GuardAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
public function testHandleSuccessWithRememberMe()
{
$authenticator = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
$authenticateToken = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
$authenticator = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
$authenticateToken = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
$providerKey = 'my_firewall_with_rememberme';
$authenticator
@ -154,7 +154,7 @@ class GuardAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
public function testHandleCatchesAuthenticationException()
{
$authenticator = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
$authenticator = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
$providerKey = 'my_firewall2';
$authException = new AuthenticationException('Get outta here crazy user with a bad password!');
@ -186,8 +186,8 @@ class GuardAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
public function testReturnNullToSkipAuth()
{
$authenticatorA = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
$authenticatorB = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
$authenticatorA = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
$authenticatorB = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
$providerKey = 'my_firewall3';
$authenticatorA
@ -240,8 +240,8 @@ class GuardAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
->method('getRequest')
->will($this->returnValue($this->request));
$this->logger = $this->getMock('Psr\Log\LoggerInterface');
$this->rememberMeServices = $this->getMock('Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface');
$this->logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$this->rememberMeServices = $this->getMockBuilder('Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface')->getMock();
}
protected function tearDown()

View File

@ -123,11 +123,11 @@ class GuardAuthenticatorHandlerTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$this->token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
$this->tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
$this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
$this->token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
$this->request = new Request(array(), array(), array(), array(), array(), array());
$this->guardAuthenticator = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
$this->guardAuthenticator = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
}
protected function tearDown()

View File

@ -27,9 +27,9 @@ class GuardAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
{
$providerKey = 'my_cool_firewall';
$authenticatorA = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
$authenticatorB = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
$authenticatorC = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
$authenticatorA = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
$authenticatorB = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
$authenticatorC = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
$authenticators = array($authenticatorA, $authenticatorB, $authenticatorC);
// called 2 times - for authenticator A and B (stops on B because of match)
@ -52,7 +52,7 @@ class GuardAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$authenticatorC->expects($this->never())
->method('getUser');
$mockedUser = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
$mockedUser = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
$authenticatorB->expects($this->once())
->method('getUser')
->with($enteredCredentials, $this->userProvider)
@ -63,7 +63,7 @@ class GuardAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
->with($enteredCredentials, $mockedUser)
// authentication works!
->will($this->returnValue(true));
$authedToken = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
$authedToken = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
$authenticatorB->expects($this->once())
->method('createAuthenticatedToken')
->with($mockedUser, $providerKey)
@ -89,7 +89,7 @@ class GuardAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
{
$providerKey = 'my_uncool_firewall';
$authenticator = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
$authenticator = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
// make sure the authenticator is used
$this->preAuthenticationToken->expects($this->any())
@ -101,7 +101,7 @@ class GuardAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
->method('getCredentials')
->will($this->returnValue('non-null-value'));
$mockedUser = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
$mockedUser = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
$authenticator->expects($this->once())
->method('getUser')
->will($this->returnValue($mockedUser));
@ -124,7 +124,7 @@ class GuardAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
// create a token and mark it as NOT authenticated anymore
// this mimics what would happen if a user "changed" between request
$mockedUser = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
$mockedUser = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
$token = new PostAuthenticationGuardToken($mockedUser, $providerKey, array('ROLE_USER'));
$token->setAuthenticated(false);
@ -134,8 +134,8 @@ class GuardAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
$this->userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$this->userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
$this->userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
$this->preAuthenticationToken = $this->getMockBuilder('Symfony\Component\Security\Guard\Token\PreAuthenticationGuardToken')
->disableOriginalConstructor()
->getMock();

View File

@ -18,30 +18,30 @@ class AnonymousAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
{
public function testHandleWithTokenStorageHavingAToken()
{
$tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
$tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')))
->will($this->returnValue($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()))
;
$tokenStorage
->expects($this->never())
->method('setToken')
;
$authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
$authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock();
$authenticationManager
->expects($this->never())
->method('authenticate')
;
$listener = new AnonymousAuthenticationListener($tokenStorage, 'TheSecret', null, $authenticationManager);
$listener->handle($this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false));
$listener->handle($this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock());
}
public function testHandleWithTokenStorageHavingNoToken()
{
$tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
$tokenStorage
->expects($this->any())
->method('getToken')
@ -50,7 +50,7 @@ class AnonymousAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
$anonymousToken = new AnonymousToken('TheSecret', 'anon.', array());
$authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
$authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock();
$authenticationManager
->expects($this->once())
->method('authenticate')
@ -67,21 +67,21 @@ class AnonymousAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
;
$listener = new AnonymousAuthenticationListener($tokenStorage, 'TheSecret', null, $authenticationManager);
$listener->handle($this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false));
$listener->handle($this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock());
}
public function testHandledEventIsLogged()
{
$tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$logger = $this->getMock('Psr\Log\LoggerInterface');
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$logger->expects($this->once())
->method('info')
->with('Populated the TokenStorage with an anonymous Token.')
;
$authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
$authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock();
$listener = new AnonymousAuthenticationListener($tokenStorage, 'TheSecret', $logger, $authenticationManager);
$listener->handle($this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false));
$listener->handle($this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock());
}
}

View File

@ -34,12 +34,12 @@ class DigestAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
$entryPoint = new DigestAuthenticationEntryPoint($realm, $secret);
$user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
$user->method('getPassword')->willReturn($password);
$providerKey = 'TheProviderKey';
$tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
$tokenStorage
->expects($this->once())
->method('getToken')
@ -51,12 +51,12 @@ class DigestAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
->with($this->equalTo(new UsernamePasswordToken($user, $password, $providerKey)))
;
$userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
$userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
$userProvider->method('loadUserByUsername')->willReturn($user);
$listener = new DigestAuthenticationListener($tokenStorage, $userProvider, $providerKey, $entryPoint);
$event = $this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false);
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock();
$event
->expects($this->any())
->method('getRequest')

View File

@ -42,7 +42,7 @@ class SimplePreAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue($this->token))
;
$simpleAuthenticator = $this->getMock('Symfony\Component\Security\Http\Authentication\SimplePreAuthenticatorInterface');
$simpleAuthenticator = $this->getMockBuilder('Symfony\Component\Security\Http\Authentication\SimplePreAuthenticatorInterface')->getMock();
$simpleAuthenticator
->expects($this->once())
->method('createToken')
@ -79,7 +79,7 @@ class SimplePreAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
->with($this->equalTo(null))
;
$simpleAuthenticator = $this->getMock('Symfony\Component\Security\Http\Authentication\SimplePreAuthenticatorInterface');
$simpleAuthenticator = $this->getMockBuilder('Symfony\Component\Security\Http\Authentication\SimplePreAuthenticatorInterface')->getMock();
$simpleAuthenticator
->expects($this->once())
->method('createToken')
@ -99,20 +99,20 @@ class SimplePreAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
->getMock()
;
$this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
$this->request = new Request(array(), array(), array(), array(), array(), array());
$this->event = $this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false);
$this->event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock();
$this->event
->expects($this->any())
->method('getRequest')
->will($this->returnValue($this->request))
;
$this->logger = $this->getMock('Psr\Log\LoggerInterface');
$this->tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$this->token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
$this->logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$this->tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
$this->token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
}
protected function tearDown()

View File

@ -28,7 +28,7 @@ class ArrayDenormalizerTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->serializer = $this->getMock('Symfony\Component\Serializer\Serializer');
$this->serializer = $this->getMockBuilder('Symfony\Component\Serializer\Serializer')->getMock();
$this->denormalizer = new ArrayDenormalizer();
$this->denormalizer->setSerializer($this->serializer);
}

View File

@ -95,7 +95,7 @@ class TranslatorCacheTest extends \PHPUnit_Framework_TestCase
$catalogue->addResource(new StaleResource()); // better use a helper class than a mock, because it gets serialized in the cache and re-loaded
/** @var LoaderInterface|\PHPUnit_Framework_MockObject_MockObject $loader */
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
$loader = $this->getMockBuilder('Symfony\Component\Translation\Loader\LoaderInterface')->getMock();
$loader
->expects($this->exactly(2))
->method('load')
@ -228,8 +228,8 @@ class TranslatorCacheTest extends \PHPUnit_Framework_TestCase
public function testRefreshCacheWhenResourcesAreNoLongerFresh()
{
$resource = $this->getMock('Symfony\Component\Config\Resource\SelfCheckingResourceInterface');
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
$resource = $this->getMockBuilder('Symfony\Component\Config\Resource\SelfCheckingResourceInterface')->getMock();
$loader = $this->getMockBuilder('Symfony\Component\Translation\Loader\LoaderInterface')->getMock();
$resource->method('isFresh')->will($this->returnValue(false));
$loader
->expects($this->exactly(2))
@ -272,7 +272,7 @@ class TranslatorCacheTest extends \PHPUnit_Framework_TestCase
*/
private function createFailingLoader()
{
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
$loader = $this->getMockBuilder('Symfony\Component\Translation\Loader\LoaderInterface')->getMock();
$loader
->expects($this->never())
->method('load');

View File

@ -224,7 +224,7 @@ class ExpressionValidatorTest extends AbstractConstraintValidatorTest
'expression' => 'false',
));
$expressionLanguage = $this->getMock('Symfony\Component\ExpressionLanguage\ExpressionLanguage');
$expressionLanguage = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ExpressionLanguage')->getMock();
$used = false;