Source
CExceptionHelper::setMessage($t, $t->getMessage()."\n\nAPI calls:\n".CAPIHelper::getDebugInfoAsString());
<?php
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
require_once 'vendor/autoload.php';
require_once dirname(__FILE__).'/CTest.php';
/**
* Base class for Zabbix API tests.
*/
class CAPITest extends CTest {
/**
* Check API response.
*
* @param array $response response to be checked
* @param mixed $error expected error:
*
* Possible $error types:
* null/false - there should not be an error
* array - exact match
* string - error message should match
* int - error code should match
*/
public function checkResult($response, $error = null) {
// Check response data.
if ($error === null || $error === false) {
$this->assertArrayHasKey('result', $response, json_encode($response, JSON_PRETTY_PRINT));
$this->assertArrayNotHasKey('error', $response);
}
else {
$this->assertArrayNotHasKey('result', $response);
$this->assertArrayHasKey('error', $response);
if (is_array($error)) {
$this->assertSame($error, $response['error']);
}
elseif (is_string($error)) {
$this->assertSame($error, $response['error']['data']);
}
elseif (is_numeric($error)) {
$this->assertSame($error, $response['error']['code']);
}
elseif (is_callable($error)) {
$this->assertSame($error(), $response['error']['data']);
}
}
}
/**
* Make API call.