8000 fixed obsolete getMock() usage by fabpot · Pull Request #20984 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

fixed obsolete getMock() usage #20984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixed obsolete getMock() usage
  • Loading branch information
fabpot committed Dec 19, 2016
commit 71d059cad115e4adb8e56ebad8c19f9ca0670c2f
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private function createCollector($queries)
->method('getDatabasePlatform')
->will($this->returnValue(new MySqlPlatform()));

$registry = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
$registry
->expects($this->any())
->method('getConnectionNames')
Expand All @@ -152,7 +152,7 @@ private function createCollector($queries)
->method('getConnection')
->will($this->returnValue($connection));

$logger = $this->getMock('Doctrine\DBAL\Logging\DebugStack');
$logger = $this->getMockBuilder('Doctrine\DBAL\Logging\DebugStack')->getMock();
$logger->queries = $queries;

$collector = new DoctrineDataCollector($registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ContainerAwareLoaderTest extends \PHPUnit_Framework_TestCase
{
public function testShouldSetContainerOnContainerAwareFixture()
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$loader = new ContainerAwareLoader($container);
$fixture = new ContainerAwareFixture();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DoctrineParserCacheTest extends \PHPUnit_Framework_TestCase
{
public function testFetch()
{
$doctrineCacheMock = $this->getMock('Doctrine\Common\Cache\Cache');
$doctrineCacheMock = $this->getMockBuilder('Doctrine\Common\Cache\Cache')->getMock();
$parserCache = new DoctrineParserCache($doctrineCacheMock);

$doctrineCacheMock->expects($this->once())
Expand All @@ -31,7 +31,7 @@ public function testFetch()

public function testFetchUnexisting()
{
$doctrineCacheMock = $this->getMock('Doctrine\Common\Cache\Cache');
$doctrineCacheMock = $this->getMockBuilder('Doctrine\Common\Cache\Cache')->getMock();
$parserCache = new DoctrineParserCache($doctrineCacheMock);

$doctrineCacheMock
Expand All @@ -44,7 +44,7 @@ public function testFetchUnexisting()

public function testSave()
{
$doctrineCacheMock = $this->getMock('Doctrine\Common\Cache\Cache');
$doctrineCacheMock = $this->getMockBuilder('Doctrine\Common\Cache\Cache')->getMock();
$parserCache = new DoctrineParserCache($doctrineCacheMock);

$expression = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParsedExpression')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase

protected function setUp()
{
$this->factory = $this->getMock('Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface');
$this->om = $this->getMock('Doctrine\Common\Persistence\ObjectManager');
$this->repository = $this->getMock('Doctrine\Common\Persistence\ObjectRepository');
$this->factory = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface')->getMock();
$this->om = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock();
$this->repository = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectRepository')->getMock();
$this->class = 'stdClass';
$this->idReader = $this->getMockBuilder('Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader')
->disableOriginalConstructor()
->getMock();
$this->objectLoader = $this->getMock('Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface');
$this->objectLoader = $this->getMockBuilder('Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface')->getMock();
$this->obj1 = (object) array('name' => 'A');
$this->obj2 = (object) array('name' => 'B');
$this->obj3 = (object) array('name' => 'C');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ public function requiredProvider()

private function getGuesser(ClassMetadata $classMetadata)
{
$em = $this->getMock('Doctrine\Common\Persistence\ObjectManager');
$em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock();
$em->expects($this->once())->method('getClassMetaData')->with('TestEntity')->will($this->returnValue($classMetadata));

$registry = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
$registry->expects($this->once())->method('getManagers')->will($this->returnValue(array($em)));

return new DoctrineOrmTypeGuesser($registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase

protected function getExtensions()
{
$manager = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
$manager = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();

$manager->expects($this->any())
->method('getManager')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ public function testPropertyOption()

protected function createRegistryMock($name, $em)
{
$registry = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
$registry->expects($this->any())
->method('getManager')
->with($this->equalTo($name))
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DbalLoggerTest extends \PHPUnit_Framework_TestCase
*/
public function testLog($sql, $params, $logParams)
{
$logger = $this->getMock('Psr\\Log\\LoggerInterface');
$logger = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock();

$dbalLogger = $this
->getMockBuilder('Symfony\\Bridge\\Doctrine\\Logger\\DbalLogger')
Expand Down Expand Up @@ -52,7 +52,7 @@ public function getLogFixtures()

public function testLogNonUtf8()
{
$logger = $this->getMock('Psr\\Log\\LoggerInterface');
$logger = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock();

$dbalLogger = $this
->getMockBuilder('Symfony\\Bridge\\Doctrine\\Logger\\DbalLogger')
Expand All @@ -75,7 +75,7 @@ public function testLogNonUtf8()

public function testLogNonUtf8Array()
{
$logger = $this->getMock('Psr\\Log\\LoggerInterface');
$logger = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock();

$dbalLogger = $this
->getMockBuilder('Symfony\\Bridge\\Doctrine\\Logger\\DbalLogger')
Expand Down Expand Up @@ -106,7 +106,7 @@ public function testLogNonUtf8Array()

public function testLogLongString()
{
$logger = $this->getMock('Psr\\Log\\LoggerInterface');
$logger = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock();

$dbalLogger = $this
->getMockBuilder('Symfony\\Bridge\\Doctrine\\Logger\\DbalLogger')
Expand Down Expand Up @@ -137,7 +137,7 @@ public function testLogLongString()
*/
public function testLogUTF8LongString()
{
$logger = $this->getMock('Psr\\Log\\LoggerInterface');
$logger = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock();

$dbalLogger = $this
->getMockBuilder('Symfony\\Bridge\\Doctrine\\Logger\\DbalLogger')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function testSupportProxy()

private function getManager($em, $name = null)
{
$manager = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
$manager = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
$manager->expects($this->any())
->method('getManager')
->with($this->equalTo($name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function setUp()

protected function createRegistryMock(ObjectManager $em = null)
{
$registry = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
$registry->expects($this->any())
->method('getManager')
->with($this->equalTo(self::EM_NAME))
Expand Down Expand Up @@ -92,7 +92,7 @@ protected function createEntityManagerMock($repositoryMock)
->will($this->returnValue($repositoryMock))
;

$classMetadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
$classMetadata = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata')->getMock();
$classMetadata
->expects($this->any())
->method('hasField')
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testIsHandling()
*/
public function testVerbosityMapping($verbosity, $level, $isHandling, array $map = array())
{
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();
$output
->expects($this->atLeastOnce())
->method('getVerbosity')
Expand Down Expand Up @@ -80,7 +80,7 @@ public function provideVerbosityMappingTests()

public function testVerbosityChanged()
{
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();
$output
->expects($this->at(0))
->method('getVerbosity')
Expand Down Expand Up @@ -110,7 +110,7 @@ public function testGetFormatter()

public function testWritingAndFormatting()
{
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();
$output
->expects($this->any())
->method('getVerbosity')
Expand Down Expand Up @@ -165,12 +165,12 @@ public function testLogsFromListeners()
$logger->addInfo('After terminate message.');
});

$event = new ConsoleCommandEvent(new Command('foo'), $this->getMock('Symfony\Component\Console\Input\InputInterface'), $output);
$event = new ConsoleCommandEvent(new Command('foo'), $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock(), $output);
$dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
$this->assertContains('Before command message.', $out = $output->fetch());
$this->assertContains('After command message.', $out);

$event = new ConsoleTerminateEvent(new Command('foo'), $this->getMock('Symfony\Component\Console\Input\InputInterface'), $output, 0);
$event = new ConsoleTerminateEvent(new Command('foo'), $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock(), $output, 0);
$dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
$this->assertContains('Before terminate message.', $out = $output->fetch());
$this->assertContains('After terminate message.', $out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function setUp()
public function testInstantiateProxy()
{
$instance = new \stdClass();
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$definition = new Definition('stdClass');
$instantiator = function () use ($instance) {
return $instance;
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Bridge/Twig/Tests/AppVariableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testEnvironment()

public function testGetSession()
{
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
$request->method('getSession')->willReturn($session = new Session());

$this->setRequestStack($request);
Expand All @@ -69,7 +69,7 @@ public function testGetRequest()

public function testGetUser()
{
$this->setTokenStorage($user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface'));
$this->setTokenStorage($user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock());

$this->assertEquals($user, $this->appVariable->getUser());
}
Expand All @@ -83,7 +83,7 @@ public function testGetUserWithUsernameAsTokenUser()

public function testGetUserWithNoToken()
{
$tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
$this->appVariable->setTokenStorage($tokenStorage);

$this->assertNull($th 10000 is->appVariable->getUser());
Expand Down Expand Up @@ -131,18 +131,18 @@ public function testGetSessionWithRequestStackNotSet()

protected function setRequestStack($request)
{
$requestStackMock = $this->getMock('Symfony\Component\HttpFoundation\RequestStack');
$requestStackMock = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
$requestStackMock->method('getCurrentRequest')->willReturn($request);

$this->appVariable->setRequestStack($requestStackMock);
}

protected function setTokenStorage($user)
{
$tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
$this->appVariable->setTokenStorage($tokenStorage);

$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
$tokenStorage->method('getToken')->willReturn($token);

$token->method('getUser')->willReturn($user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function getDumpTags()
public function testDump($context, $args, $expectedOutput, $debug = true)
{
$extension = new DumpExtension(new VarCloner());
$twig = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array(
$twig = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array(
'debug' => $debug,
'cache' => false,
'optimizations' => 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function setUp()
'bootstrap_3_horizontal_layout.html.twig',
'custom_widgets.html.twig',
));
$renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface'));
$renderer = new TwigRenderer($rendererEngine, $this->getMockBuilder('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')->getMock());

$this->extension = new FormExtension($renderer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function setUp()
'bootstrap_3_layout.html.twig',
'custom_widgets.html.twig',
));
$renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface'));
$renderer = new TwigRenderer($rendererEngine, $this->getMockBuilder('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')->getMock());

$this->extension = new FormExtension($renderer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function setUp()
'form_div_layout.html.twig',
'custom_widgets.html.twig',
));
$renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface'));
$renderer = new TwigRenderer($rendererEngine, $this->getMockBuilder('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')->getMock());

$this->extension = new FormExtension($renderer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function setUp()
'form_table_layout.html.twig',
'custom_widgets.html.twig',
));
$renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface'));
$renderer = new TwigRenderer($rendererEngine, $this->getMockBuilder('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')->getMock());

$this->extension = new FormExtension($renderer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testUnknownFragmentRenderer()

protected function getFragmentHandler($return)
{
$strategy = $this->getMock('Symfony\\Component\\HttpKernel\\Fragment\\FragmentRendererInterface');
$strategy = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Fragment\\FragmentRendererInterface')->getMock();
$strategy->expects($this->once())->method('getName')->will($this->returnValue('inline'));
$strategy->expects($this->once())->method('render')->will($return);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class RoutingExtensionTest extends \PHPUnit_Framework_TestCase
*/
public function testEscaping($template, $mustBeEscaped)
{
$twig = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
$twig->addExtension(new RoutingExtension($this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface')));
$twig = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
$twig->addExtension(new RoutingExtension($this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->getMock()));

$nodes = $twig->parse($twig->tokenize(new \Twig_Source($template, '')));

Expand Down
10000
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function getTimingTemplates()
protected function getStopwatch($events = array())
{
$events = is_array($events) ? $events : array($events);
$stopwatch = $this->getMock('Symfony\Component\Stopwatch\Stopwatch');
$stopwatch = $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch')->getMock();

$i = -1;
foreach ($events as $eventName) {
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testNoVar()
{
$node = new DumpNode('bar', null, 7);

$env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'));
$env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
$compiler = new \Twig_Compiler($env);

$expected = <<<'EOTXT'
Expand All @@ -43,7 +43,7 @@ public function testIndented()
{
$node = new DumpNode('bar', null, 7);

$env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'));
$env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
$compiler = new \Twig_Compiler($env);

$expected = <<<'EOTXT'
Expand All @@ -70,7 +70,7 @@ public function testOneVar()
));
$node = new DumpNode('bar', $vars, 7);

$env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'));
$env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
$compiler = new \Twig_Compiler($env);

$expected = <<<'EOTXT'
Expand Down Expand Up @@ -99,7 +99,7 @@ public function testMultiVars()
));
$node = new DumpNode('bar', $vars, 7);

$env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'));
$env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
$compiler = new \Twig_Compiler($env);

$expected = <<<'EOTXT'
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testCompile()

$node = new FormThemeNode($form, $resources, 0);

$compiler = new \Twig_Compiler(new \Twig_Environment($this->getMock('Twig_LoaderInterface')));
$compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));

$this->assertEquals(
sprintf(
Expand Down
Loading
0