From cf45a34dbac9312199f01e3a7b607b9fb71cc347 Mon Sep 17 00:00:00 2001 From: Florian Liebe Date: Thu, 16 Jul 2026 08:46:27 +0200 Subject: [PATCH] Give LinkTest and TagTest the same generous HTTP timeout as AbstractBaseTest Both classes create and delete real tickets (with articles, links, etc.) for every single test, but still relied on the client's 5 second default HTTP timeout instead of the 30 second one AbstractBaseTest already switched to. Under load, ticket deletion cascades through enough related records that it can occasionally exceed 5 seconds, causing a ConnectException in tearDown() that gets misattributed to whatever test happened to be running. --- test/ZammadAPIClient/Resource/LinkTest.php | 27 ++++++++++------------ test/ZammadAPIClient/Resource/TagTest.php | 27 ++++++++++------------ 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/test/ZammadAPIClient/Resource/LinkTest.php b/test/ZammadAPIClient/Resource/LinkTest.php index 3317969..2d1a462 100644 --- a/test/ZammadAPIClient/Resource/LinkTest.php +++ b/test/ZammadAPIClient/Resource/LinkTest.php @@ -4,31 +4,28 @@ use PHPUnit\Framework\TestCase; use ZammadAPIClient\Client; +use ZammadAPIClient\EnvConfigTrait; use ZammadAPIClient\ResourceType; class LinkTest extends TestCase { + use EnvConfigTrait; + private static $client; private static $source_ticket; private static $target_ticket; public static function setUpBeforeClass(): void { - $client_config = []; - - $env_keys = [ - 'url' => 'ZAMMAD_PHP_API_CLIENT_UNIT_TESTS_URL', - 'username' => 'ZAMMAD_PHP_API_CLIENT_UNIT_TESTS_USERNAME', - 'password' => 'ZAMMAD_PHP_API_CLIENT_UNIT_TESTS_PASSWORD', - ]; - foreach ( $env_keys as $config_key => $env_key ) { - $value = getenv( $env_key ); - if ( empty($value) ) { - throw new \RuntimeException("Missing environment variable $env_key"); - } - - $client_config[$config_key] = $value; - } + // This suite creates and deletes real tickets (with their articles, links, + // etc.) for every single test, which can occasionally take longer than the + // client's 5 second default timeout under load. Match AbstractBaseTest's + // more generous timeout to avoid spurious ConnectExceptions in tearDown(). + $client_timeout = getenv('ZAMMAD_PHP_API_CLIENT_UNIT_TESTS_TIMEOUT'); + + $client_config = self::getZammadConfig([ + 'timeout' => !empty($client_timeout) ? $client_timeout : 30, + ]); self::$client = new Client($client_config); } diff --git a/test/ZammadAPIClient/Resource/TagTest.php b/test/ZammadAPIClient/Resource/TagTest.php index 2fa9dc6..72ea509 100644 --- a/test/ZammadAPIClient/Resource/TagTest.php +++ b/test/ZammadAPIClient/Resource/TagTest.php @@ -4,10 +4,13 @@ use PHPUnit\Framework\TestCase; use ZammadAPIClient\Client; +use ZammadAPIClient\EnvConfigTrait; use ZammadAPIClient\ResourceType; class TagTest extends TestCase { + use EnvConfigTrait; + private static $client; private static $ticket; @@ -15,21 +18,15 @@ class TagTest extends TestCase public static function setUpBeforeClass(): void { - $client_config = []; - - $env_keys = [ - 'url' => 'ZAMMAD_PHP_API_CLIENT_UNIT_TESTS_URL', - 'username' => 'ZAMMAD_PHP_API_CLIENT_UNIT_TESTS_USERNAME', - 'password' => 'ZAMMAD_PHP_API_CLIENT_UNIT_TESTS_PASSWORD', - ]; - foreach ( $env_keys as $config_key => $env_key ) { - $value = getenv($env_key); - if ( empty($value) ) { - throw new \RuntimeException("Missing environment variable $env_key"); - } - - $client_config[$config_key] = $value; - } + // This suite creates and deletes a real ticket for every single test, which + // can occasionally take longer than the client's 5 second default timeout + // under load. Match AbstractBaseTest's more generous timeout to avoid + // spurious ConnectExceptions in tearDown(). + $client_timeout = getenv('ZAMMAD_PHP_API_CLIENT_UNIT_TESTS_TIMEOUT'); + + $client_config = self::getZammadConfig([ + 'timeout' => !empty($client_timeout) ? $client_timeout : 30, + ]); self::$client = new Client($client_config); }