MDL-81308 core: Update tests to not use withConsecutive
This commit is contained in:
@@ -247,10 +247,17 @@ class completionlib_test extends advanced_testcase {
|
||||
$c->expects($this->exactly(1)) // Pretend the user has the required capability for overriding completion statuses.
|
||||
->method('user_can_override_completion')
|
||||
->will($this->returnValue(true));
|
||||
$c->expects($this->exactly(2))
|
||||
$getinvocations = $this->exactly(2);
|
||||
$c->expects($getinvocations)
|
||||
->method('get_data')
|
||||
->with($cm, false, 100)
|
||||
->willReturnOnConsecutiveCalls($current1, $current2);
|
||||
->willReturnCallback(function () use ($getinvocations, $current1, $current2) {
|
||||
return match ($getinvocations->getInvocationCount()) {
|
||||
1 => $current1,
|
||||
2 => $current2,
|
||||
default => $this->fail('Unexpected invocation count'),
|
||||
};
|
||||
});
|
||||
$changed1 = clone($current1);
|
||||
$changed1->timemodified = time();
|
||||
$changed1->completionstate = COMPLETION_COMPLETE;
|
||||
@@ -263,12 +270,28 @@ class completionlib_test extends advanced_testcase {
|
||||
$changed2->completionstate = COMPLETION_INCOMPLETE;
|
||||
$comparewith2 = new phpunit_constraint_object_is_equal_with_exceptions($changed2);
|
||||
$comparewith2->add_exception('timemodified', 'assertGreaterThanOrEqual');
|
||||
$c->expects($this->exactly(2))
|
||||
$setinvocations = $this->exactly(2);
|
||||
$c->expects($setinvocations)
|
||||
->method('internal_set_data')
|
||||
->withConsecutive(
|
||||
array($cm, $comparewith1),
|
||||
array($cm, $comparewith2)
|
||||
);
|
||||
->willReturnCallback(function ($comparecm, $comparewith) use (
|
||||
$setinvocations,
|
||||
$cm,
|
||||
$comparewith1,
|
||||
$comparewith2
|
||||
): void {
|
||||
switch ($setinvocations->getInvocationCount()) {
|
||||
case 1:
|
||||
$this->assertEquals($cm, $comparecm);
|
||||
$comparewith1->evaluate($comparewith);
|
||||
break;
|
||||
case 2:
|
||||
$this->assertEquals($cm, $comparecm);
|
||||
$comparewith2->evaluate($comparewith);
|
||||
break;
|
||||
default:
|
||||
$this->fail('Unexpected invocation count');
|
||||
}
|
||||
});
|
||||
$c->update_state($cm, COMPLETION_COMPLETE, 100, true);
|
||||
// And confirm that the status can be changed back to incomplete without an override.
|
||||
$c->update_state($cm, COMPLETION_INCOMPLETE, 100);
|
||||
@@ -685,13 +708,26 @@ class completionlib_test extends advanced_testcase {
|
||||
(object)array('id' => 100, 'firstname' => 'Woot', 'lastname' => 'Plugh'),
|
||||
(object)array('id' => 201, 'firstname' => 'Vroom', 'lastname' => 'Xyzzy'))));
|
||||
|
||||
$c->expects($this->exactly(3))
|
||||
$updateinvocations = $this->exactly(3);
|
||||
$c->expects($updateinvocations)
|
||||
->method('update_state')
|
||||
->withConsecutive(
|
||||
array($cm, COMPLETION_UNKNOWN, 100),
|
||||
array($cm, COMPLETION_UNKNOWN, 101),
|
||||
array($cm, COMPLETION_UNKNOWN, 201)
|
||||
);
|
||||
->willReturnCallback(function ($comparecm, $state, $userid) use ($updateinvocations, $cm): void {
|
||||
$this->assertEquals($cm, $comparecm);
|
||||
$this->assertEquals(COMPLETION_UNKNOWN, $state);
|
||||
switch ($updateinvocations->getInvocationCount()) {
|
||||
case 1:
|
||||
$this->assertEquals(100, $userid);
|
||||
break;
|
||||
case 2:
|
||||
$this->assertEquals(101, $userid);
|
||||
break;
|
||||
case 3:
|
||||
$this->assertEquals(201, $userid);
|
||||
break;
|
||||
default:
|
||||
$this->fail('Unexpected invocation count');
|
||||
}
|
||||
});
|
||||
|
||||
$c->reset_all_state($cm);
|
||||
}
|
||||
@@ -1178,20 +1214,31 @@ class completionlib_test extends advanced_testcase {
|
||||
->method('get_tracked_users')
|
||||
->with(true, 3, 0, '', '', '', null)
|
||||
->will($this->returnValue($tracked));
|
||||
$DB->expects($this->exactly(2))
|
||||
$inorequalsinvocations = $this->exactly(2);
|
||||
$DB->expects($inorequalsinvocations)
|
||||
->method('get_in_or_equal')
|
||||
->withConsecutive(
|
||||
array(array_slice($ids, 0, 1000)),
|
||||
array(array_slice($ids, 1000))
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
array(' IN whatever', array()),
|
||||
array(' IN whatever2', array()));
|
||||
$DB->expects($this->exactly(2))
|
||||
->willReturnCallback(function ($paramids) use ($inorequalsinvocations, $ids) {
|
||||
switch ($inorequalsinvocations->getInvocationCount()) {
|
||||
case 1:
|
||||
$this->assertEquals(array_slice($ids, 0, 1000), $paramids);
|
||||
return [' IN whatever', []];
|
||||
case 2:
|
||||
$this->assertEquals(array_slice($ids, 1000), $paramids);
|
||||
return [' IN whatever2', []];
|
||||
default:
|
||||
$this->fail('Unexpected invocation count');
|
||||
}
|
||||
});
|
||||
$getinvocations = $this->exactly(2);
|
||||
$DB->expects($getinvocations)
|
||||
->method('get_recordset_sql')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
new core_completionlib_fake_recordset(array_slice($progress, 0, 1000)),
|
||||
new core_completionlib_fake_recordset(array_slice($progress, 1000)));
|
||||
->willReturnCallback(function () use ($getinvocations, $progress) {
|
||||
return match ($getinvocations->getInvocationCount()) {
|
||||
1 => new core_completionlib_fake_recordset(array_slice($progress, 0, 1000)),
|
||||
2 => new core_completionlib_fake_recordset(array_slice($progress, 1000)),
|
||||
default => $this->fail('Unexpected invocation count'),
|
||||
};
|
||||
});
|
||||
|
||||
$result = $c->get_progress_all(true, 3);
|
||||
$resultok = true;
|
||||
|
||||
Reference in New Issue
Block a user