MDL-73826 phpunit: Allow curl mock responses to handle empty strings

Before this commit, is_empty() was being applied before returning
the mock response. But we want to be able to mock the empty response
for some tests, hence moving the condition to null/isset, that is
the value that array_pop() returns where there aren't more elements
in the array.

With that change performed, we can test lti_load_cartridge() with
empty responses, hence adding a new test for that.
This commit is contained in:
Eloy Lafuente (stronk7) 2022-02-10 11:33:33 +01:00
parent 64969e82d7
commit d66a5316ae
2 changed files with 16 additions and 1 deletions

View file

@ -3712,7 +3712,8 @@ class curl {
$this->reset_request_state_vars();
if ((defined('PHPUNIT_TEST') && PHPUNIT_TEST)) {
if ($mockresponse = array_pop(self::$mockresponses)) {
$mockresponse = array_pop(self::$mockresponses);
if ($mockresponse !== null) {
$this->info = [ 'http_code' => 200 ];
return $mockresponse;
}