mirror of
https://github.com/moodle/moodle.git
synced 2025-08-10 03:16:42 +02:00
MDL-71036 phpunit: assertContains() now performs strict comparison
The methods assertContains() and assertNotContains() now perform strict (type and value) comparison, pretty much like assertSame() does. A couple of new assertContainsEquals() and assertNotContainsEquals() methods have been created to provide old (non-strict) behavior, pretty much like assertEquals() do. Apart from replacing the calls needing a relaxed comparison to those new methods, there are also a couple of alternative, about how to fix this, depending of every case: - If the test is making any array_values() conversion, then it's better to remove that conversion and use assertArrayHasKey(), that is not strict. - Sometimes if may be also possible to, simply, cast the expectation to the exact type coming in the array. I've not applied this technique to any of the cases in core. Link: https://github.com/sebastianbergmann/phpunit/issues/3426
This commit is contained in:
parent
8940f67486
commit
3dd26fe334
27 changed files with 139 additions and 143 deletions
|
@ -2437,7 +2437,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
|
|||
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
|
||||
|
||||
// Assert that the record is either the 7th, 8th, 9th, ... 13th day of the month.
|
||||
$this->assertContains(date('j', $record->timestart), $bymonthdays);
|
||||
$this->assertContainsEquals(date('j', $record->timestart), $bymonthdays);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2494,7 +2494,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
|
|||
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
|
||||
|
||||
// Assert that the record is either the 2nd, 3rd, 4th ... 8th day of the month.
|
||||
$this->assertContains(date('j', $record->timestart), $bymonthdays);
|
||||
$this->assertContainsEquals(date('j', $record->timestart), $bymonthdays);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2525,7 +2525,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
|
|||
(new DateTime('1997-11-06 09:00:00 EST'))->getTimestamp()
|
||||
];
|
||||
foreach ($records as $record) {
|
||||
$this->assertContains($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
|
||||
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2603,7 +2603,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
|
|||
(new DateTime('1997-09-02 15:00:00 EDT'))->getTimestamp(),
|
||||
];
|
||||
foreach ($records as $record) {
|
||||
$this->assertContains($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
|
||||
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2634,7 +2634,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
|
|||
(new DateTime('1997-09-02 10:15:00 EDT'))->getTimestamp(),
|
||||
];
|
||||
foreach ($records as $record) {
|
||||
$this->assertContains($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
|
||||
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2663,7 +2663,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
|
|||
(new DateTime('1997-09-02 13:30:00 EDT'))->getTimestamp(),
|
||||
];
|
||||
foreach ($records as $record) {
|
||||
$this->assertContains($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
|
||||
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2707,7 +2707,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
|
|||
$this->assertCount($count, $records);
|
||||
|
||||
foreach ($records as $record) {
|
||||
$this->assertContains($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
|
||||
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2751,7 +2751,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
|
|||
$this->assertCount($count, $records);
|
||||
|
||||
foreach ($records as $record) {
|
||||
$this->assertContains($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
|
||||
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2782,7 +2782,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
|
|||
(new DateTime('1997-08-24 09:00:00 EDT'))->getTimestamp(),
|
||||
];
|
||||
foreach ($records as $record) {
|
||||
$this->assertContains($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
|
||||
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2815,7 +2815,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
|
|||
];
|
||||
|
||||
foreach ($records as $record) {
|
||||
$this->assertContains($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
|
||||
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue