Source
CExceptionHelper::setMessage($t, $t->getMessage()."\n\nAPI calls:\n".CAPIHelper::getDebugInfoAsString());
<?php
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
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']);
}
}
}