/** * Include messages from a Status object in the API call's output. * * An ApiErrorHandler is used to report the status, if necessary. * If $status->isOK() is false, this method will terminate with a UsageException. * * @param Status $status The status to report * @param string $errorCode The API error code to use in case $status->isOK() returns false * @param array $extradata Additional data to include the the error report, * if $status->isOK() returns false * @param int $httpRespCode the HTTP response code to use in case * $status->isOK() returns false.+ * * @throws UsageException If $status->isOK() returns false. */ private function handleStatus(Status $status, $errorCode, array $extradata = array(), $httpRespCode = 0) { if ($status->isGood()) { return; } elseif ($status->isOK()) { $this->errorReporter->reportStatusWarnings($status); } else { $this->errorReporter->reportStatusWarnings($status); $this->errorReporter->dieStatus($status, $errorCode, $httpRespCode, $extradata); } }
/** * @dataProvider warningProvider */ public function testReportStatusWarnings(Status $status, array $expectedDataFields) { $api = new ApiMain(); $localizer = $this->getExceptionLocalizer(); $reporter = new ApiErrorReporter($api, $localizer, Language::factory('de')); $reporter->reportStatusWarnings($status); $result = $api->getResult()->getResultData(); foreach ($expectedDataFields as $path => $value) { $path = explode('/', $path); $this->assertValueAtPath($value, $path, $result); } }