From 00a7c130dfab63e138e16cacdf9f12060c627e96 Mon Sep 17 00:00:00 2001 From: liugang Date: Mon, 10 Nov 2025 14:25:02 +0800 Subject: [PATCH] + [misc] Add webhookParseBodyTest method to gitlabZenTest class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- module/gitlab/test/lib/zen.class.php | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/module/gitlab/test/lib/zen.class.php b/module/gitlab/test/lib/zen.class.php index cc4e28fa3b..151787b592 100644 --- a/module/gitlab/test/lib/zen.class.php +++ b/module/gitlab/test/lib/zen.class.php @@ -335,4 +335,42 @@ class gitlabZenTest extends baseTest /* 返回日志内容用于验证 */ return $logContent; } + + /** + * Test webhookParseBody method. + * + * @param object $body + * @param int $gitlabID + * @access public + * @return object|bool|string + */ + public function webhookParseBodyTest(object $body, int $gitlabID) + { + global $app; + if(!class_exists('gitlab')) require_once $app->getModulePath('', 'gitlab') . 'control.php'; + if(!class_exists('gitlabZen')) require_once $app->getModulePath('', 'gitlab') . 'zen.php'; + + $reflection = new ReflectionClass('gitlabZen'); + $zenInstance = $reflection->newInstanceWithoutConstructor(); + $zenInstance->app = $app; + $zenInstance->config = $app->config; + $zenInstance->lang = $app->lang; + $zenInstance->dao = $app->loadClass('dao'); + + $method = $reflection->getMethod('webhookParseBody'); + $method->setAccessible(true); + + try { + $result = $method->invoke($zenInstance, $body, $gitlabID); + } catch(TypeError $e) { + if(strpos($e->getMessage(), 'Return value must be of type object, bool returned') !== false) return 'type_error_false'; + if(strpos($e->getMessage(), 'Return value must be of type object, null returned') !== false) return 'type_error_null'; + throw $e; + } catch(EndResponseException $e) { + return 'method_not_found'; + } + + if(dao::isError()) return dao::getError(); + return $result; + } }