From 2718a80a6b77297fb5c607271659d8cf1c4cf1a9 Mon Sep 17 00:00:00 2001 From: xjm Date: Mon, 4 May 2020 07:54:15 -0500 Subject: [PATCH] Issue #3131818 by jungle, mero.S: Replace assertions involving calls to is_object() with assertIsObject()/assertIsObject() --- .../file/tests/src/Kernel/LoadTest.php | 2 +- .../src/Functional/NodeLoadMultipleTest.php | 2 +- .../src/Functional/UserRoleAdminTest.php | 2 +- .../FunctionalTests/Image/ToolkitTest.php | 2 +- .../Cache/GenericCacheBackendUnitTestBase.php | 22 +++++++++---------- .../Controller/ControllerResolverTest.php | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/core/modules/file/tests/src/Kernel/LoadTest.php b/core/modules/file/tests/src/Kernel/LoadTest.php index 56212b4bf0e..988a7628bb6 100644 --- a/core/modules/file/tests/src/Kernel/LoadTest.php +++ b/core/modules/file/tests/src/Kernel/LoadTest.php @@ -46,7 +46,7 @@ class LoadTest extends FileManagedUnitTestBase { $file = $this->createFile('druplicon.txt', NULL, 'public'); $by_fid_file = File::load($file->id()); $this->assertFileHookCalled('load'); - $this->assertTrue(is_object($by_fid_file), '\Drupal\file\Entity\File::load() returned an object.'); + $this->assertIsObject($by_fid_file); $this->assertEqual($by_fid_file->id(), $file->id(), 'Loading by fid got the same fid.', 'File'); $this->assertEqual($by_fid_file->getFileUri(), $file->getFileUri(), 'Loading by fid got the correct filepath.', 'File'); $this->assertEqual($by_fid_file->getFilename(), $file->getFilename(), 'Loading by fid got the correct filename.', 'File'); diff --git a/core/modules/node/tests/src/Functional/NodeLoadMultipleTest.php b/core/modules/node/tests/src/Functional/NodeLoadMultipleTest.php index b20a4dc205c..367f66fdb1f 100644 --- a/core/modules/node/tests/src/Functional/NodeLoadMultipleTest.php +++ b/core/modules/node/tests/src/Functional/NodeLoadMultipleTest.php @@ -58,7 +58,7 @@ class NodeLoadMultipleTest extends NodeTestBase { $this->assertTrue(isset($nodes[$node2->id()]), 'Node is correctly keyed in the array'); $this->assertTrue(isset($nodes[$node4->id()]), 'Node is correctly keyed in the array'); foreach ($nodes as $node) { - $this->assertTrue(is_object($node), 'Node is an object'); + $this->assertIsObject($node); } } diff --git a/core/modules/user/tests/src/Functional/UserRoleAdminTest.php b/core/modules/user/tests/src/Functional/UserRoleAdminTest.php index 8697038e24f..bd8e0424e35 100644 --- a/core/modules/user/tests/src/Functional/UserRoleAdminTest.php +++ b/core/modules/user/tests/src/Functional/UserRoleAdminTest.php @@ -63,7 +63,7 @@ class UserRoleAdminTest extends BrowserTestBase { $this->drupalPostForm('admin/people/roles/add', $edit, t('Save')); $this->assertRaw(t('Role %label has been added.', ['%label' => 123])); $role = Role::load($role_name); - $this->assertTrue(is_object($role), 'The role was successfully retrieved from the database.'); + $this->assertIsObject($role); // Check that the role was created in site default language. $this->assertEqual($role->language()->getId(), $default_langcode); diff --git a/core/tests/Drupal/FunctionalTests/Image/ToolkitTest.php b/core/tests/Drupal/FunctionalTests/Image/ToolkitTest.php index e91dab4b297..3c02f38da97 100644 --- a/core/tests/Drupal/FunctionalTests/Image/ToolkitTest.php +++ b/core/tests/Drupal/FunctionalTests/Image/ToolkitTest.php @@ -32,7 +32,7 @@ class ToolkitTest extends ToolkitTestBase { */ public function testLoad() { $image = $this->getImage(); - $this->assertTrue(is_object($image), 'Returned an object.'); + $this->assertIsObject($image); $this->assertEqual($image->getToolkitId(), 'test', 'Image had toolkit set.'); $this->assertToolkitOperationsCalled(['parseFile']); } diff --git a/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php b/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php index a8d042fdfae..4451ec71b3f 100644 --- a/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php +++ b/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php @@ -134,7 +134,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase { $with_backslash = ['foo' => '\Drupal\foo\Bar']; $backend->set('test1', $with_backslash); $cached = $backend->get('test1'); - $this->assert(is_object($cached), "Backend returned an object for cache id test1."); + $this->assertIsObject($cached); $this->assertSame($with_backslash, $cached->data); $this->assertTrue($cached->valid, 'Item is marked as valid.'); // We need to round because microtime may be rounded up in the backend. @@ -144,7 +144,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase { $this->assertFalse($backend->get('test2'), "Backend does not contain data for cache id test2."); $backend->set('test2', ['value' => 3], REQUEST_TIME + 3); $cached = $backend->get('test2'); - $this->assert(is_object($cached), "Backend returned an object for cache id test2."); + $this->assertIsObject($cached); $this->assertSame(['value' => 3], $cached->data); $this->assertTrue($cached->valid, 'Item is marked as valid.'); $this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.'); @@ -153,7 +153,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase { $backend->set('test3', 'foobar', REQUEST_TIME - 3); $this->assertFalse($backend->get('test3'), 'Invalid item not returned.'); $cached = $backend->get('test3', TRUE); - $this->assert(is_object($cached), 'Backend returned an object for cache id test3.'); + $this->assertIsObject($cached); $this->assertFalse($cached->valid, 'Item is marked as valid.'); $this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.'); $this->assertEqual($cached->expire, REQUEST_TIME - 3, 'Expire time is correct.'); @@ -162,7 +162,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase { $with_eof = ['foo' => "\nEOF\ndata"]; $backend->set('test4', $with_eof); $cached = $backend->get('test4'); - $this->assert(is_object($cached), "Backend returned an object for cache id test4."); + $this->assertIsObject($cached); $this->assertSame($with_eof, $cached->data); $this->assertTrue($cached->valid, 'Item is marked as valid.'); $this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.'); @@ -172,7 +172,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase { $with_eof_and_semicolon = ['foo' => "\nEOF;\ndata"]; $backend->set('test5', $with_eof_and_semicolon); $cached = $backend->get('test5'); - $this->assert(is_object($cached), "Backend returned an object for cache id test5."); + $this->assertIsObject($cached); $this->assertSame($with_eof_and_semicolon, $cached->data); $this->assertTrue($cached->valid, 'Item is marked as valid.'); $this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.'); @@ -181,7 +181,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase { $with_variable = ['foo' => '$bar']; $backend->set('test6', $with_variable); $cached = $backend->get('test6'); - $this->assert(is_object($cached), "Backend returned an object for cache id test6."); + $this->assertIsObject($cached); $this->assertSame($with_variable, $cached->data); // Make sure that a cached object is not affected by changing the original. @@ -194,7 +194,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase { // Add a property to the original. It should not appear in the cached data. $data->this_should_not_be_in_the_cache = TRUE; $cached = $backend->get('test7'); - $this->assert(is_object($cached), "Backend returned an object for cache id test7."); + $this->assertIsObject($cached); $this->assertEqual($expected_data, $cached->data); $this->assertFalse(isset($cached->data->this_should_not_be_in_the_cache)); // Add a property to the cache data. It should not appear when we fetch @@ -231,16 +231,16 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase { $this->assertFalse($backend->get('test1'), "Backend does not contain data for cache id test1."); $backend->set('test1', 7); - $this->assert(is_object($backend->get('test1')), "Backend returned an object for cache id test1."); + $this->assertIsObject($backend->get('test1')); $this->assertFalse($backend->get('test2'), "Backend does not contain data for cache id test2."); $backend->set('test2', 3); - $this->assert(is_object($backend->get('test2')), "Backend returned an object for cache id %cid."); + $this->assertIsObject($backend->get('test2')); $backend->delete('test1'); $this->assertFalse($backend->get('test1'), "Backend does not contain data for cache id test1 after deletion."); - $this->assert(is_object($backend->get('test2')), "Backend still has an object for cache id test2."); + $this->assertIsObject($backend->get('test2')); $backend->delete('test2'); $this->assertFalse($backend->get('test2'), "Backend does not contain data for cache id test2 after deletion."); @@ -274,7 +274,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase { // Retrieve and test cache objects. foreach ($variables as $cid => $value) { $object = $backend->get($cid); - $this->assert(is_object($object), sprintf("Backend returned an object for cache id %s.", $cid)); + $this->assertIsObject($object, sprintf("Backend returned an object for cache id %s.", $cid)); $this->assertSame($value, $object->data, sprintf("Data of cached id %s kept is identical in type and value", $cid)); } } diff --git a/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php b/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php index 6483f8e05f5..b9b63e0b18f 100644 --- a/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php +++ b/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php @@ -185,7 +185,7 @@ class ControllerResolverTest extends UnitTestCase { */ protected function assertCallableController($controller, $class, $output) { if ($class) { - $this->assertTrue(is_object($controller[0])); + $this->assertIsObject($controller[0]); $this->assertInstanceOf($class, $controller[0]); } $this->assertIsCallable($controller);