Commit 286c1b57 authored by catch's avatar catch
Browse files

Issue #3130811 by mondrake, jungle, longwave, ravi.shankar: Remove redundant...

Issue #3130811 by mondrake, jungle, longwave, ravi.shankar: Remove redundant $message from assert(Not)InstanceOf calls
parent 8e265e8f
......@@ -85,7 +85,7 @@ public function testCronDeleteNonExistingTemporary() {
// Delete the file, but leave it in the file_managed table.
\Drupal::service('file_system')->delete($file->getFileUri());
$this->assertFalse(file_exists($file->getFileUri()), 'File is deleted from the filesystem.');
$this->assertInstanceOf(File::class, File::load($file->id()), 'File exist in file_managed table');
$this->assertInstanceOf(File::class, File::load($file->id()));
// Call file_cron() to clean up the file. Make sure the changed timestamp
// of the file is older than the system.file.temporary_maximum_age
......
......@@ -93,8 +93,8 @@ public function testFileItem() {
$entity->save();
$entity = EntityTest::load($entity->id());
$this->assertTrue($entity->file_test instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->file_test[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertInstanceOf(FieldItemListInterface::class, $entity->file_test);
$this->assertInstanceOf(FieldItemInterface::class, $entity->file_test[0]);
$this->assertEqual($entity->file_test->target_id, $this->file->id());
$this->assertEqual($entity->file_test->display, 1);
$this->assertEqual($entity->file_test->description, $description);
......
......@@ -53,7 +53,7 @@ protected function setUp() {
protected function assertEntity($fid, $name, $size, $uri, $type, $uid) {
/** @var \Drupal\file\FileInterface $file */
$file = File::load($fid);
$this->assertTrue($file instanceof FileInterface);
$this->assertInstanceOf(FileInterface::class, $file);
$this->assertIdentical($name, $file->getFilename());
$this->assertIdentical($size, $file->getSize());
$this->assertIdentical($uri, $file->getFileUri());
......
......@@ -335,7 +335,7 @@ public function testTypedDataAPI() {
$definition = DataDefinition::create('filter_format');
$data = \Drupal::typedDataManager()->create($definition);
$this->assertTrue($data instanceof OptionsProviderInterface, 'Typed data object implements \Drupal\Core\TypedData\OptionsProviderInterface');
$this->assertInstanceOf(OptionsProviderInterface::class, $data);
$filtered_html_user = $this->createUser(['uid' => 2], [
FilterFormat::load('filtered_html')->getPermissionName(),
......
......@@ -89,8 +89,8 @@ public function testImageItem() {
$entity->save();
$entity = EntityTest::load($entity->id());
$this->assertTrue($entity->image_test instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->image_test[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertInstanceOf(FieldItemListInterface::class, $entity->image_test);
$this->assertInstanceOf(FieldItemInterface::class, $entity->image_test[0]);
$this->assertEqual($entity->image_test->target_id, $this->image->id());
$this->assertEqual($entity->image_test->alt, $alt);
$this->assertEqual($entity->image_test->title, $title);
......
......@@ -51,7 +51,7 @@ public function testImageStylesMigration() {
*/
protected function assertEntity($id, $label, array $expected_effect_plugins, array $expected_effect_config) {
$style = ImageStyle::load($id);
$this->assertTrue($style instanceof ImageStyleInterface);
$this->assertInstanceOf(ImageStyleInterface::class, $style);
/** @var \Drupal\image\ImageStyleInterface $style */
$this->assertIdentical($id, $style->id());
$this->assertIdentical($label, $style->label());
......@@ -62,7 +62,7 @@ protected function assertEntity($id, $label, array $expected_effect_plugins, arr
$index = 0;
foreach ($effects as $effect) {
$this->assertTrue($effect instanceof ImageEffectBase);
$this->assertInstanceOf(ImageEffectBase::class, $effect);
$this->assertIdentical($expected_effect_plugins[$index], $effect->getPluginId());
$config = $effect->getConfiguration();
$this->assertIdentical($expected_effect_config[$index], $config['data']);
......
......@@ -102,7 +102,7 @@ public function testFallbackNormalizer() {
];
$value = $this->sut->normalize($this->node->field_text, 'api_json', $context);
$this->assertTrue($value instanceof CacheableNormalization);
$this->assertInstanceOf(CacheableNormalization::class, $value);
$nested_field = [
$this->node->field_text,
......@@ -117,7 +117,7 @@ public function testFallbackNormalizer() {
// When wrapped in an array, we should still be using the JSON:API
// serializer.
$value = $this->sut->normalize($nested_field, 'api_json', $context);
$this->assertTrue($value[0] instanceof CacheableNormalization);
$this->assertInstanceOf(CacheableNormalization::class, $value[0]);
// Continue to use the fallback normalizer when we need it.
$data = Markup::create('<h2>Test Markup</h2>');
......
......@@ -32,7 +32,7 @@ class MigrateLanguageTest extends MigrateDrupal6TestBase {
protected function assertLanguage($id, $label, $direction = ConfigurableLanguageInterface::DIRECTION_LTR, $weight = 0) {
/** @var \Drupal\language\ConfigurableLanguageInterface $language */
$language = ConfigurableLanguage::load($id);
$this->assertTrue($language instanceof ConfigurableLanguageInterface);
$this->assertInstanceOf(ConfigurableLanguageInterface::class, $language);
$this->assertIdentical($label, $language->label());
$this->assertIdentical($direction, $language->getDirection());
$this->assertIdentical(0, $language->getWeight());
......
......@@ -92,8 +92,8 @@ public function testLinkItem() {
// Verify that the field value is changed.
$id = $entity->id();
$entity = EntityTest::load($id);
$this->assertTrue($entity->field_test instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->field_test[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertInstanceOf(FieldItemListInterface::class, $entity->field_test);
$this->assertInstanceOf(FieldItemInterface::class, $entity->field_test[0]);
$this->assertEqual($entity->field_test->uri, $parsed_url['path']);
$this->assertEqual($entity->field_test[0]->uri, $parsed_url['path']);
$this->assertEqual($entity->field_test->title, $title);
......
......@@ -472,11 +472,11 @@ protected function assertTranslation($config_name, $translation, $langcode, $cus
]);
$this->assertIdentical(1, count($strings));
$string = reset($strings);
$this->assertTrue($string instanceof StringInterface);
$this->assertInstanceOf(StringInterface::class, $string);
/** @var \Drupal\locale\StringInterface $string */
$this->assertIdentical($translation, $string->getString());
$this->assertTrue($string->isTranslation());
$this->assertTrue($string instanceof TranslationString);
$this->assertInstanceOf(TranslationString::class, $string);
/** @var \Drupal\locale\TranslationString $string */
// Make sure the string is marked as customized so that it does not get
// overridden when the string translations are updated.
......
......@@ -86,7 +86,7 @@ public function testMediaTypes() {
$source = $media_type->getSource();
/** @var \Drupal\field\FieldConfigInterface $source_field */
$source_field = $source->getSourceFieldDefinition($media_type);
$this->assertInstanceOf(FieldConfigInterface::class, $source_field, 'Source field exists.');
$this->assertInstanceOf(FieldConfigInterface::class, $source_field);
$this->assertFalse($source_field->isNew(), 'Source field was saved.');
/** @var \Drupal\field\FieldStorageConfigInterface $storage */
$storage = $source_field->getFieldStorageDefinition();
......
......@@ -22,12 +22,12 @@ class MediaCreationTest extends MediaKernelTestBase {
public function testMediaTypeCreation() {
$media_type_storage = $this->container->get('entity_type.manager')->getStorage('media_type');
$this->assertInstanceOf(MediaTypeInterface::class, MediaType::load($this->testMediaType->id()), 'The new media type has not been correctly created in the database.');
$this->assertInstanceOf(MediaTypeInterface::class, MediaType::load($this->testMediaType->id()));
// Test a media type created from default configuration.
$this->container->get('module_installer')->install(['media_test_type']);
$test_media_type = $media_type_storage->load('test');
$this->assertInstanceOf(MediaTypeInterface::class, $test_media_type, 'The media type from default configuration has not been created in the database.');
$this->assertInstanceOf(MediaTypeInterface::class, $test_media_type);
$this->assertSame('Test type', $test_media_type->get('label'), 'Could not assure the correct type name.');
$this->assertSame('Test type.', $test_media_type->get('description'), 'Could not assure the correct type description.');
$this->assertSame('test', $test_media_type->get('source'), 'Could not assure the correct media source.');
......@@ -69,9 +69,9 @@ public function testMediaEntityCreation() {
]);
$media->save();
$this->assertNotInstanceOf(MediaInterface::class, Media::load(rand(1000, 9999)), 'Failed asserting a non-existent media.');
$this->assertNotInstanceOf(MediaInterface::class, Media::load(rand(1000, 9999)));
$this->assertInstanceOf(MediaInterface::class, Media::load($media->id()), 'The new media item has not been created in the database.');
$this->assertInstanceOf(MediaInterface::class, Media::load($media->id()));
$this->assertSame($this->testMediaType->id(), $media->bundle(), 'The media item was not created with the correct type.');
$this->assertSame('Unnamed', $media->getName(), 'The media item was not created with the correct name.');
$source_field_name = $media->bundle->entity->getSource()->getSourceFieldDefinition($media->bundle->entity)->getName();
......
......@@ -65,7 +65,7 @@ public function testRediscover() {
$tree_element = reset($menu_tree);
$this->assertEqual('route_name_2', $tree_element->link->getRouteName());
$title = $tree_element->link->getTitle();
$this->assertFalse($title instanceof TranslatableMarkup);
$this->assertNotInstanceOf(TranslatableMarkup::class, $title);
$this->assertIdentical('<script>alert("Welcome to the discovered jungle!")</script>', $title);
// Create a hierarchy.
......
......@@ -222,7 +222,7 @@ public function testMenuNodeFormWidget() {
// Assert that the link is still in the Administration menu after save.
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
$link = MenuLinkContent::load($item->id());
$this->assertInstanceOf(MenuLinkContent::class, $link, 'Link in not allowed menu still exists after saving node');
$this->assertInstanceOf(MenuLinkContent::class, $link);
// Move the menu link back to the Tools menu.
$item->menu_name->value = 'tools';
......
......@@ -621,7 +621,7 @@ public function addMenuLink($parent = '', $path = '/', $menu_name = 'tools', $ex
$menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')->loadByProperties(['title' => $title]);
$menu_link = reset($menu_links);
$this->assertInstanceOf(MenuLinkContent::class, $menu_link, 'Menu link was found in database.');
$this->assertInstanceOf(MenuLinkContent::class, $menu_link);
$this->assertMenuLink(['menu_name' => $menu_name, 'children' => [], 'parent' => $parent], $menu_link->getPluginId());
return $menu_link;
......
......@@ -276,7 +276,7 @@ public function testNewHighwater() {
$source = $this->getSource($configuration, [], MigrateIdMapInterface::STATUS_IMPORTED, $this->row['timestamp'] - 1);
$source->rewind();
$this->assertInstanceOf(Row::class, $source->current(), 'Incoming row timestamp is greater than current highwater mark so we have a row.');
$this->assertInstanceOf(Row::class, $source->current());
}
/**
......
......@@ -33,7 +33,7 @@ protected function setUp() {
*/
protected function assertEntity($id, $label) {
$override = BaseFieldOverride::load($id);
$this->assertTrue($override instanceof BaseFieldOverride);
$this->assertInstanceOf(BaseFieldOverride::class, $override);
/** @var \Drupal\Core\Field\Entity\BaseFieldOverride $override */
$this->assertIdentical($label, $override->getLabel());
}
......@@ -54,7 +54,7 @@ public function testMigration() {
];
foreach ($no_override_node_type as $type) {
$override = BaseFieldOverride::load("node.$type.title");
$this->assertFalse($override instanceof BaseFieldOverride);
$this->assertNotInstanceOf(BaseFieldOverride::class, $override);
}
}
......
......@@ -47,7 +47,7 @@ protected function setUp() {
protected function assertEntity($id, $label, $description, $help, $display_submitted, $new_revision, $expected_available_menus, $expected_parent, $body_label = NULL) {
/** @var \Drupal\node\NodeTypeInterface $entity */
$entity = NodeType::load($id);
$this->assertTrue($entity instanceof NodeTypeInterface);
$this->assertInstanceOf(NodeTypeInterface::class, $entity);
$this->assertIdentical($label, $entity->label());
$this->assertIdentical($description, $entity->getDescription());
......@@ -59,7 +59,7 @@ protected function assertEntity($id, $label, $description, $help, $display_submi
if ($body_label) {
/** @var \Drupal\field\FieldConfigInterface $body */
$body = FieldConfig::load('node.' . $id . '.body');
$this->assertTrue($body instanceof FieldConfigInterface);
$this->assertInstanceOf(FieldConfigInterface::class, $body);
$this->assertIdentical($body_label, $body->label());
}
......
......@@ -57,7 +57,7 @@ public function testFieldOverrides() {
/** @var \Drupal\node\NodeInterface $node */
$node = Node::create(['type' => 'ponies']);
$owner = $node->getOwner();
$this->assertTrue($owner instanceof UserInterface);
$this->assertInstanceOf(UserInterface::class, $owner);
$this->assertEqual($owner->id(), $this->user->id());
}
......
......@@ -3,7 +3,6 @@
namespace Drupal\Tests\serialization\Kernel;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\entity_test\Entity\EntitySerializedField;
use Drupal\entity_test\Entity\EntityTestMulRev;
use Drupal\filter\Entity\FilterFormat;
......@@ -254,7 +253,7 @@ public function testDenormalize() {
foreach (['json', 'xml'] as $type) {
$denormalized = $this->serializer->denormalize($normalized, $this->entityClass, $type, ['entity_type' => 'entity_test_mulrev']);
$this->assertTrue($denormalized instanceof $this->entityClass, new FormattableMarkup('Denormalized entity is an instance of @class', ['@class' => $this->entityClass]));
$this->assertInstanceOf($this->entityClass, $denormalized);
$this->assertIdentical($denormalized->getEntityTypeId(), $this->entity->getEntityTypeId(), 'Expected entity type found.');
$this->assertIdentical($denormalized->bundle(), $this->entity->bundle(), 'Expected entity bundle found.');
$this->assertIdentical($denormalized->uuid(), $this->entity->uuid(), 'Expected entity UUID found.');
......
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