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

(cherry picked from commit 6335af17b4)
merge-requests/444/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()) $this->statement->expects($this->any())
->method('fetchObject') ->method('fetchObject')
->will($this->returnCallback([$this, 'fetchObjectCallback'])); ->willReturnCallback([$this, 'fetchObjectCallback']);
$this->select = $this->getMockBuilder('Drupal\Core\Database\Query\Select') $this->select = $this->getMockBuilder('Drupal\Core\Database\Query\Select')
->disableOriginalConstructor() ->disableOriginalConstructor()

View File

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

View File

@ -21,10 +21,13 @@ class ContentTranslationLocalTasksTest extends LocalTaskIntegrationTestBase {
$entity_type = $this->createMock('Drupal\Core\Entity\EntityTypeInterface'); $entity_type = $this->createMock('Drupal\Core\Entity\EntityTypeInterface');
$entity_type->expects($this->any()) $entity_type->expects($this->any())
->method('getLinkTemplate') ->method('getLinkTemplate')
->will($this->returnValueMap([ ->willReturnMap([
['canonical', 'entity.node.canonical'], ['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 = $this->createMock('Drupal\content_translation\ContentTranslationManagerInterface');
$content_translation_manager->expects($this->any()) $content_translation_manager->expects($this->any())
->method('getSupportedEntityTypes') ->method('getSupportedEntityTypes')

View File

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

View File

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

View File

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

View File

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

View File

@ -129,13 +129,14 @@ class FormErrorHandlerTest extends UnitTestCase {
$this->renderer->expects($this->once()) $this->renderer->expects($this->once())
->method('renderPlain') ->method('renderPlain')
->will($this->returnCallback(function ($render_array) { ->willReturnCallback(function ($render_array) {
$links = []; $links = [];
foreach ($render_array[1]['#items'] as $item) { foreach ($render_array[1]['#items'] as $item) {
$links[] = htmlspecialchars($item['#title']); $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>'; 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 = new FormState();
$form_state->setErrorByName('test1', 'invalid'); $form_state->setErrorByName('test1', 'invalid');

View File

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

View File

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

View File

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

View File

@ -53,9 +53,9 @@ class MachineNameTest extends MigrateProcessTestCase {
->expects($this->once()) ->expects($this->once())
->method('transliterate') ->method('transliterate')
->with($human_name) ->with($human_name)
->will($this->returnCallback(function (string $string): string { ->willReturnCallback(function (string $string): string {
return str_replace(['á', 'é', 'ő'], ['a', 'e', 'o'], $string); return str_replace(['á', 'é', 'ő'], ['a', 'e', 'o'], $string);
})); });
$plugin = new MachineName($configuration, 'machine_name', [], $this->transliteration); $plugin = new MachineName($configuration, 'machine_name', [], $this->transliteration);
$value = $plugin->transform($human_name, $this->migrateExecutable, $this->row, 'destination_property'); $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)); ->will($this->returnValue($this->entityQuery));
$this->entityQuery->expects($this->exactly($count + 1)) $this->entityQuery->expects($this->exactly($count + 1))
->method('execute') ->method('execute')
->will($this->returnCallback(function () use (&$count) { ->willReturnCallback(function () use (&$count) {
return $count--; return $count--;
})); });
} }
/** /**
@ -198,15 +198,15 @@ class MakeUniqueEntityFieldTest extends MigrateProcessTestCase {
} }
$this->entityQuery $this->entityQuery
->method('condition') ->method('condition')
->will($this->returnValueMap($map)); ->willReturnMap($map);
// Entity 'forums' is pre-existing, entity 'test_vocab' was migrated. // Entity 'forums' is pre-existing, entity 'test_vocab' was migrated.
$this->idMap $this->idMap
->method('lookupSourceId') ->method('lookupSourceId')
->will($this->returnValueMap([ ->willReturnMap([
[['test_field' => 'forums'], FALSE], [['test_field' => 'forums'], FALSE],
[['test_field' => 'test_vocab'], ['source_id' => 42]], [['test_field' => 'test_vocab'], ['source_id' => 42]],
])); ]);
// Existing entity 'forums' was not migrated, value should not be unique. // Existing entity 'forums' was not migrated, value should not be unique.
$actual = $plugin->transform('forums', $this->migrateExecutable, $this->row, 'testproperty'); $actual = $plugin->transform('forums', $this->migrateExecutable, $this->row, 'testproperty');

View File

@ -42,10 +42,10 @@ class AliasPathProcessorTest extends UnitTestCase {
public function testProcessInbound() { public function testProcessInbound() {
$this->aliasManager->expects($this->exactly(2)) $this->aliasManager->expects($this->exactly(2))
->method('getPathByAlias') ->method('getPathByAlias')
->will($this->returnValueMap([ ->willReturnMap([
['urlalias', NULL, 'internal-url'], ['urlalias', NULL, 'internal-url'],
['url', NULL, 'url'], ['url', NULL, 'url'],
])); ]);
$request = Request::create('/urlalias'); $request = Request::create('/urlalias');
$this->assertEquals('internal-url', $this->pathProcessor->processInbound('urlalias', $request)); $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) { public function testProcessOutbound($path, array $options, $expected_path) {
$this->aliasManager->expects($this->any()) $this->aliasManager->expects($this->any())
->method('getAliasByPath') ->method('getAliasByPath')
->will($this->returnValueMap([ ->willReturnMap([
['internal-url', NULL, 'urlalias'], ['internal-url', NULL, 'urlalias'],
['url', NULL, 'url'], ['url', NULL, 'url'],
])); ]);
$bubbleable_metadata = new BubbleableMetadata(); $bubbleable_metadata = new BubbleableMetadata();
$this->assertEquals($expected_path, $this->pathProcessor->processOutbound($path, $options, NULL, $bubbleable_metadata)); $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()) $entity->expects($this->any())
->method('hasTranslation') ->method('hasTranslation')
->will($this->returnValueMap([ ->willReturnMap([
[LanguageInterface::LANGCODE_NOT_SPECIFIED, TRUE], [LanguageInterface::LANGCODE_NOT_SPECIFIED, TRUE],
['xx-lolspeak', FALSE], ['xx-lolspeak', FALSE],
])); ]);
$entity->expects($this->any()) $entity->expects($this->any())
->method('hasField') ->method('hasField')
->will($this->returnValueMap([ ->willReturnMap([
['valid', TRUE], ['valid', TRUE],
['not_valid', FALSE], ['not_valid', FALSE],
])); ]);
return $entity; return $entity;
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -33,11 +33,14 @@ class RolesRidTest extends UnitTestCase {
$role_storage = $this->getMockForAbstractClass('Drupal\Core\Entity\EntityStorageInterface'); $role_storage = $this->getMockForAbstractClass('Drupal\Core\Entity\EntityStorageInterface');
$role_storage->expects($this->any()) $role_storage->expects($this->any())
->method('loadMultiple') ->method('loadMultiple')
->will($this->returnValueMap([ ->willReturnMap([
[[], []], [[], []],
[['test_rid_1'], ['test_rid_1' => $role1]], [['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 = $this->createMock('Drupal\Core\Entity\EntityTypeInterface');
$entity_type->expects($this->any()) $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 = $this->createMock('\Drupal\Core\Render\RendererInterface');
$this->renderer->expects($this->any()) $this->renderer->expects($this->any())
->method('render') ->method('render')
->will($this->returnCallback(function (array &$elements) { ->willReturnCallback(function (array &$elements) {
$elements['#attached'] = []; $elements['#attached'] = [];
return isset($elements['#markup']) ? $elements['#markup'] : ''; return isset($elements['#markup']) ? $elements['#markup'] : '';
})); });
$this->renderer->expects($this->any()) $this->renderer->expects($this->any())
->method('executeInRenderContext') ->method('executeInRenderContext')
->willReturnCallback(function (RenderContext $context, callable $callable) { ->willReturnCallback(function (RenderContext $context, callable $callable) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -463,7 +463,7 @@ class EntityResolverManagerTest extends UnitTestCase {
])); ]));
$this->entityTypeManager->expects($this->any()) $this->entityTypeManager->expects($this->any())
->method('getDefinition') ->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') { if ($entity_type == 'entity_test') {
return $definition; return $definition;
} }
@ -473,7 +473,7 @@ class EntityResolverManagerTest extends UnitTestCase {
else { else {
return NULL; return NULL;
} }
})); });
} }
} }

View File

@ -216,9 +216,9 @@ class EntityUnitTest extends UnitTestCase {
public function testLanguage() { public function testLanguage() {
$this->entityType->expects($this->any()) $this->entityType->expects($this->any())
->method('getKey') ->method('getKey')
->will($this->returnValueMap([ ->willReturnMap([
['langcode', 'langcode'], ['langcode', 'langcode'],
])); ]);
$this->assertSame('en', $this->entity->language()->getId()); $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; return $expected_table_schemas[$invocation_count] == $table_schema;
}) })
) )
->will($this->returnCallback(function () use (&$invocation_count) { ->willReturnCallback(function () use (&$invocation_count) {
$invocation_count++; $invocation_count++;
})); });
} }
$connection = $this->getMockBuilder('Drupal\Core\Database\Connection') $connection = $this->getMockBuilder('Drupal\Core\Database\Connection')

View File

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

View File

@ -135,9 +135,9 @@ class CustomPageExceptionHtmlSubscriberTest extends UnitTestCase {
->method('getContext') ->method('getContext')
->willReturn($request_context); ->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()); return new HtmlResponse($request->getMethod());
})); });
$event = new ExceptionEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, new NotFoundHttpException('foo')); $event = new ExceptionEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, new NotFoundHttpException('foo'));
@ -162,9 +162,9 @@ class CustomPageExceptionHtmlSubscriberTest extends UnitTestCase {
->method('getContext') ->method('getContext')
->willReturn($request_context); ->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())); return new Response($request->getMethod() . ' ' . UrlHelper::buildQuery($request->query->all()));
})); });
$event = new ExceptionEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, new NotFoundHttpException('foo')); $event = new ExceptionEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, new NotFoundHttpException('foo'));
$this->customPageSubscriber->onException($event); $this->customPageSubscriber->onException($event);

View File

@ -31,7 +31,7 @@ class ModuleRouteSubscriberTest extends UnitTestCase {
$this->moduleHandler->expects($this->any()) $this->moduleHandler->expects($this->any())
->method('moduleExists') ->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 = $this->getMockForm($form_id, $expected_form);
$form_arg->expects($this->any()) $form_arg->expects($this->any())
->method('submitForm') ->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->setFormState([$form_state_key => $response]);
})); });
$form_state = new FormState(); $form_state = new FormState();
try { try {
@ -192,11 +192,11 @@ class FormBuilderTest extends FormTestBase {
$form_arg = $this->getMockForm($form_id, $expected_form); $form_arg = $this->getMockForm($form_id, $expected_form);
$form_arg->expects($this->any()) $form_arg->expects($this->any())
->method('submitForm') ->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. // Set both the response and the redirect.
$form_state->setResponse($response); $form_state->setResponse($response);
$form_state->set('redirect', $redirect); $form_state->set('redirect', $redirect);
})); });
$form_state = new FormState(); $form_state = new FormState();
try { try {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -188,7 +188,7 @@ class LocalActionManagerTest extends UnitTestCase {
} }
$this->factory->expects($this->any()) $this->factory->expects($this->any())
->method('createInstance') ->method('createInstance')
->will($this->returnValueMap($map)); ->willReturnMap($map);
$this->assertEquals($expected_actions, $this->localActionManager->getActionsForRoute($route_appears)); $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. // Set all the modules as being existent.
$module_handler->expects($this->any()) $module_handler->expects($this->any())
->method('moduleExists') ->method('moduleExists')
->will($this->returnCallback(function ($module) use ($module_dirs) { ->willReturnCallback(function ($module) use ($module_dirs) {
return isset($module_dirs[$module]); return isset($module_dirs[$module]);
})); });
$pluginDiscovery = new YamlDiscovery('links.task', $module_dirs); $pluginDiscovery = new YamlDiscovery('links.task', $module_dirs);
$pluginDiscovery = new ContainerDerivativeDiscoveryDecorator($pluginDiscovery); $pluginDiscovery = new ContainerDerivativeDiscoveryDecorator($pluginDiscovery);

View File

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

View File

@ -173,9 +173,9 @@ class MenuActiveTrailTest extends UnitTestCase {
if ($expected_link !== NULL) { if ($expected_link !== NULL) {
$this->menuLinkManager->expects($this->exactly(2)) $this->menuLinkManager->expects($this->exactly(2))
->method('getParentIds') ->method('getParentIds')
->will($this->returnValueMap([ ->willReturnMap([
[$expected_link->getPluginId(), $expected_trail_ids], [$expected_link->getPluginId(), $expected_trail_ids],
])); ]);
} }
} }
@ -213,9 +213,9 @@ class MenuActiveTrailTest extends UnitTestCase {
$this->menuLinkManager->expects($this->any()) $this->menuLinkManager->expects($this->any())
->method('getParentIds') ->method('getParentIds')
->will($this->returnValueMap([ ->willReturnMap([
[$expected_link->getPluginId(), $expected_trail_ids], [$expected_link->getPluginId(), $expected_trail_ids],
])); ]);
$this->assertSame($expected_trail_ids, $this->menuActiveTrail->getActiveTrailIds($data[2])); $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()) $alias_manager->expects($this->any())
->method('getPathByAlias') ->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 // Create a stub config factory with all config settings that will be checked
// during this test. // during this test.

View File

@ -92,11 +92,20 @@ class HookDiscoveryTest extends UnitTestCase {
$this->moduleHandler->expects($this->any()) $this->moduleHandler->expects($this->any())
->method('invoke') ->method('invoke')
->will($this->returnValueMap([ ->willReturnMap([
['hook_discovery_test', 'test_plugin', [], $this->hookDiscoveryTestTestPlugin()], [
['hook_discovery_test2', 'test_plugin', [], $this->hookDiscoveryTest2TestPlugin()], 'hook_discovery_test',
] 'test_plugin',
)); [],
$this->hookDiscoveryTestTestPlugin(),
],
[
'hook_discovery_test2',
'test_plugin',
[],
$this->hookDiscoveryTest2TestPlugin(),
],
]);
$this->assertNull($this->hookDiscovery->getDefinition('test_non_existent', FALSE)); $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(); $create_count = $create_count ?: $this->never();
$this->pluginManager->expects($create_count) $this->pluginManager->expects($create_count)
->method('createInstance') ->method('createInstance')
->will($this->returnCallback([$this, 'returnPluginMap'])); ->willReturnCallback([$this, 'returnPluginMap']);
$this->defaultPluginCollection = new DefaultLazyPluginCollection($this->pluginManager, $this->config); $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()); $container->set('test_module.route_service', new TestRouteSubscriber());
$this->controllerResolver->expects($this->any()) $this->controllerResolver->expects($this->any())
->method('getControllerFromDefinition') ->method('getControllerFromDefinition')
->will($this->returnCallback(function ($controller) use ($container) { ->willReturnCallback(function ($controller) use ($container) {
$count = substr_count($controller, ':'); $count = substr_count($controller, ':');
if ($count == 1) { if ($count == 1) {
list($service, $method) = explode(':', $controller, 2); [$service, $method] = explode(':', $controller, 2);
$object = $container->get($service); $object = $container->get($service);
} }
else { else {
list($class, $method) = explode('::', $controller, 2); [$class, $method] = explode('::', $controller, 2);
$object = new $class(); $object = new $class();
} }
return [$object, $method]; return [$object, $method];
})); });
$route_collection_filled = new RouteCollection(); $route_collection_filled = new RouteCollection();
$route_collection_filled->add('test_route.1', new Route('/test-route/1')); $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 = $provider;
$this->provider->expects($this->any()) $this->provider->expects($this->any())
->method('getRouteByName') ->method('getRouteByName')
->will($this->returnValueMap($route_name_return_map)); ->willReturnMap($route_name_return_map);
$provider->expects($this->any()) $provider->expects($this->any())
->method('getRoutesByNames') ->method('getRoutesByNames')
->will($this->returnValueMap($routes_names_return_map)); ->willReturnMap($routes_names_return_map);
// Create an alias manager stub. // Create an alias manager stub.
$alias_manager = $this->getMockBuilder('Drupal\path_alias\AliasManager') $alias_manager = $this->getMockBuilder('Drupal\path_alias\AliasManager')
@ -149,7 +149,7 @@ class UrlGeneratorTest extends UnitTestCase {
$alias_manager->expects($this->any()) $alias_manager->expects($this->any())
->method('getAliasByPath') ->method('getAliasByPath')
->will($this->returnCallback([$this, 'aliasManagerCallback'])); ->willReturnCallback([$this, 'aliasManagerCallback']);
$this->aliasManager = $alias_manager; $this->aliasManager = $alias_manager;

View File

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

View File

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

View File

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

View File

@ -40,7 +40,7 @@ class PhpTransliterationTest extends UnitTestCase {
$module_handler = $this->createMock('Drupal\Core\Extension\ModuleHandlerInterface'); $module_handler = $this->createMock('Drupal\Core\Extension\ModuleHandlerInterface');
$module_handler->expects($this->any()) $module_handler->expects($this->any())
->method('alter') ->method('alter')
->will($this->returnCallback(function ($hook, &$overrides, $langcode) { ->willReturnCallback(function ($hook, &$overrides, $langcode) {
if ($langcode == 'zz') { if ($langcode == 'zz') {
// The default transliteration of Ä is A, but change it to Z for testing. // The default transliteration of Ä is A, but change it to Z for testing.
$overrides[0xC4] = 'Z'; $overrides[0xC4] = 'Z';
@ -49,7 +49,7 @@ class PhpTransliterationTest extends UnitTestCase {
$overrides[0x10330] = 'A'; $overrides[0x10330] = 'A';
$overrides[0x10338] = 'Th'; $overrides[0x10338] = 'Th';
} }
})); });
$transliteration = new PhpTransliteration(NULL, $module_handler); $transliteration = new PhpTransliteration(NULL, $module_handler);
$actual = $transliteration->transliterate($original, $langcode); $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 = $this->createMock('Drupal\Core\Routing\UrlGeneratorInterface');
$this->urlGenerator->expects($this->any()) $this->urlGenerator->expects($this->any())
->method('generateFromRoute') ->method('generateFromRoute')
->will($this->returnValueMap($generate_from_route_map)); ->willReturnMap($generate_from_route_map);
$this->pathAliasManager = $this->createMock('Drupal\path_alias\AliasManagerInterface'); $this->pathAliasManager = $this->createMock('Drupal\path_alias\AliasManagerInterface');
$this->pathAliasManager->expects($this->any()) $this->pathAliasManager->expects($this->any())
->method('getPathByAlias') ->method('getPathByAlias')
->will($this->returnValueMap($alias_map)); ->willReturnMap($alias_map);
$this->router = $this->createMock('Drupal\Tests\Core\Routing\TestRouterInterface'); $this->router = $this->createMock('Drupal\Tests\Core\Routing\TestRouterInterface');
$this->pathValidator = $this->createMock('Drupal\Core\Path\PathValidatorInterface'); $this->pathValidator = $this->createMock('Drupal\Core\Path\PathValidatorInterface');

View File

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

View File

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