Skip to content

Commit

Permalink
Issue #3131817 by quietone, Suresh Prabhu Parkala, jungle, mondrake, …
Browse files Browse the repository at this point in the history
…daffie, xjm, catch: Replace assertions involving calls to is_numeric() with assertIsNumeric()/assertIsNotNumeric()
  • Loading branch information
xjm committed May 3, 2020
1 parent d77c05b commit e1f3a8b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testAggregatorFeedImport() {
// The feed's last checked time can change as the fixture is updated, so
// assert that its format is correct.
$checked_time = $feed->getLastCheckedTime();
$this->assertTrue(is_numeric($checked_time));
$this->assertIsNumeric($checked_time);
$this->assertTrue($checked_time > 1000000000);
$this->assertIdentical('0', $feed->getQueuedTime());
$this->assertIdentical('http://knowyourmeme.com', $feed->link->value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public function testRevisions() {
]));
if ($delta > 0) {
$this->assertInstanceOf(UserInterface::class, $loaded->getRevisionUser());
$this->assertTrue(is_numeric($loaded->getRevisionUserId()), 'Revision User ID found.');
$this->assertTrue(is_numeric($loaded->getRevisionCreationTime()), 'Revision time found.');
$this->assertIsNumeric($loaded->getRevisionUserId());
$this->assertIsNumeric($loaded->getRevisionCreationTime());
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/history/tests/src/Functional/HistoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function testHistory() {
$response = $this->markNodeAsRead($nid);
$this->assertEquals(200, $response->getStatusCode());
$timestamp = Json::decode($response->getBody());
$this->assertTrue(is_numeric($timestamp), 'Node has been marked as read. Timestamp received.');
$this->assertIsNumeric($timestamp);

// Retrieve "last read" timestamp for test node, for the current user.
$response = $this->getNodeReadTimestamps([$nid]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ public function testModuleMetaData() {
// Use 0 if mtime isn't present, to avoid an array index notice.
$test_mtime = !empty($modules['system']->info['mtime']) ? $modules['system']->info['mtime'] : 0;
// Ensure the mtime field contains a number that is greater than zero.
$this->assertTrue(is_numeric($test_mtime) && ($test_mtime > 0), 'The system.info.yml file modification time field contains a timestamp.');
$this->assertIsNumeric($test_mtime);
$this->assertGreaterThan(0, $test_mtime);
}

/**
Expand Down Expand Up @@ -355,7 +356,8 @@ public function testThemeMetaData() {
// Use 0 if mtime isn't present, to avoid an array index notice.
$test_mtime = !empty($themes['bartik']->info['mtime']) ? $themes['bartik']->info['mtime'] : 0;
// Ensure the mtime field contains a number that is greater than zero.
$this->assertTrue(is_numeric($test_mtime) && ($test_mtime > 0), 'The bartik.info.yml file modification time field contains a timestamp.');
$this->assertIsNumeric($test_mtime);
$this->assertGreaterThan(0, $test_mtime);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion tests/Drupal/Tests/Component/Utility/SortArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\Tests\Component\Utility;

use Drupal\Component\Utility\SortArray;
use Drupal\Tests\PhpunitCompatibilityTrait;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -14,6 +15,8 @@
*/
class SortArrayTest extends TestCase {

use PhpunitCompatibilityTrait;

/**
* Tests SortArray::sortByWeightElement() input against expected output.
*
Expand Down Expand Up @@ -316,7 +319,8 @@ public function providerSortByTitleProperty() {
* Actual comparison function return value.
*/
protected function assertBothNegativePositiveOrZero($expected, $result) {
$this->assertTrue(is_numeric($expected) && is_numeric($result), 'Parameters are numeric.');
$this->assertIsNumeric($expected);
$this->assertIsNumeric($result);
$this->assertTrue(($expected < 0 && $result < 0) || ($expected > 0 && $result > 0) || ($expected === 0 && $result === 0), 'Numbers are either both negative, both positive or both zero.');
}

Expand Down

0 comments on commit e1f3a8b

Please sign in to comment.