Issue #3131818 by jungle, mero.S: Replace assertions involving calls to is_object() with assertIsObject()/assertIsObject()

merge-requests/2419/head
xjm 2020-05-04 07:54:15 -05:00
parent 0585f27ca8
commit 2718a80a6b
6 changed files with 16 additions and 16 deletions

View File

@ -46,7 +46,7 @@ class LoadTest extends FileManagedUnitTestBase {
$file = $this->createFile('druplicon.txt', NULL, 'public'); $file = $this->createFile('druplicon.txt', NULL, 'public');
$by_fid_file = File::load($file->id()); $by_fid_file = File::load($file->id());
$this->assertFileHookCalled('load'); $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->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->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'); $this->assertEqual($by_fid_file->getFilename(), $file->getFilename(), 'Loading by fid got the correct filename.', 'File');

View File

@ -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[$node2->id()]), 'Node is correctly keyed in the array');
$this->assertTrue(isset($nodes[$node4->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) { foreach ($nodes as $node) {
$this->assertTrue(is_object($node), 'Node is an object'); $this->assertIsObject($node);
} }
} }

View File

@ -63,7 +63,7 @@ class UserRoleAdminTest extends BrowserTestBase {
$this->drupalPostForm('admin/people/roles/add', $edit, t('Save')); $this->drupalPostForm('admin/people/roles/add', $edit, t('Save'));
$this->assertRaw(t('Role %label has been added.', ['%label' => 123])); $this->assertRaw(t('Role %label has been added.', ['%label' => 123]));
$role = Role::load($role_name); $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. // Check that the role was created in site default language.
$this->assertEqual($role->language()->getId(), $default_langcode); $this->assertEqual($role->language()->getId(), $default_langcode);

View File

@ -32,7 +32,7 @@ class ToolkitTest extends ToolkitTestBase {
*/ */
public function testLoad() { public function testLoad() {
$image = $this->getImage(); $image = $this->getImage();
$this->assertTrue(is_object($image), 'Returned an object.'); $this->assertIsObject($image);
$this->assertEqual($image->getToolkitId(), 'test', 'Image had toolkit set.'); $this->assertEqual($image->getToolkitId(), 'test', 'Image had toolkit set.');
$this->assertToolkitOperationsCalled(['parseFile']); $this->assertToolkitOperationsCalled(['parseFile']);
} }

View File

@ -134,7 +134,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
$with_backslash = ['foo' => '\Drupal\foo\Bar']; $with_backslash = ['foo' => '\Drupal\foo\Bar'];
$backend->set('test1', $with_backslash); $backend->set('test1', $with_backslash);
$cached = $backend->get('test1'); $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->assertSame($with_backslash, $cached->data);
$this->assertTrue($cached->valid, 'Item is marked as valid.'); $this->assertTrue($cached->valid, 'Item is marked as valid.');
// We need to round because microtime may be rounded up in the backend. // 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."); $this->assertFalse($backend->get('test2'), "Backend does not contain data for cache id test2.");
$backend->set('test2', ['value' => 3], REQUEST_TIME + 3); $backend->set('test2', ['value' => 3], REQUEST_TIME + 3);
$cached = $backend->get('test2'); $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->assertSame(['value' => 3], $cached->data);
$this->assertTrue($cached->valid, 'Item is marked as valid.'); $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.'); $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); $backend->set('test3', 'foobar', REQUEST_TIME - 3);
$this->assertFalse($backend->get('test3'), 'Invalid item not returned.'); $this->assertFalse($backend->get('test3'), 'Invalid item not returned.');
$cached = $backend->get('test3', TRUE); $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->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->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.'); $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"]; $with_eof = ['foo' => "\nEOF\ndata"];
$backend->set('test4', $with_eof); $backend->set('test4', $with_eof);
$cached = $backend->get('test4'); $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->assertSame($with_eof, $cached->data);
$this->assertTrue($cached->valid, 'Item is marked as valid.'); $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.'); $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"]; $with_eof_and_semicolon = ['foo' => "\nEOF;\ndata"];
$backend->set('test5', $with_eof_and_semicolon); $backend->set('test5', $with_eof_and_semicolon);
$cached = $backend->get('test5'); $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->assertSame($with_eof_and_semicolon, $cached->data);
$this->assertTrue($cached->valid, 'Item is marked as valid.'); $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.'); $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']; $with_variable = ['foo' => '$bar'];
$backend->set('test6', $with_variable); $backend->set('test6', $with_variable);
$cached = $backend->get('test6'); $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); $this->assertSame($with_variable, $cached->data);
// Make sure that a cached object is not affected by changing the original. // 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. // Add a property to the original. It should not appear in the cached data.
$data->this_should_not_be_in_the_cache = TRUE; $data->this_should_not_be_in_the_cache = TRUE;
$cached = $backend->get('test7'); $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->assertEqual($expected_data, $cached->data);
$this->assertFalse(isset($cached->data->this_should_not_be_in_the_cache)); $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 // 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."); $this->assertFalse($backend->get('test1'), "Backend does not contain data for cache id test1.");
$backend->set('test1', 7); $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."); $this->assertFalse($backend->get('test2'), "Backend does not contain data for cache id test2.");
$backend->set('test2', 3); $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'); $backend->delete('test1');
$this->assertFalse($backend->get('test1'), "Backend does not contain data for cache id test1 after deletion."); $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'); $backend->delete('test2');
$this->assertFalse($backend->get('test2'), "Backend does not contain data for cache id test2 after deletion."); $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. // Retrieve and test cache objects.
foreach ($variables as $cid => $value) { foreach ($variables as $cid => $value) {
$object = $backend->get($cid); $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)); $this->assertSame($value, $object->data, sprintf("Data of cached id %s kept is identical in type and value", $cid));
} }
} }

View File

@ -185,7 +185,7 @@ class ControllerResolverTest extends UnitTestCase {
*/ */
protected function assertCallableController($controller, $class, $output) { protected function assertCallableController($controller, $class, $output) {
if ($class) { if ($class) {
$this->assertTrue(is_object($controller[0])); $this->assertIsObject($controller[0]);
$this->assertInstanceOf($class, $controller[0]); $this->assertInstanceOf($class, $controller[0]);
} }
$this->assertIsCallable($controller); $this->assertIsCallable($controller);