Skip to content

Commit

Permalink
Issue #3131818 by jungle, mero.S, xjm: Replace assertions involving c…
Browse files Browse the repository at this point in the history
…alls to is_object() with assertIsObject()/assertIsObject()
  • Loading branch information
xjm committed May 4, 2020
1 parent 99fc0a9 commit 963f652
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion modules/file/tests/src/Kernel/LoadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testSingleValues() {
$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');
Expand Down
2 changes: 1 addition & 1 deletion modules/node/tests/src/Functional/NodeLoadMultipleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testNodeMultipleLoad() {
$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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/user/tests/src/Functional/UserRoleAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testRoleAdministration() {
$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);
Expand Down
2 changes: 1 addition & 1 deletion tests/Drupal/FunctionalTests/Image/ToolkitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testGetAvailableToolkits() {
*/
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']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function testSetGet() {
$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.
Expand All @@ -144,7 +144,7 @@ public function testSetGet() {
$this->assertSame(FALSE, $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.');
Expand All @@ -153,7 +153,7 @@ public function testSetGet() {
$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.');
Expand All @@ -162,7 +162,7 @@ public function testSetGet() {
$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.');
Expand All @@ -172,7 +172,7 @@ public function testSetGet() {
$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.');
Expand All @@ -181,7 +181,7 @@ public function testSetGet() {
$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.
Expand All @@ -194,7 +194,7 @@ public function testSetGet() {
// 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
Expand Down Expand Up @@ -231,16 +231,16 @@ public function testDelete() {

$this->assertSame(FALSE, $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->assertSame(FALSE, $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->assertSame(FALSE, $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->assertSame(FALSE, $backend->get('test2'), "Backend does not contain data for cache id test2 after deletion.");
Expand Down Expand Up @@ -274,7 +274,7 @@ public function testValueTypeIsKept() {
// 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));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function testGetControllerFromDefinitionNotCallable() {
*/
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);
Expand Down

0 comments on commit 963f652

Please sign in to comment.