Commit 00efdb11 authored by catch's avatar catch
Browse files

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

(cherry picked from commit 6335af17)
parent 8ea7c1f6
......@@ -57,7 +57,7 @@ protected function setUp(): void {
$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()
......
......@@ -506,7 +506,7 @@ public function testHasSchema(array $mock_return_values, $expected) {
$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 @@ public function testHasTranslatable(array $mock_return_values, $expected) {
$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 @@ public function testHasTranslation(array $mock_return_values, $expected) {
$this->localeConfigManager
->expects($this->any())
->method('hasTranslation')
->will($this->returnValueMap($map));
->willReturnMap($map);
$result = $this->configNamesMapper->hasTranslation($language);
$this->assertSame($expected, $result);
......
......@@ -21,10 +21,13 @@ protected function setUp(): void {
$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')
......
......@@ -78,9 +78,9 @@ protected function setUp(): void {
$this->member
->expects($this->any())
->method('hasPermission')
->will($this->returnValueMap([
->willReturnMap([
['administer node fields', TRUE],
]));
]);
$this->member
->expects($this->any())
->method('id')
......
......@@ -68,7 +68,7 @@ public function testApplies($expected, $route_name = NULL, $parameter_map = [])
->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 @@ public function testBuild() {
$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(
[
......
......@@ -75,7 +75,7 @@ public function testApplies($expected, $route_name = NULL, $parameter_map = [])
->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 @@ public function testBuild() {
$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(
[
......
......@@ -73,7 +73,7 @@ protected function getImageStyleMock($image_effect_id, $image_effect, $stubs = [
->will($this->returnValue($effectManager));
$image_style->expects($this->any())
->method('fileDefaultScheme')
->will($this->returnCallback([$this, 'fileDefaultScheme']));
->willReturnCallback([$this, 'fileDefaultScheme']);
return $image_style;
}
......
......@@ -129,13 +129,14 @@ public function testErrorMessagesInline() {
$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');
......
......@@ -134,9 +134,9 @@ protected function mockUrlAssembler() {
$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);
......
......@@ -157,16 +157,17 @@ public function testResolveCacheMissWithFallback($langcode, $string, $context, $
// 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 @@ public function testResolveCacheMissWithFallback($langcode, $string, $context, $
default:
return [];
}
}));
});
$this->cache->expects($this->once())
->method('get')
......@@ -289,20 +290,21 @@ public function testResolveCacheMissNoTranslation() {
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);
......
......@@ -35,9 +35,9 @@ public function testTransformSourceArray() {
$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 @@ public function testTransformSourceArrayAt() {
$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);
}
......
......@@ -53,9 +53,9 @@ public function testMachineNames(string $human_name, array $configuration, strin
->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');
......
......@@ -168,9 +168,9 @@ protected function entityQueryExpects($count) {
->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 @@ public function testMakeUniqueEntityFieldMigrated() {
}
$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');
......
......@@ -42,10 +42,10 @@ protected function setUp(): void {
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 @@ public function testProcessInbound() {
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));
......
......@@ -132,16 +132,16 @@ protected function createMockEntity() {
$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;
}
......
......@@ -189,7 +189,7 @@ public function testBuildWithTwoPathElements() {
$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 @@ public function testBuildWithTwoPathElements() {
'_raw_variables' => new ParameterBag([]),
];
}
}));
});
$this->setupAccessManagerToAllow();
......@@ -229,7 +229,7 @@ public function testBuildWithThreePathElements() {
$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 @@ public function testBuildWithThreePathElements() {
'_raw_variables' => new ParameterBag([]),
];
}
}));
});
$this->accessManager->expects($this->any())
->method('check')
......@@ -364,7 +364,7 @@ public function testBuildWithUserPath() {
$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 @@ public function testBuildWithUserPath() {
'_raw_variables' => new ParameterBag([]),
];
}
}));
});
$this->setupAccessManagerToAllow();
$this->titleResolver->expects($this->once())
......
......@@ -76,12 +76,11 @@ public function testAccess($requirements, $access, array $contexts = [], $messag
$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));
......
......@@ -171,11 +171,11 @@ public function testBuildPermissionsSortPerModule() {
]);
$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');
......
......@@ -87,10 +87,10 @@ protected function setUp(): void {
$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 @@ protected function setUp(): void {
$this->emailViewer
->expects($this->any())
->method('hasPermission')
->will($this->returnValueMap([
->willReturnMap([
['view user email addresses', TRUE],
]));
]);
$this->emailViewer
->expects($this->any())
->method('id')
......
......@@ -33,11 +33,14 @@ public function testTitleQuery() {
$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())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment