Issue #3221312 by Spokje: ->willReturn(...) would make more sense here

(cherry picked from commit 6335af17b4)
merge-requests/429/merge
catch 2021-07-28 11:57:46 +01:00
parent 8ea7c1f67b
commit 00efdb11e5
59 changed files with 312 additions and 225 deletions

View File

@ -57,7 +57,7 @@ class CommentStatisticsUnitTest extends UnitTestCase {
$this->statement->expects($this->any())
->method('fetchObject')
->will($this->returnCallback([$this, 'fetchObjectCallback']));
->willReturnCallback([$this, 'fetchObjectCallback']);
$this->select = $this->getMockBuilder('Drupal\Core\Database\Query\Select')
->disableOriginalConstructor()

View File

@ -506,7 +506,7 @@ class ConfigNamesMapperTest extends UnitTestCase {
$this->typedConfigManager
->expects($this->any())
->method('hasConfigSchema')
->will($this->returnValueMap($map));
->willReturnMap($map);
$result = $this->configNamesMapper->hasSchema();
$this->assertSame($expected, $result);
@ -553,7 +553,7 @@ class ConfigNamesMapperTest extends UnitTestCase {
$this->configMapperManager
->expects($this->any())
->method('hasTranslatable')
->will($this->returnValueMap($map));
->willReturnMap($map);
$result = $this->configNamesMapper->hasTranslatable();
$this->assertSame($expected, $result);
@ -604,7 +604,7 @@ class ConfigNamesMapperTest extends UnitTestCase {
$this->localeConfigManager
->expects($this->any())
->method('hasTranslation')
->will($this->returnValueMap($map));
->willReturnMap($map);
$result = $this->configNamesMapper->hasTranslation($language);
$this->assertSame($expected, $result);

View File

@ -21,10 +21,13 @@ class ContentTranslationLocalTasksTest extends LocalTaskIntegrationTestBase {
$entity_type = $this->createMock('Drupal\Core\Entity\EntityTypeInterface');
$entity_type->expects($this->any())
->method('getLinkTemplate')
->will($this->returnValueMap([
->willReturnMap([
['canonical', 'entity.node.canonical'],
['drupal:content-translation-overview', 'entity.node.content_translation_overview'],
]));
[
'drupal:content-translation-overview',
'entity.node.content_translation_overview',
],
]);
$content_translation_manager = $this->createMock('Drupal\content_translation\ContentTranslationManagerInterface');
$content_translation_manager->expects($this->any())
->method('getSupportedEntityTypes')

View File

@ -78,9 +78,9 @@ class FieldStorageConfigAccessControlHandlerTest extends UnitTestCase {
$this->member
->expects($this->any())
->method('hasPermission')
->will($this->returnValueMap([
->willReturnMap([
['administer node fields', TRUE],
]));
]);
$this->member
->expects($this->any())
->method('id')

View File

@ -68,7 +68,7 @@ class ForumListingBreadcrumbBuilderTest extends UnitTestCase {
->will($this->returnValue($route_name));
$route_match->expects($this->any())
->method('getParameter')
->will($this->returnValueMap($parameter_map));
->willReturnMap($parameter_map);
$this->assertEquals($expected, $builder->applies($route_match));
}
@ -159,19 +159,19 @@ class ForumListingBreadcrumbBuilderTest extends UnitTestCase {
$vocab_storage = $this->createMock('Drupal\Core\Entity\EntityStorageInterface');
$vocab_storage->expects($this->any())
->method('load')
->will($this->returnValueMap([
->willReturnMap([
['forums', $prophecy->reveal()],
]));
]);
$entity_type_manager = $this->getMockBuilder(EntityTypeManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$entity_type_manager->expects($this->any())
->method('getStorage')
->will($this->returnValueMap([
->willReturnMap([
['taxonomy_vocabulary', $vocab_storage],
['taxonomy_term', $term_storage],
]));
]);
$config_factory = $this->getConfigFactoryStub(
[

View File

@ -75,7 +75,7 @@ class ForumNodeBreadcrumbBuilderTest extends UnitTestCase {
->will($this->returnValue($route_name));
$route_match->expects($this->any())
->method('getParameter')
->will($this->returnValueMap($parameter_map));
->willReturnMap($parameter_map);
$this->assertEquals($expected, $builder->applies($route_match));
}
@ -169,19 +169,19 @@ class ForumNodeBreadcrumbBuilderTest extends UnitTestCase {
$vocab_storage = $this->createMock('Drupal\Core\Entity\EntityStorageInterface');
$vocab_storage->expects($this->any())
->method('load')
->will($this->returnValueMap([
->willReturnMap([
['forums', $prophecy->reveal()],
]));
]);
$entity_type_manager = $this->getMockBuilder(EntityTypeManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$entity_type_manager->expects($this->any())
->method('getStorage')
->will($this->returnValueMap([
->willReturnMap([
['taxonomy_vocabulary', $vocab_storage],
['taxonomy_term', $term_storage],
]));
]);
$config_factory = $this->getConfigFactoryStub(
[

View File

@ -73,7 +73,7 @@ class ImageStyleTest extends UnitTestCase {
->will($this->returnValue($effectManager));
$image_style->expects($this->any())
->method('fileDefaultScheme')
->will($this->returnCallback([$this, 'fileDefaultScheme']));
->willReturnCallback([$this, 'fileDefaultScheme']);
return $image_style;
}

View File

@ -129,13 +129,14 @@ class FormErrorHandlerTest extends UnitTestCase {
$this->renderer->expects($this->once())
->method('renderPlain')
->will($this->returnCallback(function ($render_array) {
->willReturnCallback(function ($render_array) {
$links = [];
foreach ($render_array[1]['#items'] as $item) {
$links[] = htmlspecialchars($item['#title']);
}
return $render_array[0]['#markup'] . '<ul-comma-list-mock><li-mock>' . implode('</li-mock><li-mock>', $links) . '</li-mock></ul-comma-list-mock>';
}));
});
$form_state = new FormState();
$form_state->setErrorByName('test1', 'invalid');

View File

@ -134,9 +134,9 @@ class LinkTest extends UnitTestCase {
$url_assembler = $this->getMockBuilder(UnroutedUrlAssemblerInterface::class)
->disableOriginalConstructor()
->getMock();
$url_assembler->method('assemble')->will($this->returnCallback(function ($uri) {
$url_assembler->method('assemble')->willReturnCallback(function ($uri) {
return (new GeneratedUrl())->setGeneratedUrl($uri);
}));
});
$container = new ContainerBuilder();
$container->set('unrouted_url_assembler', $url_assembler);

View File

@ -157,16 +157,17 @@ class LocaleLookupTest extends UnitTestCase {
// cSpell:enable
$this->storage->expects($this->any())
->method('findTranslation')
->will($this->returnCallback(function ($argument) use ($translations) {
->willReturnCallback(function ($argument) use ($translations) {
if (isset($translations[$argument['language']][$argument['source']])) {
return (object) ['translation' => $translations[$argument['language']][$argument['source']]];
}
return TRUE;
}));
});
$this->languageManager->expects($this->any())
->method('getFallbackCandidates')
->will($this->returnCallback(function (array $context = []) {
->willReturnCallback(function (array $context = []) {
switch ($context['langcode']) {
case 'pl':
return ['cs', 'en'];
@ -177,7 +178,7 @@ class LocaleLookupTest extends UnitTestCase {
default:
return [];
}
}));
});
$this->cache->expects($this->once())
->method('get')
@ -289,20 +290,21 @@ class LocaleLookupTest extends UnitTestCase {
public function testFixOldPluralStyleTranslations($translations, $langcode, $string, $is_fix) {
$this->storage->expects($this->any())
->method('findTranslation')
->will($this->returnCallback(function ($argument) use ($translations) {
->willReturnCallback(function ($argument) use ($translations) {
if (isset($translations[$argument['language']][$argument['source']])) {
return (object) ['translation' => $translations[$argument['language']][$argument['source']]];
}
return TRUE;
}));
});
$this->languageManager->expects($this->any())
->method('getFallbackCandidates')
->will($this->returnCallback(function (array $context = []) {
->willReturnCallback(function (array $context = []) {
switch ($context['langcode']) {
case 'by':
return ['ru'];
}
}));
});
$this->cache->expects($this->once())
->method('get')
->with('locale:' . $langcode . '::anonymous', FALSE);

View File

@ -35,9 +35,9 @@ class GetTest extends MigrateProcessTestCase {
$this->plugin = new Get(['source' => ['test1', 'test2']], '', []);
$this->row->expects($this->exactly(2))
->method('get')
->will($this->returnCallback(function ($argument) use ($map) {
->willReturnCallback(function ($argument) use ($map) {
return $map[$argument];
}));
});
$value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destination_property');
$this->assertSame(['source_value1', 'source_value2'], $value);
}
@ -68,9 +68,9 @@ class GetTest extends MigrateProcessTestCase {
$this->plugin = new Get(['source' => ['test1', '@@test2', '@@test3', 'test4']], '', []);
$this->row->expects($this->exactly(4))
->method('get')
->will($this->returnCallback(function ($argument) use ($map) {
->willReturnCallback(function ($argument) use ($map) {
return $map[$argument];
}));
});
$value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destination_property');
$this->assertSame(['source_value1', 'source_value2', 'source_value3', 'source_value4'], $value);
}

View File

@ -53,9 +53,9 @@ class MachineNameTest extends MigrateProcessTestCase {
->expects($this->once())
->method('transliterate')
->with($human_name)
->will($this->returnCallback(function (string $string): string {
->willReturnCallback(function (string $string): string {
return str_replace(['á', 'é', 'ő'], ['a', 'e', 'o'], $string);
}));
});
$plugin = new MachineName($configuration, 'machine_name', [], $this->transliteration);
$value = $plugin->transform($human_name, $this->migrateExecutable, $this->row, 'destination_property');

View File

@ -168,9 +168,9 @@ class MakeUniqueEntityFieldTest extends MigrateProcessTestCase {
->will($this->returnValue($this->entityQuery));
$this->entityQuery->expects($this->exactly($count + 1))
->method('execute')
->will($this->returnCallback(function () use (&$count) {
->willReturnCallback(function () use (&$count) {
return $count--;
}));
});
}
/**
@ -198,15 +198,15 @@ class MakeUniqueEntityFieldTest extends MigrateProcessTestCase {
}
$this->entityQuery
->method('condition')
->will($this->returnValueMap($map));
->willReturnMap($map);
// Entity 'forums' is pre-existing, entity 'test_vocab' was migrated.
$this->idMap
->method('lookupSourceId')
->will($this->returnValueMap([
->willReturnMap([
[['test_field' => 'forums'], FALSE],
[['test_field' => 'test_vocab'], ['source_id' => 42]],
]));
]);
// Existing entity 'forums' was not migrated, value should not be unique.
$actual = $plugin->transform('forums', $this->migrateExecutable, $this->row, 'testproperty');

View File

@ -42,10 +42,10 @@ class AliasPathProcessorTest extends UnitTestCase {
public function testProcessInbound() {
$this->aliasManager->expects($this->exactly(2))
->method('getPathByAlias')
->will($this->returnValueMap([
->willReturnMap([
['urlalias', NULL, 'internal-url'],
['url', NULL, 'url'],
]));
]);
$request = Request::create('/urlalias');
$this->assertEquals('internal-url', $this->pathProcessor->processInbound('urlalias', $request));
@ -61,10 +61,10 @@ class AliasPathProcessorTest extends UnitTestCase {
public function testProcessOutbound($path, array $options, $expected_path) {
$this->aliasManager->expects($this->any())
->method('getAliasByPath')
->will($this->returnValueMap([
->willReturnMap([
['internal-url', NULL, 'urlalias'],
['url', NULL, 'url'],
]));
]);
$bubbleable_metadata = new BubbleableMetadata();
$this->assertEquals($expected_path, $this->pathProcessor->processOutbound($path, $options, NULL, $bubbleable_metadata));

View File

@ -132,16 +132,16 @@ class QuickEditEntityFieldAccessCheckTest extends UnitTestCase {
$entity->expects($this->any())
->method('hasTranslation')
->will($this->returnValueMap([
->willReturnMap([
[LanguageInterface::LANGCODE_NOT_SPECIFIED, TRUE],
['xx-lolspeak', FALSE],
]));
]);
$entity->expects($this->any())
->method('hasField')
->will($this->returnValueMap([
->willReturnMap([
['valid', TRUE],
['not_valid', FALSE],
]));
]);
return $entity;
}

View File

@ -189,7 +189,7 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
$this->requestMatcher->expects($this->exactly(1))
->method('matchRequest')
->will($this->returnCallback(function (Request $request) use ($route_1) {
->willReturnCallback(function (Request $request) use ($route_1) {
if ($request->getPathInfo() == '/example') {
return [
RouteObjectInterface::ROUTE_NAME => 'example',
@ -197,7 +197,7 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
'_raw_variables' => new ParameterBag([]),
];
}
}));
});
$this->setupAccessManagerToAllow();
@ -229,7 +229,7 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
$this->requestMatcher->expects($this->exactly(2))
->method('matchRequest')
->will($this->returnCallback(function (Request $request) use ($route_1, $route_2) {
->willReturnCallback(function (Request $request) use ($route_1, $route_2) {
if ($request->getPathInfo() == '/example/bar') {
return [
RouteObjectInterface::ROUTE_NAME => 'example_bar',
@ -244,7 +244,7 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
'_raw_variables' => new ParameterBag([]),
];
}
}));
});
$this->accessManager->expects($this->any())
->method('check')
@ -364,7 +364,7 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
$this->requestMatcher->expects($this->exactly(1))
->method('matchRequest')
->will($this->returnCallback(function (Request $request) use ($route_1) {
->willReturnCallback(function (Request $request) use ($route_1) {
if ($request->getPathInfo() == '/user/1') {
return [
RouteObjectInterface::ROUTE_NAME => 'user_page',
@ -372,7 +372,7 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
'_raw_variables' => new ParameterBag([]),
];
}
}));
});
$this->setupAccessManagerToAllow();
$this->titleResolver->expects($this->once())

View File

@ -76,12 +76,11 @@ class PermissionAccessCheckTest extends UnitTestCase {
$user = $this->createMock('Drupal\Core\Session\AccountInterface');
$user->expects($this->any())
->method('hasPermission')
->will($this->returnValueMap([
['allowed', TRUE],
['denied', FALSE],
['other', FALSE],
]
));
->willReturnMap([
['allowed', TRUE],
['denied', FALSE],
['other', FALSE],
]);
$route = new Route('', [], $requirements);
$this->assertEquals($access_result, $this->accessCheck->access($route, $user));

View File

@ -171,11 +171,11 @@ EOF
]);
$this->moduleHandler->expects($this->exactly(3))
->method('getName')
->will($this->returnValueMap([
->willReturnMap([
['module_a', 'Module a'],
['module_b', 'Module b'],
['module_c', 'A Module'],
]));
]);
$url = vfsStream::url('modules');
mkdir($url . '/module_a');

View File

@ -87,10 +87,10 @@ class UserAccessControlHandlerTest extends UnitTestCase {
$this->owner
->expects($this->any())
->method('hasPermission')
->will($this->returnValueMap([
->willReturnMap([
['administer users', FALSE],
['change own username', TRUE],
]));
]);
$this->owner
->expects($this->any())
@ -107,9 +107,9 @@ class UserAccessControlHandlerTest extends UnitTestCase {
$this->emailViewer
->expects($this->any())
->method('hasPermission')
->will($this->returnValueMap([
->willReturnMap([
['view user email addresses', TRUE],
]));
]);
$this->emailViewer
->expects($this->any())
->method('id')

View File

@ -33,11 +33,14 @@ class RolesRidTest extends UnitTestCase {
$role_storage = $this->getMockForAbstractClass('Drupal\Core\Entity\EntityStorageInterface');
$role_storage->expects($this->any())
->method('loadMultiple')
->will($this->returnValueMap([
->willReturnMap([
[[], []],
[['test_rid_1'], ['test_rid_1' => $role1]],
[['test_rid_1', 'test_rid_2'], ['test_rid_1' => $role1, 'test_rid_2' => $role2]],
]));
[
['test_rid_1', 'test_rid_2'],
['test_rid_1' => $role1, 'test_rid_2' => $role2],
],
]);
$entity_type = $this->createMock('Drupal\Core\Entity\EntityTypeInterface');
$entity_type->expects($this->any())

View File

@ -74,10 +74,11 @@ class ViewAjaxControllerTest extends UnitTestCase {
$this->renderer = $this->createMock('\Drupal\Core\Render\RendererInterface');
$this->renderer->expects($this->any())
->method('render')
->will($this->returnCallback(function (array &$elements) {
->willReturnCallback(function (array &$elements) {
$elements['#attached'] = [];
return isset($elements['#markup']) ? $elements['#markup'] : '';
}));
});
$this->renderer->expects($this->any())
->method('executeInRenderContext')
->willReturnCallback(function (RenderContext $context, callable $callable) {

View File

@ -164,11 +164,11 @@ class RouteSubscriberTest extends UnitTestCase {
$executable->expects($this->any())
->method('setDisplay')
->will($this->returnValueMap([
->willReturnMap([
['page_1', TRUE],
['page_2', TRUE],
['page_3', FALSE],
]));
]);
// Ensure that only the first two displays are actually called.
$display_1 = $this->createMock('Drupal\views\Plugin\views\display\DisplayRouterInterface');
@ -179,10 +179,10 @@ class RouteSubscriberTest extends UnitTestCase {
->getMock();
$display_collection->expects($this->any())
->method('get')
->will($this->returnValueMap([
->willReturnMap([
['page_1', $display_1],
['page_2', $display_2],
]));
]);
$executable->displayHandlers = $display_collection;
$this->routeSubscriber->applicableViews = [];

View File

@ -63,11 +63,11 @@ class EntityTest extends UnitTestCase {
->will($this->returnValue('test_bundle'));
$mock_entity->expects($this->any())
->method('access')
->will($this->returnValueMap([
->willReturnMap([
['test_op', NULL, FALSE, TRUE],
['test_op_2', NULL, FALSE, FALSE],
['test_op_3', NULL, FALSE, TRUE],
]));
]);
$mock_entity_bundle_2 = $this->getMockForAbstractClass('Drupal\Core\Entity\EntityBase', [], '', FALSE, TRUE, TRUE, ['bundle', 'access']);
$mock_entity_bundle_2->expects($this->any())
@ -75,11 +75,11 @@ class EntityTest extends UnitTestCase {
->will($this->returnValue('test_bundle_2'));
$mock_entity_bundle_2->expects($this->any())
->method('access')
->will($this->returnValueMap([
->willReturnMap([
['test_op', NULL, FALSE, FALSE],
['test_op_2', NULL, FALSE, FALSE],
['test_op_3', NULL, FALSE, TRUE],
]));
]);
$storage = $this->createMock('Drupal\Core\Entity\EntityStorageInterface');
@ -95,7 +95,7 @@ class EntityTest extends UnitTestCase {
];
$storage->expects($this->any())
->method('loadMultiple')
->will($this->returnValueMap($value_map));
->willReturnMap($value_map);
$this->entityTypeManager->expects($this->any())
->method('getStorage')

View File

@ -38,7 +38,7 @@ class ViewListBuilderTest extends UnitTestCase {
$display_manager->expects($this->any())
->method('getDefinition')
->will($this->returnValueMap([
->willReturnMap([
[
'default',
TRUE,
@ -73,7 +73,7 @@ class ViewListBuilderTest extends UnitTestCase {
'admin' => 'Embed admin label',
],
],
]));
]);
$default_display = $this->getMockBuilder('Drupal\views\Plugin\views\display\DefaultDisplay')
->setMethods(['initDisplay'])
@ -125,13 +125,13 @@ class ViewListBuilderTest extends UnitTestCase {
$display_manager->expects($this->any())
->method('createInstance')
->will($this->returnValueMap([
->willReturnMap([
['default', $values['display']['default'], $default_display],
['page', $values['display']['page_1'], $page_display],
['page', $values['display']['page_2'], $page_display],
['page', $values['display']['page_3'], $page_display],
['embed', $values['display']['embed'], $embed_display],
]));
]);
$container = new ContainerBuilder();
$user = $this->createMock('Drupal\Core\Session\AccountInterface');

View File

@ -136,10 +136,10 @@ class DiscoveryTraitTest extends TestCase {
// for 'not_valid'.
$trait->expects($this->once())
->method('getDefinition')
->will($this->returnValueMap([
->willReturnMap([
['valid', FALSE, TRUE],
['not_valid', FALSE, FALSE],
]));
]);
// Call hasDefinition().
$this->assertSame(
$expected,

View File

@ -113,7 +113,7 @@ class AccessManagerTest extends UnitTestCase {
$map[] = ['test_route_4', $this->routeCollection->get('test_route_4')];
$this->routeProvider->expects($this->any())
->method('getRouteByName')
->will($this->returnValueMap($map));
->willReturnMap($map);
$map = [];
$map[] = ['test_route_1', [], '/test-route-1'];
@ -173,9 +173,9 @@ class AccessManagerTest extends UnitTestCase {
$access_check->expects($this->exactly(2))
->method('applies')
->with($this->isInstanceOf('Symfony\Component\Routing\Route'))
->will($this->returnCallback(function (Route $route) {
return $route->getRequirement('_bar') == 2;
}));
->willReturnCallback(function (Route $route) {
return $route->getRequirement('_bar') == 2;
});
$this->checkProvider->setChecks($collection);
$this->assertEmpty($route->getOption('_access_checks'));
@ -535,15 +535,16 @@ class AccessManagerTest extends UnitTestCase {
}
return $this->argumentsResolverFactory->expects($constraint)
->method('getArgumentsResolver')
->will($this->returnCallback(function ($route_match, $account) {
->willReturnCallback(function ($route_match, $account) {
$resolver = $this->createMock('Drupal\Component\Utility\ArgumentsResolverInterface');
$resolver->expects($this->any())
->method('getArguments')
->will($this->returnCallback(function ($callable) use ($route_match) {
return [$route_match->getRouteObject()];
}));
return $resolver;
}));
});
}
}

View File

@ -32,13 +32,33 @@ class CacheContextsManagerTest extends UnitTestCase {
->getMock();
$container->expects($this->any())
->method('get')
->will($this->returnValueMap([
['cache_context.a', Container::EXCEPTION_ON_INVALID_REFERENCE, new FooCacheContext()],
['cache_context.a.b', Container::EXCEPTION_ON_INVALID_REFERENCE, new FooCacheContext()],
['cache_context.a.b.c', Container::EXCEPTION_ON_INVALID_REFERENCE, new BazCacheContext()],
['cache_context.x', Container::EXCEPTION_ON_INVALID_REFERENCE, new BazCacheContext()],
['cache_context.a.b.no-optimize', Container::EXCEPTION_ON_INVALID_REFERENCE, new NoOptimizeCacheContext()],
]));
->willReturnMap([
[
'cache_context.a',
Container::EXCEPTION_ON_INVALID_REFERENCE,
new FooCacheContext(),
],
[
'cache_context.a.b',
Container::EXCEPTION_ON_INVALID_REFERENCE,
new FooCacheContext(),
],
[
'cache_context.a.b.c',
Container::EXCEPTION_ON_INVALID_REFERENCE,
new BazCacheContext(),
],
[
'cache_context.x',
Container::EXCEPTION_ON_INVALID_REFERENCE,
new BazCacheContext(),
],
[
'cache_context.a.b.no-optimize',
Container::EXCEPTION_ON_INVALID_REFERENCE,
new NoOptimizeCacheContext(),
],
]);
$cache_contexts_manager = new CacheContextsManager($container, $this->getContextsFixture());
$this->assertSame($optimized_context_tokens, $cache_contexts_manager->optimizeTokens($context_tokens));
@ -161,10 +181,18 @@ class CacheContextsManagerTest extends UnitTestCase {
->getMock();
$container->expects($this->any())
->method('get')
->will($this->returnValueMap([
['cache_context.foo', Container::EXCEPTION_ON_INVALID_REFERENCE, new FooCacheContext()],
['cache_context.baz', Container::EXCEPTION_ON_INVALID_REFERENCE, new BazCacheContext()],
]));
->willReturnMap([
[
'cache_context.foo',
Container::EXCEPTION_ON_INVALID_REFERENCE,
new FooCacheContext(),
],
[
'cache_context.baz',
Container::EXCEPTION_ON_INVALID_REFERENCE,
new BazCacheContext(),
],
]);
return $container;
}

View File

@ -84,11 +84,12 @@ class ParamConversionEnhancerTest extends UnitTestCase {
$this->paramConverterManager->expects($this->any())
->method('convert')
->with($this->isType('array'))
->will($this->returnCallback(function ($defaults) {
->willReturnCallback(function ($defaults) {
// Convert the mirrored default to another value.
$defaults['bar'] = '2';
return $defaults;
}));
});
$expected = new ParameterBag(['id' => 1]);
$result = $this->paramConversionEnhancer->enhance($defaults, new Request());
$this->assertEquals($result['_raw_variables'], $expected);

View File

@ -99,9 +99,9 @@ class EntityFormDisplayAccessControlHandlerTest extends UnitTestCase {
$this->member
->expects($this->any())
->method('hasPermission')
->will($this->returnValueMap([
->willReturnMap([
['administer foobar form display', TRUE],
]));
]);
$this->member
->expects($this->any())
->method('id')
@ -111,9 +111,9 @@ class EntityFormDisplayAccessControlHandlerTest extends UnitTestCase {
$this->parent_member
->expects($this->any())
->method('hasPermission')
->will($this->returnValueMap([
->willReturnMap([
['Llama', TRUE],
]));
]);
$this->parent_member
->expects($this->any())
->method('id')
@ -126,9 +126,9 @@ class EntityFormDisplayAccessControlHandlerTest extends UnitTestCase {
$entity_form_display_entity_type
->expects($this->any())
->method('getKey')
->will($this->returnValueMap([
->willReturnMap([
['langcode', 'langcode'],
]));
]);
$entity_form_display_entity_type->expects($this->any())
->method('entityClassImplements')
->will($this->returnValue(TRUE));

View File

@ -22,9 +22,9 @@ class EntityViewDisplayAccessControlHandlerTest extends EntityFormDisplayAccessC
$this->member
->expects($this->any())
->method('hasPermission')
->will($this->returnValueMap([
->willReturnMap([
['administer foobar display', TRUE],
]));
]);
$this->member
->expects($this->any())
->method('id')

View File

@ -463,7 +463,7 @@ class EntityResolverManagerTest extends UnitTestCase {
]));
$this->entityTypeManager->expects($this->any())
->method('getDefinition')
->will($this->returnCallback(function ($entity_type) use ($definition, $revisionable_definition) {
->willReturnCallback(function ($entity_type) use ($definition, $revisionable_definition) {
if ($entity_type == 'entity_test') {
return $definition;
}
@ -473,7 +473,7 @@ class EntityResolverManagerTest extends UnitTestCase {
else {
return NULL;
}
}));
});
}
}

View File

@ -216,9 +216,9 @@ class EntityUnitTest extends UnitTestCase {
public function testLanguage() {
$this->entityType->expects($this->any())
->method('getKey')
->will($this->returnValueMap([
->willReturnMap([
['langcode', 'langcode'],
]));
]);
$this->assertSame('en', $this->entity->language()->getId());
}

View File

@ -1393,9 +1393,9 @@ class SqlContentEntityStorageSchemaTest extends UnitTestCase {
return $expected_table_schemas[$invocation_count] == $table_schema;
})
)
->will($this->returnCallback(function () use (&$invocation_count) {
->willReturnCallback(function () use (&$invocation_count) {
$invocation_count++;
}));
});
}
$connection = $this->getMockBuilder('Drupal\Core\Database\Connection')

View File

@ -381,14 +381,14 @@ class SqlContentEntityStorageTest extends UnitTestCase {
->will($this->returnValue(['id' => 'id']));
$this->entityType->expects($this->any())
->method('hasKey')
->will($this->returnValueMap([
->willReturnMap([
// SqlContentEntityStorageSchema::initializeBaseTable()
['revision', FALSE],
['id', TRUE],
]));
]);
$this->entityType->expects($this->any())
->method('getKey')
->will($this->returnValueMap([
->willReturnMap([
// EntityStorageBase::__construct()
['id', 'id'],
// ContentEntityStorageBase::__construct()
@ -397,7 +397,7 @@ class SqlContentEntityStorageTest extends UnitTestCase {
// SqlContentEntityStorageSchema::initializeBaseTable()
['id' => 'id'],
['id' => 'id'],
]));
]);
$this->setUpEntityStorage();
@ -478,11 +478,11 @@ class SqlContentEntityStorageTest extends UnitTestCase {
public function testGetTableMappingSimple(array $entity_keys) {
$this->entityType->expects($this->any())
->method('getKey')
->will($this->returnValueMap([
->willReturnMap([
['id', $entity_keys['id']],
['uuid', $entity_keys['uuid']],
['bundle', $entity_keys['bundle']],
]));
]);
$this->setUpEntityStorage();
@ -596,12 +596,12 @@ class SqlContentEntityStorageTest extends UnitTestCase {
->will($this->returnValue(TRUE));
$this->entityType->expects($this->any())
->method('getKey')
->will($this->returnValueMap([
->willReturnMap([
['id', $entity_keys['id']],
['uuid', $entity_keys['uuid']],
['bundle', $entity_keys['bundle']],
['revision', $entity_keys['revision']],
]));
]);
$this->entityType->expects($this->any())
->method('getRevisionMetadataKeys')
->will($this->returnValue([]));
@ -669,12 +669,12 @@ class SqlContentEntityStorageTest extends UnitTestCase {
->will($this->returnValue(TRUE));
$this->entityType->expects($this->any())
->method('getKey')
->will($this->returnValueMap([
->willReturnMap([
['id', $entity_keys['id']],
['uuid', $entity_keys['uuid']],
['bundle', $entity_keys['bundle']],
['revision', $entity_keys['revision']],
]));
]);
$this->entityType->expects($this->any())
->method('getRevisionMetadataKeys')
@ -723,12 +723,12 @@ class SqlContentEntityStorageTest extends UnitTestCase {
->will($this->returnValue('entity_test_field_data'));
$this->entityType->expects($this->any())
->method('getKey')
->will($this->returnValueMap([
->willReturnMap([
['id', $entity_keys['id']],
['uuid', $entity_keys['uuid']],
['bundle', $entity_keys['bundle']],
['langcode', $entity_keys['langcode']],
]));
]);
$this->setUpEntityStorage();
@ -783,12 +783,12 @@ class SqlContentEntityStorageTest extends UnitTestCase {
->will($this->returnValue('entity_test_field_data'));
$this->entityType->expects($this->any())
->method('getKey')
->will($this->returnValueMap([
->willReturnMap([
['id', $entity_keys['id']],
['uuid', $entity_keys['uuid']],
['bundle', $entity_keys['bundle']],
['langcode', $entity_keys['langcode']],
]));
]);
$this->setUpEntityStorage();
@ -853,13 +853,13 @@ class SqlContentEntityStorageTest extends UnitTestCase {
->will($this->returnValue('entity_test_field_data'));
$this->entityType->expects($this->any())
->method('getKey')
->will($this->returnValueMap([
->willReturnMap([
['id', $entity_keys['id']],
['uuid', $entity_keys['uuid']],
['bundle', $entity_keys['bundle']],
['revision', $entity_keys['revision']],
['langcode', $entity_keys['langcode']],
]));
]);
$this->entityType->expects($this->any())
->method('getRevisionMetadataKeys')
->will($this->returnValue($revision_metadata_keys));
@ -980,13 +980,13 @@ class SqlContentEntityStorageTest extends UnitTestCase {
->will($this->returnValue('entity_test_field_data'));
$this->entityType->expects($this->any())
->method('getKey')
->will($this->returnValueMap([
->willReturnMap([
['id', $entity_keys['id']],
['uuid', $entity_keys['uuid']],
['bundle', $entity_keys['bundle']],
['revision', $entity_keys['revision']],
['langcode', $entity_keys['langcode']],
]));
]);
$this->entityType->expects($this->any())
->method('getRevisionMetadataKeys')
->will($this->returnValue($revision_metadata_field_names));
@ -1424,9 +1424,7 @@ class SqlContentEntityStorageTest extends UnitTestCase {
$this->entityType->expects($this->any())
->method('getKey')
->will($this->returnValueMap(
[['id', 'id']]
));
->willReturnMap([['id', 'id']]);
$method = new \ReflectionMethod($this->entityStorage, 'cleanIds');
$method->setAccessible(TRUE);
@ -1456,10 +1454,10 @@ class SqlContentEntityStorageTest extends UnitTestCase {
protected function setUpModuleHandlerNoImplementations() {
$this->moduleHandler->expects($this->any())
->method('getImplementations')
->will($this->returnValueMap([
->willReturnMap([
['entity_load', []],
[$this->entityTypeId . '_load', []],
]));
]);
$this->container->set('module_handler', $this->moduleHandler);
}

View File

@ -135,9 +135,9 @@ class CustomPageExceptionHtmlSubscriberTest extends UnitTestCase {
->method('getContext')
->willReturn($request_context);
$this->kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
$this->kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) {
return new HtmlResponse($request->getMethod());
}));
});
$event = new ExceptionEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, new NotFoundHttpException('foo'));
@ -162,9 +162,9 @@ class CustomPageExceptionHtmlSubscriberTest extends UnitTestCase {
->method('getContext')
->willReturn($request_context);
$this->kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
$this->kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) {
return new Response($request->getMethod() . ' ' . UrlHelper::buildQuery($request->query->all()));
}));
});
$event = new ExceptionEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, new NotFoundHttpException('foo'));
$this->customPageSubscriber->onException($event);

View File

@ -31,7 +31,7 @@ class ModuleRouteSubscriberTest extends UnitTestCase {
$this->moduleHandler->expects($this->any())
->method('moduleExists')
->will($this->returnValueMap($value_map));
->willReturnMap($value_map);
}
/**

View File

@ -145,9 +145,9 @@ class FormBuilderTest extends FormTestBase {
$form_arg = $this->getMockForm($form_id, $expected_form);
$form_arg->expects($this->any())
->method('submitForm')
->will($this->returnCallback(function ($form, FormStateInterface $form_state) use ($response, $form_state_key) {
->willReturnCallback(function ($form, FormStateInterface $form_state) use ($response, $form_state_key) {
$form_state->setFormState([$form_state_key => $response]);
}));
});
$form_state = new FormState();
try {
@ -192,11 +192,11 @@ class FormBuilderTest extends FormTestBase {
$form_arg = $this->getMockForm($form_id, $expected_form);
$form_arg->expects($this->any())
->method('submitForm')
->will($this->returnCallback(function ($form, FormStateInterface $form_state) use ($response, $redirect) {
->willReturnCallback(function ($form, FormStateInterface $form_state) use ($response, $redirect) {
// Set both the response and the redirect.
$form_state->setResponse($response);
$form_state->set('redirect', $redirect);
}));
});
$form_state = new FormState();
try {

View File

@ -105,10 +105,10 @@ class FormCacheTest extends UnitTestCase {
$this->keyValueExpirableFactory = $this->createMock('Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface');
$this->keyValueExpirableFactory->expects($this->any())
->method('get')
->will($this->returnValueMap([
->willReturnMap([
['form', $this->formCacheStore],
['form_state', $this->formStateCacheStore],
]));
]);
$this->csrfToken = $this->getMockBuilder('Drupal\Core\Access\CsrfTokenGenerator')
->disableOriginalConstructor()

View File

@ -138,10 +138,17 @@ class FormSubmitterTest extends UnitTestCase {
$form_submitter = $this->getFormSubmitter();
$this->urlGenerator->expects($this->once())
->method('generateFromRoute')
->will($this->returnValueMap([
->willReturnMap(
[
['test_route_a', [], ['absolute' => TRUE], FALSE, 'test-route'],
['test_route_b', ['key' => 'value'], ['absolute' => TRUE], FALSE, 'test-route/value'],
])
[
'test_route_b',
['key' => 'value'],
['absolute' => TRUE],
FALSE,
'test-route/value',
],
]
);
$form_state = $this->createMock('Drupal\Core\Form\FormStateInterface');

View File

@ -163,7 +163,7 @@ abstract class FormTestBase extends UnitTestCase {
->getMock();
$this->elementInfo->expects($this->any())
->method('getInfo')
->will($this->returnCallback([$this, 'getInfo']));
->willReturnCallback([$this, 'getInfo']);
$this->csrfToken = $this->getMockBuilder('Drupal\Core\Access\CsrfTokenGenerator')
->disableOriginalConstructor()

View File

@ -84,11 +84,11 @@ class LoggerChannelTest extends UnitTestCase {
$logger = $this->createMock('Psr\Log\LoggerInterface');
$logger->expects($this->once())
->method('log')
->will($this->returnCallback(function () use ($i, &$index_order) {
->willReturnCallback(function () use ($i, &$index_order) {
// Append the $i to the index order, so that we know the order that
// loggers got called with.
$index_order .= $i;
}));
});
$channel->addLogger($logger, $i);
}

View File

@ -283,7 +283,7 @@ class ContextualLinkManagerTest extends UnitTestCase {
}
$this->factory->expects($this->any())
->method('createInstance')
->will($this->returnValueMap($map));
->willReturnMap($map);
$this->moduleHandler->expects($this->exactly(2))
->method('alter')
@ -336,10 +336,10 @@ class ContextualLinkManagerTest extends UnitTestCase {
$this->accessManager->expects($this->any())
->method('checkNamedRoute')
->will($this->returnValueMap([
->willReturnMap([
['test_route', ['key' => 'value'], $this->account, FALSE, TRUE],
['test_route2', ['key' => 'value'], $this->account, FALSE, FALSE],
]));
]);
// Set up mocking of the plugin factory.
$map = [];
@ -361,7 +361,7 @@ class ContextualLinkManagerTest extends UnitTestCase {
}
$this->factory->expects($this->any())
->method('createInstance')
->will($this->returnValueMap($map));
->willReturnMap($map);
$result = $this->contextualLinkManager->getContextualLinksArrayByGroup('group1', ['key' => 'value']);

View File

@ -165,13 +165,25 @@ class DefaultMenuLinkTreeManipulatorsTest extends UnitTestCase {
// calls will be made.
$this->accessManager->expects($this->exactly(5))
->method('checkNamedRoute')
->will($this->returnValueMap([
->willReturnMap([
['example1', [], $this->currentUser, TRUE, AccessResult::forbidden()],
['example2', ['foo' => 'bar'], $this->currentUser, TRUE, AccessResult::allowed()->cachePerPermissions()],
['example3', ['baz' => 'qux'], $this->currentUser, TRUE, AccessResult::neutral()],
[
'example2',
['foo' => 'bar'],
$this->currentUser,
TRUE,
AccessResult::allowed()->cachePerPermissions(),
],
[
'example3',
['baz' => 'qux'],
$this->currentUser,
TRUE,
AccessResult::neutral(),
],
['example5', [], $this->currentUser, TRUE, AccessResult::allowed()],
['user.logout', [], $this->currentUser, TRUE, AccessResult::allowed()],
]));
]);
$this->mockTree();
$this->originalTree[5]->subtree[7]->access = AccessResult::neutral();

View File

@ -188,7 +188,7 @@ class LocalActionManagerTest extends UnitTestCase {
}
$this->factory->expects($this->any())
->method('createInstance')
->will($this->returnValueMap($map));
->willReturnMap($map);
$this->assertEquals($expected_actions, $this->localActionManager->getActionsForRoute($route_appears));
}

View File

@ -91,9 +91,9 @@ abstract class LocalTaskIntegrationTestBase extends UnitTestCase {
// Set all the modules as being existent.
$module_handler->expects($this->any())
->method('moduleExists')
->will($this->returnCallback(function ($module) use ($module_dirs) {
->willReturnCallback(function ($module) use ($module_dirs) {
return isset($module_dirs[$module]);
}));
});
$pluginDiscovery = new YamlDiscovery('links.task', $module_dirs);
$pluginDiscovery = new ContainerDerivativeDiscoveryDecorator($pluginDiscovery);

View File

@ -336,7 +336,7 @@ class LocalTaskManagerTest extends UnitTestCase {
}
$this->factory->expects($this->any())
->method('createInstance')
->will($this->returnValueMap($map));
->willReturnMap($map);
}
/**
@ -468,7 +468,7 @@ class LocalTaskManagerTest extends UnitTestCase {
$this->factory->expects($this->any())
->method('createInstance')
->will($this->returnValueMap($map));
->willReturnMap($map);
}
protected function setupNullCacheabilityMetadataValidation() {

View File

@ -173,9 +173,9 @@ class MenuActiveTrailTest extends UnitTestCase {
if ($expected_link !== NULL) {
$this->menuLinkManager->expects($this->exactly(2))
->method('getParentIds')
->will($this->returnValueMap([
->willReturnMap([
[$expected_link->getPluginId(), $expected_trail_ids],
]));
]);
}
}
@ -213,9 +213,9 @@ class MenuActiveTrailTest extends UnitTestCase {
$this->menuLinkManager->expects($this->any())
->method('getParentIds')
->will($this->returnValueMap([
->willReturnMap([
[$expected_link->getPluginId(), $expected_trail_ids],
]));
]);
$this->assertSame($expected_trail_ids, $this->menuActiveTrail->getActiveTrailIds($data[2]));

View File

@ -90,7 +90,7 @@ class PathProcessorTest extends UnitTestCase {
$alias_manager->expects($this->any())
->method('getPathByAlias')
->will($this->returnValueMap($system_path_map));
->willReturnMap($system_path_map);
// Create a stub config factory with all config settings that will be checked
// during this test.

View File

@ -92,11 +92,20 @@ class HookDiscoveryTest extends UnitTestCase {
$this->moduleHandler->expects($this->any())
->method('invoke')
->will($this->returnValueMap([
['hook_discovery_test', 'test_plugin', [], $this->hookDiscoveryTestTestPlugin()],
['hook_discovery_test2', 'test_plugin', [], $this->hookDiscoveryTest2TestPlugin()],
]
));
->willReturnMap([
[
'hook_discovery_test',
'test_plugin',
[],
$this->hookDiscoveryTestTestPlugin(),
],
[
'hook_discovery_test2',
'test_plugin',
[],
$this->hookDiscoveryTest2TestPlugin(),
],
]);
$this->assertNull($this->hookDiscovery->getDefinition('test_non_existent', FALSE));

View File

@ -71,7 +71,7 @@ abstract class LazyPluginCollectionTestBase extends UnitTestCase {
$create_count = $create_count ?: $this->never();
$this->pluginManager->expects($create_count)
->method('createInstance')
->will($this->returnCallback([$this, 'returnPluginMap']));
->willReturnCallback([$this, 'returnPluginMap']);
$this->defaultPluginCollection = new DefaultLazyPluginCollection($this->pluginManager, $this->config);
}

View File

@ -208,18 +208,19 @@ class RouteBuilderTest extends UnitTestCase {
$container->set('test_module.route_service', new TestRouteSubscriber());
$this->controllerResolver->expects($this->any())
->method('getControllerFromDefinition')
->will($this->returnCallback(function ($controller) use ($container) {
->willReturnCallback(function ($controller) use ($container) {
$count = substr_count($controller, ':');
if ($count == 1) {
list($service, $method) = explode(':', $controller, 2);
[$service, $method] = explode(':', $controller, 2);
$object = $container->get($service);
}
else {
list($class, $method) = explode('::', $controller, 2);
[$class, $method] = explode('::', $controller, 2);
$object = new $class();
}
return [$object, $method];
}));
});
$route_collection_filled = new RouteCollection();
$route_collection_filled->add('test_route.1', new Route('/test-route/1'));

View File

@ -137,10 +137,10 @@ class UrlGeneratorTest extends UnitTestCase {
$this->provider = $provider;
$this->provider->expects($this->any())
->method('getRouteByName')
->will($this->returnValueMap($route_name_return_map));
->willReturnMap($route_name_return_map);
$provider->expects($this->any())
->method('getRoutesByNames')
->will($this->returnValueMap($routes_names_return_map));
->willReturnMap($routes_names_return_map);
// Create an alias manager stub.
$alias_manager = $this->getMockBuilder('Drupal\path_alias\AliasManager')
@ -149,7 +149,7 @@ class UrlGeneratorTest extends UnitTestCase {
$alias_manager->expects($this->any())
->method('getAliasByPath')
->will($this->returnCallback([$this, 'aliasManagerCallback']));
->willReturnCallback([$this, 'aliasManagerCallback']);
$this->aliasManager = $alias_manager;

View File

@ -64,11 +64,11 @@ class UserSessionTest extends UnitTestCase {
->getMock();
$roles['role_one']->expects($this->any())
->method('hasPermission')
->will($this->returnValueMap([
->willReturnMap([
['example permission', TRUE],
['another example permission', FALSE],
['last example permission', FALSE],
]));
]);
$roles['role_two'] = $this->getMockBuilder('Drupal\user\Entity\Role')
->disableOriginalConstructor()
@ -76,11 +76,11 @@ class UserSessionTest extends UnitTestCase {
->getMock();
$roles['role_two']->expects($this->any())
->method('hasPermission')
->will($this->returnValueMap([
->willReturnMap([
['example permission', TRUE],
['another example permission', TRUE],
['last example permission', FALSE],
]));
]);
$roles['anonymous'] = $this->getMockBuilder('Drupal\user\Entity\Role')
->disableOriginalConstructor()
@ -88,11 +88,11 @@ class UserSessionTest extends UnitTestCase {
->getMock();
$roles['anonymous']->expects($this->any())
->method('hasPermission')
->will($this->returnValueMap([
->willReturnMap([
['example permission', FALSE],
['another example permission', FALSE],
['last example permission', FALSE],
]));
]);
$role_storage = $this->getMockBuilder('Drupal\user\RoleStorage')
->setConstructorArgs(['role', new MemoryCache()])
@ -101,14 +101,17 @@ class UserSessionTest extends UnitTestCase {
->getMock();
$role_storage->expects($this->any())
->method('loadMultiple')
->will($this->returnValueMap([
->willReturnMap([
[[], []],
[NULL, $roles],
[['anonymous'], [$roles['anonymous']]],
[['anonymous', 'role_one'], [$roles['role_one']]],
[['anonymous', 'role_two'], [$roles['role_two']]],
[['anonymous', 'role_one', 'role_two'], [$roles['role_one'], $roles['role_two']]],
]));
[
['anonymous', 'role_one', 'role_two'],
[$roles['role_one'], $roles['role_two']],
],
]);
$entity_type_manager = $this->createMock('Drupal\Core\Entity\EntityTypeManagerInterface');
$entity_type_manager->expects($this->any())

View File

@ -56,9 +56,9 @@ class TranslationManagerTest extends UnitTestCase {
$translator->expects($this->once())
->method('getStringTranslation')
->with($langcode, $this->anything(), $this->anything())
->will($this->returnCallback(function ($langcode, $string, $context) {
->willReturnCallback(function ($langcode, $string, $context) {
return $string;
}));
});
$this->translationManager->setDefaultLangcode('fr');
$this->translationManager->addTranslator($translator);
$result = $this->translationManager->formatPlural($count, $singular, $plural, $args, $options);

View File

@ -155,9 +155,9 @@ class TwigExtensionTest extends UnitTestCase {
public function testFormatDate() {
$this->dateFormatter->expects($this->exactly(1))
->method('format')
->will($this->returnCallback(function ($timestamp) {
->willReturnCallback(function ($timestamp) {
return date('Y-m-d', $timestamp);
}));
});
$loader = new StringLoader();
$twig = new Environment($loader);

View File

@ -40,7 +40,7 @@ class PhpTransliterationTest extends UnitTestCase {
$module_handler = $this->createMock('Drupal\Core\Extension\ModuleHandlerInterface');
$module_handler->expects($this->any())
->method('alter')
->will($this->returnCallback(function ($hook, &$overrides, $langcode) {
->willReturnCallback(function ($hook, &$overrides, $langcode) {
if ($langcode == 'zz') {
// The default transliteration of Ä is A, but change it to Z for testing.
$overrides[0xC4] = 'Z';
@ -49,7 +49,7 @@ class PhpTransliterationTest extends UnitTestCase {
$overrides[0x10330] = 'A';
$overrides[0x10338] = 'Th';
}
}));
});
$transliteration = new PhpTransliteration(NULL, $module_handler);
$actual = $transliteration->transliterate($original, $langcode);

View File

@ -99,12 +99,12 @@ class UrlTest extends UnitTestCase {
$this->urlGenerator = $this->createMock('Drupal\Core\Routing\UrlGeneratorInterface');
$this->urlGenerator->expects($this->any())
->method('generateFromRoute')
->will($this->returnValueMap($generate_from_route_map));
->willReturnMap($generate_from_route_map);
$this->pathAliasManager = $this->createMock('Drupal\path_alias\AliasManagerInterface');
$this->pathAliasManager->expects($this->any())
->method('getPathByAlias')
->will($this->returnValueMap($alias_map));
->willReturnMap($alias_map);
$this->router = $this->createMock('Drupal\Tests\Core\Routing\TestRouterInterface');
$this->pathValidator = $this->createMock('Drupal\Core\Path\PathValidatorInterface');

View File

@ -477,11 +477,11 @@ class LinkGeneratorTest extends UnitTestCase {
$this->urlGenerator->expects($this->exactly(4))
->method('getPathFromRoute')
->will($this->returnValueMap([
->willReturnMap([
['test_route_1', [], 'test-route-1'],
['test_route_3', [], 'test-route-3'],
['test_route_4', ['object' => '1'], 'test-route-4/1'],
]));
]);
$this->moduleHandler->expects($this->exactly(5))
->method('alter');
@ -553,9 +553,15 @@ class LinkGeneratorTest extends UnitTestCase {
$options = ['query' => [], 'language' => NULL, 'set_active_class' => FALSE, 'absolute' => FALSE];
$this->urlGenerator->expects($this->any())
->method('generateFromRoute')
->will($this->returnValueMap([
['test_route_1', [], $options, TRUE, (new GeneratedUrl())->setGeneratedUrl('/test-route-1')],
]));
->willReturnMap([
[
'test_route_1',
[],
$options,
TRUE,
(new GeneratedUrl())->setGeneratedUrl('/test-route-1'),
],
]);
$url = new Url('test_route_1');
$url->setUrlGenerator($this->urlGenerator);
@ -584,10 +590,22 @@ class LinkGeneratorTest extends UnitTestCase {
$options = ['query' => [], 'language' => NULL, 'set_active_class' => FALSE, 'absolute' => FALSE];
$this->urlGenerator->expects($this->any())
->method('generateFromRoute')
->will($this->returnValueMap([
['test_route_1', [], $options, TRUE, (new GeneratedUrl())->setGeneratedUrl('/test-route-1')],
['test_route_2', [], $options, TRUE, (new GeneratedUrl())->setGeneratedUrl('/test-route-2')],
]));
->willReturnMap([
[
'test_route_1',
[],
$options,
TRUE,
(new GeneratedUrl())->setGeneratedUrl('/test-route-1'),
],
[
'test_route_2',
[],
$options,
TRUE,
(new GeneratedUrl())->setGeneratedUrl('/test-route-2'),
],
]);
$url = new Url('test_route_2');
$url->setUrlGenerator($this->urlGenerator);

View File

@ -159,7 +159,7 @@ abstract class UnitTestCase extends TestCase {
->getMock();
$immutable_config_object->expects($this->any())
->method('get')
->will($this->returnCallback($config_get));
->willReturnCallback($config_get);
$config_get_map[] = [$config_name, $immutable_config_object];
$mutable_config_object = $this->getMockBuilder('Drupal\Core\Config\Config')
@ -167,7 +167,7 @@ abstract class UnitTestCase extends TestCase {
->getMock();
$mutable_config_object->expects($this->any())
->method('get')
->will($this->returnCallback($config_get));
->willReturnCallback($config_get);
$config_editable_map[] = [$config_name, $mutable_config_object];
}
// Construct a config factory with the array of configuration object stubs
@ -175,10 +175,10 @@ abstract class UnitTestCase extends TestCase {
$config_factory = $this->createMock('Drupal\Core\Config\ConfigFactoryInterface');
$config_factory->expects($this->any())
->method('get')
->will($this->returnValueMap($config_get_map));
->willReturnMap($config_get_map);
$config_factory->expects($this->any())
->method('getEditable')
->will($this->returnValueMap($config_editable_map));
->willReturnMap($config_editable_map);
return $config_factory;
}
@ -265,14 +265,14 @@ abstract class UnitTestCase extends TestCase {
$class_resolver = $this->createMock('Drupal\Core\DependencyInjection\ClassResolverInterface');
$class_resolver->expects($this->any())
->method('getInstanceFromDefinition')
->will($this->returnCallback(function ($class) {
->willReturnCallback(function ($class) {
if (is_subclass_of($class, 'Drupal\Core\DependencyInjection\ContainerInjectionInterface')) {
return $class::create(new ContainerBuilder());
}
else {
return new $class();
}
}));
});
return $class_resolver;
}