Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[WIP] [Tests] Refactor PHPUnit mockwill/with to spefic method #29739

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

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,20 @@ private function createCollector($queries)
->getMock();
$connection->expects($this->any())
->method('getDatabasePlatform')
->will($this->returnValue(new MySqlPlatform()));
->willReturn(new MySqlPlatform());

$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
$registry
->expects($this->any())
->method('getConnectionNames')
->will($this->returnValue(array('default' => 'doctrine.dbal.default_connection')));
->willReturn(array('default' => 'doctrine.dbal.default_connection'));
$registry
->expects($this->any())
->method('getManagerNames')
->will($this->returnValue(array('default' => 'doctrine.orm.default_entity_manager')));
->willReturn(array('default' => 'doctrine.orm.default_entity_manager'));
$registry->expects($this->any())
->method('getConnection')
->will($this->returnValue($connection));
->willReturn($connection);

$logger = $this->getMockBuilder('Doctrine\DBAL\Logging\DebugStack')->getMock();
$logger->queries = $queries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ protected function setUp()

$this->extension->expects($this->any())
->method('getObjectManagerElementName')
->will($this->returnCallback(function ($name) {
->willReturnCallback(function ($name) {
return 'doctrine.orm.'.$name;
}));
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,47 +34,47 @@ public function requiredProvider()
// Simple field, not nullable
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
$classMetadata->fieldMappings['field'] = true;
$classMetadata->expects($this->once())->method('isNullable')->with('field')->will($this->returnValue(false));
$classMetadata->expects($this->once())->method('isNullable')->with('field')->willReturn(false);

$return[] = array($classMetadata, new ValueGuess(true, Guess::HIGH_CONFIDENCE));

// Simple field, nullable
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
$classMetadata->fieldMappings['field'] = true;
$classMetadata->expects($this->once())->method('isNullable')->with('field')->will($this->returnValue(true));
$classMetadata->expects($this->once())->method('isNullable')->with('field')->willReturn(true);

$return[] = array($classMetadata, new ValueGuess(false, Guess::MEDIUM_CONFIDENCE));

// One-to-one, nullable (by default)
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->will($this->returnValue(true));
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(true);

$mapping = array('joinColumns' => array(array()));
$classMetadata->expects($this->once())->method('getAssociationMapping')->with('field')->will($this->returnValue($mapping));
$classMetadata->expects($this->once())->method('getAssociationMapping')->with('field')->willReturn($mapping);

$return[] = array($classMetadata, new ValueGuess(false, Guess::HIGH_CONFIDENCE));

// One-to-one, nullable (explicit)
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->will($this->returnValue(true));
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(true);

$mapping = array('joinColumns' => array(array('nullable' => true)));
$classMetadata->expects($this->once())->method('getAssociationMapping')->with('field')->will($this->returnValue($mapping));
$classMetadata->expects($this->once())->method('getAssociationMapping')->with('field')->willReturn($mapping);

$return[] = array($classMetadata, new ValueGuess(false, Guess::HIGH_CONFIDENCE));

// One-to-one, not nullable
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->will($this->returnValue(true));
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(true);

$mapping = array('joinColumns' => array(array('nullable' => false)));
$classMetadata->expects($this->once())->method('getAssociationMapping')->with('field')->will($this->returnValue($mapping));
$classMetadata->expects($this->once())->method('getAssociationMapping')->with('field')->willReturn($mapping);

$return[] = array($classMetadata, new ValueGuess(true, Guess::HIGH_CONFIDENCE));

// One-to-many, no clue
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->will($this->returnValue(false));
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(false);

$return[] = array($classMetadata, null);

Expand All @@ -84,10 +84,10 @@ public function requiredProvider()
private function getGuesser(ClassMetadata $classMetadata)
{
$em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock();
$em->expects($this->once())->method('getClassMetaData')->with('TestEntity')->will($this->returnValue($classMetadata));
$em->expects($this->once())->method('getClassMetaData')->with('TestEntity')->willReturn($classMetadata);

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

return new DoctrineOrmTypeGuesser($registry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ protected function getExtensions()

$manager->expects($this->any())
->method('getManager')
->will($this->returnValue($this->em));
->willReturn($this->em);

$manager->expects($this->any())
->method('getManagerForClass')
->will($this->returnValue($this->em));
->willReturn($this->em);

return array(
new CoreExtension(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ public function testGetManagerForClassIfNoEm()
$this->emRegistry->expects($this->once())
->method('getManagerForClass')
->with(self::SINGLE_IDENT_CLASS)
->will($this->returnValue($this->em));
->willReturn($this->em);

$this->factory->createNamed('name', static::TESTED_TYPE, null, array(
'class' => self::SINGLE_IDENT_CLASS,
Expand Down Expand Up @@ -1234,8 +1234,8 @@ protected function createRegistryMock($name, $em)
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
$registry->expects($this->any())
->method('getManager')
->with($this->equalTo($name))
->will($this->returnValue($em));
->with($name)
->willReturn($em);

return $registry;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ private function getManager($em, $name = null)
$manager = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
$manager->expects($this->any())
->method('getManager')
->with($this->equalTo($name))
->will($this->returnValue($em));
->with($name)
->willReturn($em);

return $manager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ protected function createRegistryMock(ObjectManager $em = null)
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
$registry->expects($this->any())
->method('getManager')
->with($this->equalTo(self::EM_NAME))
->will($this->returnValue($em));
->with(self::EM_NAME)
->willReturn($em);

return $registry;
}
Expand All @@ -104,14 +104,14 @@ protected function createEntityManagerMock($repositoryMock)
;
$em->expects($this->any())
->method('getRepository')
->will($this->returnValue($repositoryMock))
->willReturn($repositoryMock)
;

$classMetadata = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata')->getMock();
$classMetadata
->expects($this->any())
->method('hasField')
->will($this->returnValue(true))
->willReturn(true)
;
$reflParser = $this->getMockBuilder('Doctrine\Common\Reflection\StaticReflectionParser')
->disableOriginalConstructor()
Expand All @@ -125,12 +125,12 @@ protected function createEntityManagerMock($repositoryMock)
$refl
->expects($this->any())
->method('getValue')
->will($this->returnValue(true))
->willReturn(true)
;
$classMetadata->reflFields = array('name' => $refl);
$em->expects($this->any())
->method('getClassMetadata')
->will($this->returnValue($classMetadata))
->willReturn($classMetadata)
;

return $em;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testVerbosityMapping($verbosity, $level, $isHandling, array $map
$output
->expects($this->atLeastOnce())
->method('getVerbosity')
->will($this->returnValue($verbosity))
->willReturn($verbosity)
;
$handler = new ConsoleHandler($output, true, $map);
$this->assertSame($isHandling, $handler->isHandling(array('level' => $level)),
Expand Down Expand Up @@ -114,12 +114,12 @@ public function testVerbosityChanged()
$output
->expects($this->at(0))
->method('getVerbosity')
->will($this->returnValue(OutputInterface::VERBOSITY_QUIET))
->willReturn(OutputInterface::VERBOSITY_QUIET)
;
$output
->expects($this->at(1))
->method('getVerbosity')
->will($this->returnValue(OutputInterface::VERBOSITY_DEBUG))
->willReturn(OutputInterface::VERBOSITY_DEBUG)
;
$handler = new ConsoleHandler($output);
$this->assertFalse($handler->isHandling(array('level' => Logger::NOTICE)),
Expand All @@ -144,7 +144,7 @@ public function testWritingAndFormatting()
$output
->expects($this->any())
->method('getVerbosity')
->will($this->returnValue(OutputInterface::VERBOSITY_DEBUG))
->willReturn(OutputInterface::VERBOSITY_DEBUG)
;
$output
->expects($this->once())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ private function createRequestEvent($additionalServerParameters = array()): arra
->getMock();
$event->expects($this->any())
->method('isMasterRequest')
->will($this->returnValue(true));
->willReturn(true);
$event->expects($this->any())
->method('getRequest')
->will($this->returnValue($request));
->willReturn($request);

return array($event, $server);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ public function testUnknownFragmentRenderer()
protected function getFragmentHandler($return)
{
$strategy = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Fragment\\FragmentRendererInterface')->getMock();
$strategy->expects($this->once())->method('getName')->will($this->returnValue('inline'));
$strategy->expects($this->once())->method('getName')->willReturn('inline');
$strategy->expects($this->once())->method('render')->will($return);

$context = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack')
->disableOriginalConstructor()
->getMock()
;

$context->expects($this->any())->method('getCurrentRequest')->will($this->returnValue(Request::create('/')));
$context->expects($this->any())->method('getCurrentRequest')->willReturn(Request::create('/'));

return new FragmentHandler($context, array($strategy), false);
}
Expand All @@ -82,9 +82,9 @@ protected function renderTemplate(FragmentHandler $renderer, $template = '{{ ren
$twig->addExtension(new HttpKernelExtension());

$loader = $this->getMockBuilder('Twig\RuntimeLoader\RuntimeLoaderInterface')->getMock();
$loader->expects($this->any())->method('load')->will($this->returnValueMap(array(
$loader->expects($this->any())->method('load')->willReturnMap(array(
array('Symfony\Bridge\Twig\Extension\HttpKernelRuntime', new HttpKernelRuntime($renderer)),
)));
));
$twig->addRuntimeLoader($loader);

return $twig->render('index');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ protected function getStopwatch($events = array())
foreach ($events as $eventName) {
$stopwatch->expects($this->at(++$i))
->method('start')
->with($this->equalTo($eventName), 'template')
->with($eventName, 'template')
;
$stopwatch->expects($this->at(++$i))
->method('stop')
->with($this->equalTo($eventName))
->with($eventName)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testFindAllTemplates()
$kernel
->expects($this->once())
->method('getBundles')
->will($this->returnValue(array('BaseBundle' => new BaseBundle())))
->willReturn(array('BaseBundle' => new BaseBundle()))
;

$parser = new TemplateFilenameParser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ private function getRouter()
$router
->expects($this->any())
->method('getRouteCollection')
->will($this->returnValue($routeCollection));
->willReturn($routeCollection);
$router
->expects($this->any())
->method('getContext')
->will($this->returnValue($requestContext));
->willReturn($requestContext);

return $router;
}
Expand All @@ -77,13 +77,13 @@ private function getKernel()
$container
->expects($this->atLeastOnce())
->method('has')
->will($this->returnCallback(function ($id) {
->willReturnCallback(function ($id) {
if ('console.command_loader' === $id) {
return false;
}

return true;
}))
})
;
$container
->expects($this->any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function testDebugCustomDirectory()
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
$kernel->expects($this->once())
->method('getBundle')
->with($this->equalTo($this->translationDir.'/customDir'))
->with($this->translationDir.'/customDir')
->willThrowException(new \InvalidArgumentException());

$tester = $this->createCommandTester(array('foo' => 'foo'), array('bar' => 'bar'), $kernel);
Expand All @@ -122,7 +122,7 @@ public function testDebugInvalidDirectory()
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
$kernel->expects($this->once())
->method('getBundle')
->with($this->equalTo('dir'))
->with('dir')
->willThrowException(new \InvalidArgumentException());

$tester = $this->createCommandTester(array(), array(), $kernel);
Expand Down Expand Up @@ -154,26 +154,26 @@ private function createCommandTester($extractedMessages = array(), $loadedMessag
$translator
->expects($this->any())
->method('getFallbackLocales')
->will($this->returnValue(array('en')));
->willReturn(array('en'));

$extractor = $this->getMockBuilder('Symfony\Component\Translation\Extractor\ExtractorInterface')->getMock();
$extractor
->expects($this->any())
->method('extract')
->will(
$this->returnCallback(function ($path, $catalogue) use ($extractedMessages) {
->willReturnCallback(
function ($path, $catalogue) use ($extractedMessages) {
$catalogue->add($extractedMessages);
})
}
);

$loader = $this->getMockBuilder('Symfony\Component\Translation\Reader\TranslationReader')->getMock();
$loader
->expects($this->any())
->method('read')
->will(
$this->returnCallback(function ($path, $catalogue) use ($loadedMessages) {
->willReturnCallback(
function ($path, $catalogue) use ($loadedMessages) {
$catalogue->add($loadedMessages);
})
}
);

if (null === $kernel) {
Expand All @@ -191,7 +191,7 @@ private function createCommandTester($extractedMessages = array(), $loadedMessag
$kernel
->expects($this->any())
->method('getBundle')
->will($this->returnValueMap($returnValues));
->willReturnMap($returnValues);
}

$kernel
Expand Down Expand Up @@ -221,7 +221,7 @@ private function getBundle($path)
$bundle
->expects($this->any())
->method('getPath')
->will($this->returnValue($path))
->willReturn($path)
;

return $bundle;
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.