Skip to content

Commit

Permalink
Issue #3108006 by mondrake, longwave, ravi.shankar, alexpott: Replace…
Browse files Browse the repository at this point in the history
… assertInternalType() calls with dedicated methods
  • Loading branch information
xjm committed May 4, 2020
1 parent 3bab21f commit 59228b7
Show file tree
Hide file tree
Showing 36 changed files with 56 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function setUp() {
*/
protected function assertDisplay($id, $component_id) {
$component = EntityViewDisplay::load($id)->getComponent($component_id);
$this->assertInternalType('array', $component);
$this->assertIsArray($component);
$this->assertSame('hidden', $component['label']);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function setUp() {
*/
protected function assertDisplay($id, $component_id) {
$component = EntityFormDisplay::load($id)->getComponent($component_id);
$this->assertInternalType('array', $component);
$this->assertIsArray($component);
$this->assertSame('text_textarea_with_summary', $component['type']);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testGetConfig($language_list, $expected_number) {

$config = $this->plugin->getConfig($editor);

$this->assertInternalType('array', $config);
$this->assertIsArray($config);
$this->assertTrue(in_array('ar:Arabic:rtl', $config['language_list']));
$this->assertTrue(in_array('zh-hans:Chinese, Simplified', $config['language_list']));
$this->assertTrue(in_array('en:English', $config['language_list']));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function setUp() {
*/
protected function assertDisplay($id, $component_id) {
$component = EntityViewDisplay::load($id)->getComponent($component_id);
$this->assertInternalType('array', $component);
$this->assertIsArray($component);
$this->assertSame('hidden', $component['label']);
$this->assertSame('comment_default', $component['type']);
$this->assertSame(20, $component['weight']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function setUp() {
*/
protected function assertSubjectVisible($id) {
$component = EntityFormDisplay::load($id)->getComponent('subject');
$this->assertInternalType('array', $component);
$this->assertIsArray($component);
$this->assertSame('string_textfield', $component['type']);
$this->assertSame(10, $component['weight']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function setUp() {
*/
protected function assertDisplay($id, $component_id) {
$component = EntityFormDisplay::load($id)->getComponent($component_id);
$this->assertInternalType('array', $component);
$this->assertIsArray($component);
$this->assertSame('comment_default', $component['type']);
$this->assertSame(20, $component['weight']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function setUp() {
*/
protected function assertDisplay($id, $component_id) {
$component = EntityViewDisplay::load($id)->getComponent($component_id);
$this->assertInternalType('array', $component);
$this->assertIsArray($component);
$this->assertSame('hidden', $component['label']);
$this->assertSame('comment_default', $component['type']);
$this->assertSame(20, $component['weight']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function setUp() {
*/
protected function assertSubjectVisible($id) {
$component = EntityFormDisplay::load($id)->getComponent('subject');
$this->assertInternalType('array', $component);
$this->assertIsArray($component);
$this->assertSame('string_textfield', $component['type']);
$this->assertSame(10, $component['weight']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function setUp() {
*/
protected function assertDisplay($id, $component_id) {
$component = EntityFormDisplay::load($id)->getComponent($component_id);
$this->assertInternalType('array', $component);
$this->assertIsArray($component);
$this->assertSame('comment_default', $component['type']);
$this->assertSame(20, $component['weight']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,22 @@ public function testEntityDisplaySettings() {
// reference field.
$display = EntityViewDisplay::load('node.employee.default');
$component = $display->getComponent('field_company');
$this->assertInternalType('array', $component);
$this->assertIsArray($component);
$this->assertSame('entity_reference_label', $component['type']);
// The default node reference formatter shows the referenced node's title
// as a link.
$this->assertTrue($component['settings']['link']);

$display = EntityViewDisplay::load('node.employee.teaser');
$component = $display->getComponent('field_company');
$this->assertInternalType('array', $component);
$this->assertIsArray($component);
$this->assertSame('entity_reference_label', $component['type']);
// The plain node reference formatter shows the referenced node's title,
// unlinked.
$this->assertFalse($component['settings']['link']);

$component = $display->getComponent('field_commander');
$this->assertInternalType('array', $component);
$this->assertIsArray($component);
$this->assertSame('entity_reference_label', $component['type']);
// The default user reference formatter links to the referenced user.
$this->assertTrue($component['settings']['link']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,22 @@ public function testWidgetSettings() {

$component = $display_repository->getFormDisplay('node', 'employee', 'default')
->getComponent('field_company');
$this->assertInternalType('array', $component);
$this->assertIsArray($component);
$this->assertSame('options_select', $component['type']);

$component = $display_repository->getFormDisplay('node', 'employee', 'default')
->getComponent('field_company_2');
$this->assertInternalType('array', $component);
$this->assertIsArray($component);
$this->assertSame('options_buttons', $component['type']);

$component = $display_repository->getFormDisplay('node', 'employee', 'default')
->getComponent('field_company_3');
$this->assertInternalType('array', $component);
$this->assertIsArray($component);
$this->assertSame('entity_reference_autocomplete_tags', $component['type']);

$component = $display_repository->getFormDisplay('node', 'employee', 'default')
->getComponent('field_commander');
$this->assertInternalType('array', $component);
$this->assertIsArray($component);
$this->assertSame('options_select', $component['type']);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testTransformImageSettings() {
->getMock();

$value = $plugin->transform([[], ['type' => 'image_image'], ['data' => '']], $executable, $row, 'foo');
$this->assertInternalType('array', $value['default_image']);
$this->assertIsArray($value['default_image']);
$this->assertSame('', $value['default_image']['alt']);
$this->assertSame('', $value['default_image']['title']);
$this->assertNull($value['default_image']['width']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testTransformImageSettings() {
]);

$value = $plugin->transform([], $executable, $row, 'foo');
$this->assertInternalType('array', $value);
$this->assertIsArray($value);
$this->assertSame('', $value['default_image']['uuid']);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function testMediaOEmbedVideoSource() {
$display = \Drupal::service('entity_display.repository')->getViewDisplay('media', $media_type_id);
$this->assertFalse($display->isNew());
$component = $display->getComponent('field_media_oembed_video');
$this->assertInternalType('array', $component);
$this->assertIsArray($component);
$component['settings']['max_width'] = 240;
$display->setComponent('field_media_oembed_video', $component);
$this->assertSame(SAVED_UPDATED, $display->save());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testBadHashParameter($hash) {
->get('controller_resolver')
->getControllerFromDefinition('\Drupal\media\Controller\OEmbedIframeController::render');

$this->assertInternalType('callable', $controller);
$this->assertIsCallable($controller);

$this->expectException('\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException');
$this->expectExceptionMessage('This resource is not available');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ protected function assertViewDisplay($type_id, $image_style) {
$this->assertSame(['thumbnail'], array_keys($view_display->getComponents()));
// Assert the thumbnail image style.
$thumbnail = $view_display->getComponent('thumbnail');
$this->assertInternalType('array', $thumbnail);
$this->assertIsArray($thumbnail);
$this->assertSame($image_style, $thumbnail['settings']['image_style']);
}

Expand Down
2 changes: 1 addition & 1 deletion modules/migrate/tests/src/Kernel/process/FileCopyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function testSuccessfulReuse($source_path, $destination_path) {
clearstatcache(TRUE, $destination_path);

$timestamp = (new \SplFileInfo($file_reuse))->getMTime();
$this->assertInternalType('int', $timestamp);
$this->assertIsInt($timestamp);

// We need to make sure the modified timestamp on the file is sooner than
// the attempted migration.
Expand Down
4 changes: 2 additions & 2 deletions modules/system/tests/src/Kernel/Timezone/TimezoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class TimezoneTest extends KernelTestBase {
public function testSystemTimeZones() {
// Test the default parameters for system_time_zones().
$result = system_time_zones();
$this->assertInternalType('array', $result);
$this->assertIsArray($result);
$this->assertArrayHasKey('Africa/Dar_es_Salaam', $result);
$this->assertEquals('Africa/Dar es Salaam', $result['Africa/Dar_es_Salaam']);

// Tests time zone grouping.
$result = system_time_zones(NULL, TRUE);

// Check a two-level time zone.
$this->assertInternalType('array', $result);
$this->assertIsArray($result);
$this->assertArrayHasKey('Africa', $result);
$this->assertArrayHasKey('Africa/Dar_es_Salaam', $result['Africa']);
$this->assertEquals('Dar es Salaam', $result['Africa']['Africa/Dar_es_Salaam']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testUsesGroupBy() {
*/
public function testDefineOptions() {
$options = $this->plugin->defineOptions();
$this->assertInternalType('array', $options);
$this->assertIsArray($options);
$this->assertArrayHasKey('destination', $options);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function testPageController() {
$route_match = RouteMatch::createFromRequest($request);

$output = $this->pageController->handle($route_match->getParameter('view_id'), $route_match->getParameter('display_id'), $route_match);
$this->assertInternalType('array', $output);
$this->assertIsArray($output);
$this->assertEquals($build, $output);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public function testEntityReferenceAutocompleteWidget() {
]);
// To satisfy config schema, the size setting must be an integer, not just
// a numeric value. See https://www.drupal.org/node/2885441.
$this->assertInternalType('integer', $form_display->getComponent($field_name)['settings']['size']);
$this->assertIsInt($form_display->getComponent($field_name)['settings']['size']);
$form_display->save();
$this->assertInternalType('integer', $form_display->getComponent($field_name)['settings']['size']);
$this->assertIsInt($form_display->getComponent($field_name)['settings']['size']);

// Visit the node add page.
$this->drupalGet('node/add/page');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function setUp() {
* @covers ::getContextDefinitions
*/
public function testGetContextDefinitions() {
$this->assertInternalType('array', $this->plugin->getContextDefinitions());
$this->assertIsArray($this->plugin->getContextDefinitions());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testThemeRenderAndAutoescape($arg, $expected) {
$renderer = \Drupal::service('renderer');
$output = $renderer->executeInRenderContext($context, $theme_render_and_autoescape);
$this->assertEquals($expected, $output);
$this->assertInternalType('string', $output);
$this->assertIsString($output);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function setupDefaultExpectations() {
public function testGet() {
$this->setupDefaultExpectations();

$this->assertInternalType('string', $this->generator->get());
$this->assertIsString($this->generator->get());
$this->assertNotSame($this->generator->get(), $this->generator->get($this->randomMachineName()));
$this->assertNotSame($this->generator->get($this->randomMachineName()), $this->generator->get($this->randomMachineName()));
}
Expand All @@ -107,7 +107,7 @@ public function testGenerateSeedOnGet() {
->method('setCsrfTokenSeed')
->with($this->isType('string'));

$this->assertInternalType('string', $this->generator->get());
$this->assertIsString($this->generator->get());
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Drupal/Tests/Core/Batch/BatchBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class BatchBuilderTest extends UnitTestCase {
public function testDefaultValues() {
$batch = (new BatchBuilder())->toArray();

$this->assertInternalType('array', $batch);
$this->assertIsArray($batch);
$this->assertArrayHasKey('operations', $batch);
$this->assertInternalType('array', $batch['operations']);
$this->assertIsArray($batch['operations']);
$this->assertEmpty($batch['operations'], 'Operations array is empty.');
$this->assertEquals(new TranslatableMarkup('Processing'), $batch['title']);
$this->assertEquals(new TranslatableMarkup('Initializing.'), $batch['init_message']);
Expand All @@ -34,10 +34,10 @@ public function testDefaultValues() {
$this->assertNull($batch['finished']);
$this->assertNull($batch['file']);
$this->assertArrayHasKey('library', $batch);
$this->assertInternalType('array', $batch['library']);
$this->assertIsArray($batch['library']);
$this->assertEmpty($batch['library']);
$this->assertArrayHasKey('url_options', $batch);
$this->assertInternalType('array', $batch['url_options']);
$this->assertIsArray($batch['url_options']);
$this->assertEmpty($batch['url_options']);
$this->assertArrayHasKey('progressive', $batch);
$this->assertTrue($batch['progressive']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ public function testToArray() {
->method('getPropertiesToExport')
->willReturn(['id' => 'configId', 'dependencies' => 'dependencies']);
$properties = $this->entity->toArray();
$this->assertInternalType('array', $properties);
$this->assertIsArray($properties);
$this->assertEquals(['configId' => $this->entity->id(), 'dependencies' => []], $properties);
}

Expand All @@ -590,7 +590,7 @@ public function testToArrayIdKey() {
->with('id')
->willReturn('id');
$properties = $entity->toArray();
$this->assertInternalType('array', $properties);
$this->assertIsArray($properties);
$this->assertEquals(['configId' => $entity->id(), 'dependencies' => []], $properties);
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ public function testGetOperations() {
$list->setRedirectDestination($this->redirectDestination);

$operations = $list->getOperations($this->role);
$this->assertInternalType('array', $operations);
$this->assertIsArray($operations);
$this->assertArrayHasKey('edit', $operations);
$this->assertInternalType('array', $operations['edit']);
$this->assertIsArray($operations['edit']);
$this->assertArrayHasKey('title', $operations['edit']);
$this->assertArrayHasKey('delete', $operations);
$this->assertInternalType('array', $operations['delete']);
$this->assertIsArray($operations['delete']);
$this->assertArrayHasKey('title', $operations['delete']);
$this->assertArrayHasKey($operation_name, $operations);
$this->assertInternalType('array', $operations[$operation_name]);
$this->assertIsArray($operations[$operation_name]);
$this->assertArrayHasKey('title', $operations[$operation_name]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ protected function setUp() {
* @covers ::getConstraints
*/
public function testGetConstraints() {
$this->assertInternalType('array', $this->entityAdapter->getConstraints());
$this->assertIsArray($this->entityAdapter->getConstraints());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Drupal/Tests/Core/Lock/LockBackendAbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testWaitTrue() {
*/
public function testGetLockId() {
$lock_id = $this->lock->getLockId();
$this->assertInternalType('string', $lock_id);
$this->assertIsString($lock_id);
// Example lock ID would be '7213141505232b6ee2cb967.27683891'.
$this->assertRegExp('/[\da-f]+\.\d+/', $lock_id);
// Test the same lock ID is returned a second time.
Expand Down
12 changes: 6 additions & 6 deletions tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public function testGetDefinitionsWithoutRequiredInterface() {
$this->expectedDefinitions['banana']['provider'] = 'plugin_test';

$plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, $module_handler, NULL);
$this->assertInternalType('array', $plugin_manager->getDefinitions());
$this->assertIsArray($plugin_manager->getDefinitions());
}

/**
Expand All @@ -344,9 +344,9 @@ public function testGetCacheContexts() {
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
$plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, $module_handler->reveal(), NULL);
$cache_contexts = $plugin_manager->getCacheContexts();
$this->assertInternalType('array', $cache_contexts);
$this->assertIsArray($cache_contexts);
array_map(function ($cache_context) {
$this->assertInternalType('string', $cache_context);
$this->assertIsString($cache_context);
}, $cache_contexts);
}

Expand All @@ -357,9 +357,9 @@ public function testGetCacheTags() {
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
$plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, $module_handler->reveal(), NULL);
$cache_tags = $plugin_manager->getCacheTags();
$this->assertInternalType('array', $cache_tags);
$this->assertIsArray($cache_tags);
array_map(function ($cache_tag) {
$this->assertInternalType('string', $cache_tag);
$this->assertIsString($cache_tag);
}, $cache_tags);
}

Expand All @@ -370,7 +370,7 @@ public function testGetCacheMaxAge() {
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
$plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, $module_handler->reveal(), NULL);
$cache_max_age = $plugin_manager->getCacheMaxAge();
$this->assertInternalType('int', $cache_max_age);
$this->assertIsInt($cache_max_age);
}

/**
Expand Down

0 comments on commit 59228b7

Please sign in to comment.