From cb65c10b172288d652eed4ee02d535c6919e6452 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 22 Feb 2023 08:40:52 +0100 Subject: [PATCH] Continued: - commented out some debug lines - added some more (also commented out) --- .../tools/console/class_ConsoleTools.php | 41 +++++++++++++------ .../class_FrameworkBootstrapTest.php | 12 +++--- .../config/FrameworkConfigurationTest.php | 8 ++-- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/framework/main/classes/tools/console/class_ConsoleTools.php b/framework/main/classes/tools/console/class_ConsoleTools.php index e9d2fe5a..f4c48d2f 100644 --- a/framework/main/classes/tools/console/class_ConsoleTools.php +++ b/framework/main/classes/tools/console/class_ConsoleTools.php @@ -159,6 +159,7 @@ class ConsoleTools extends BaseFrameworkSystem { */ protected function extractHostnameFromRawData (string $rawData) { // Validate parameter + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: rawData=%s - CALLED!', $rawData)); if (empty($rawData)) { // Throw IAE throw new InvalidArgumentException('Parameter "rawData" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -171,13 +172,16 @@ class ConsoleTools extends BaseFrameworkSystem { $data = explode(PHP_EOL, $rawData); // "Walk" through it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: data()=%d', count($data))); foreach ($data as $line) { // Trim it $line = trim($line); // Begins with a hash (#) = comment? + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: line=%s', $line)); if (substr($line, 0, 1) == '#') { // Then skip it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: line=%s - SKIPPED!', $line)); continue; } @@ -187,7 +191,11 @@ class ConsoleTools extends BaseFrameworkSystem { $hostData = explode('=', $line); // Make sure only a key=value pair goes through - assert(count($hostData) == 2); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostData()=%d', count($hostData))); + if (count($hostData) < 2) { + // Ops, wrong count + throw new UnexpectedValueException(sprintf('hostData()=%d is unexpected, line=%s', count($hostData), $line), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE); + } // Try to get it and abort $hostname = str_replace( @@ -195,15 +203,18 @@ class ConsoleTools extends BaseFrameworkSystem { ['', ''], $hostData[1] ); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s from hostData - BREAK!', $hostname)); break; } else { // Use it directly $hostname = $line; + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s from line - BREAK!', $line)); break; } } // Return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: hostname=%s - EXIT!', $hostname)); return $hostname; } @@ -218,6 +229,7 @@ class ConsoleTools extends BaseFrameworkSystem { */ public static function resolveIpAddress (string $hostname) { // Validate parameter + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: hostname=%s - CALLED!', $hostname)); if (empty($hostname)) { // Throw IAE throw new InvalidArgumentException('Parameter "hostname" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -246,9 +258,11 @@ class ConsoleTools extends BaseFrameworkSystem { // Resolve it // @TODO Here should the cacher be implemented + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s', $hostname)); $ipResolved = gethostbyname($hostname); // Was it fine? + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: ipResolved[%s]=%s', gettype($ipResolved), $ipResolved)); if (($ipResolved !== false) && ($ipResolved != $hostname)) { // Okay, this works! $ipAddress = $ipResolved; @@ -270,6 +284,7 @@ class ConsoleTools extends BaseFrameworkSystem { } // Return resolved IP + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: ipAddress=%s - EXIT!', $ipAddress)); return $ipAddress; } @@ -280,7 +295,7 @@ class ConsoleTools extends BaseFrameworkSystem { */ public static function acquireHostname () { // Is cache there? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('CONSOLE-TOOLS: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('CONSOLE-TOOLS: CALLED!'); if (!isset(self::$cache[__METHOD__])) { // Get a new instance $toolsInstance = new ConsoleTools(); @@ -289,7 +304,7 @@ class ConsoleTools extends BaseFrameworkSystem { $infoInstance = new SplFileInfo(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('hostname_file')); // Init host name - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: infoInstance=%s', $infoInstance->__toString())); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: infoInstance=%s', $infoInstance->__toString())); $hostname = 'host.invalid'; // Try to check /etc/hostname first @@ -298,18 +313,18 @@ class ConsoleTools extends BaseFrameworkSystem { $fileInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_class', [$infoInstance]); // Read the file - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: fileInstance=%s', $fileInstance->__toString())); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: fileInstance=%s', $fileInstance->__toString())); $rawData = trim($fileInstance->readFromFile()); // Close the file - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: rawData=%s', $rawData)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: rawData=%s', $rawData)); $fileInstance->closeFile(); // Extract hostname from it $hostname = $toolsInstance->extractHostnameFromRawData($rawData); // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s from /etc/hostname', $hostname)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s from /etc/hostname', $hostname)); } catch (FileNotFoundException $e) { // Fall-back to 'SESSION_SVR' which found on my Sun Station if (isset($_SERVER['SESSION_SVR'])) { @@ -326,7 +341,7 @@ class ConsoleTools extends BaseFrameworkSystem { } // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s from _SERVER array', $hostname)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s from _SERVER array', $hostname)); } catch (FrameworkException $e) { // Output debug message self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:] Problem while resolving own IP address: [%s|%s]:%s', @@ -338,7 +353,7 @@ class ConsoleTools extends BaseFrameworkSystem { } // Set cache - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: Setting hostname=%s ...', $hostname)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: Setting hostname=%s ...', $hostname)); self::$cache[__METHOD__] = $hostname; } else { // Get from cache @@ -346,7 +361,7 @@ class ConsoleTools extends BaseFrameworkSystem { } // Return it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: hostname=%s - EXIT!', $hostname)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: hostname=%s - EXIT!', $hostname)); return $hostname; } @@ -358,17 +373,17 @@ class ConsoleTools extends BaseFrameworkSystem { */ public static function acquireSelfIpAddress () { // Is cache there? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('CONSOLE-TOOLS: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('CONSOLE-TOOLS: CALLED!'); if (!isset(self::$cache[__METHOD__])) { // Get host name $hostname = self::acquireHostname(); // Resolve the IP number - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s', $hostname)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s', $hostname)); $ipAddress = self::resolveIpAddress($hostname); // Set cache - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: Setting ipAddress=%s ...', $ipAddress)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: Setting ipAddress=%s ...', $ipAddress)); self::$cache[__METHOD__] = $ipAddress; } else { // Get it from cache @@ -376,7 +391,7 @@ class ConsoleTools extends BaseFrameworkSystem { } // Return it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: ipAddress=%s - EXIT!', $ipAddress)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: ipAddress=%s - EXIT!', $ipAddress)); return $ipAddress; } diff --git a/tests/framework/bootstrap/class_FrameworkBootstrapTest.php b/tests/framework/bootstrap/class_FrameworkBootstrapTest.php index 289c2433..9d3645bf 100644 --- a/tests/framework/bootstrap/class_FrameworkBootstrapTest.php +++ b/tests/framework/bootstrap/class_FrameworkBootstrapTest.php @@ -62,10 +62,8 @@ class FrameworkBootstrapTest extends TestCase { * Setup test case */ public static function setUpBeforeClass() { - // Trace message - /* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); - // Call parent method + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); parent::setUpBeforeClass(); // Lookup own hostname @@ -75,7 +73,7 @@ class FrameworkBootstrapTest extends TestCase { self::$ipAddress = ConsoleTools::acquireSelfIpAddress(); // Trace message - /* NOISY-DEBUG: */ printf('[%s:%d]: self::ipAddress[%s]=%s,self::hostname=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, gettype(self::$ipAddress), self::$ipAddress, self::$hostname); + //* NOISY-DEBUG: */ printf('[%s:%d]: self::ipAddress[%s]=%s,self::hostname=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, gettype(self::$ipAddress), self::$ipAddress, self::$hostname); } /** @@ -149,11 +147,11 @@ class FrameworkBootstrapTest extends TestCase { $infoInstance = new SplFileInfo('/does/not/exist/'); // Invoke method - /* NOISY-DEBUG: */ printf('[%s:%d]: infoInstance=%s' . PHP_EOL, __METHOD__, __LINE__, get_class($infoInstance)); + //* NOISY-DEBUG: */ printf('[%s:%d]: infoInstance=%s' . PHP_EOL, __METHOD__, __LINE__, get_class($infoInstance)); $isReachable = FrameworkBootstrap::isReachableFilePath($infoInstance); // Test if it is not reachable - /* NOISY-DEBUG: */ printf('[%s:%d]: isReachable=%d' . PHP_EOL, __METHOD__, __LINE__, intval($isReachable)); + //* NOISY-DEBUG: */ printf('[%s:%d]: isReachable=%d' . PHP_EOL, __METHOD__, __LINE__, intval($isReachable)); $this->assertTrue($isReachable, 'Returned true on a non-existing path'); // Trace message @@ -175,7 +173,7 @@ class FrameworkBootstrapTest extends TestCase { $rootScriptPath = realpath(dirname(dirname(FrameworkBootstrap::detectScriptPath()))); // Set it - /* NOISY-DEBUG: */ printf('[%s:%d]: open_basedir=%s,rootScriptPath[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, ini_get('open_basedir'), gettype($rootScriptPath), $rootScriptPath); + //* NOISY-DEBUG: */ printf('[%s:%d]: open_basedir=%s,rootScriptPath[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, ini_get('open_basedir'), gettype($rootScriptPath), $rootScriptPath); $result = ini_set('open_basedir', $rootScriptPath . ':/etc/'); // Was it set? diff --git a/tests/framework/config/FrameworkConfigurationTest.php b/tests/framework/config/FrameworkConfigurationTest.php index 3a2db60b..2bc7b0fb 100644 --- a/tests/framework/config/FrameworkConfigurationTest.php +++ b/tests/framework/config/FrameworkConfigurationTest.php @@ -400,22 +400,22 @@ class FrameworkConfigurationTest extends TestCase { */ public function testConfigSortConfigurationArray () { // First get configuration array - /* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); $config = self::$configInstance->getConfigurationArray(); // Run sort method - /* NOISY-DEBUG: */ printf('[%s:%d]: config()=%d' . PHP_EOL, __METHOD__, __LINE__, count($config)); + //* NOISY-DEBUG: */ printf('[%s:%d]: config()=%d' . PHP_EOL, __METHOD__, __LINE__, count($config)); self::$configInstance->sortConfigurationArray(); // This should be an empty array $diff = array_diff($config, self::$configInstance->getConfigurationArray()); // Check condition - /* NOISY-DEBUG: */ printf('[%s:%d]: diff()=%d' . PHP_EOL, __METHOD__, __LINE__, count($diff)); + //* NOISY-DEBUG: */ printf('[%s:%d]: diff()=%d' . PHP_EOL, __METHOD__, __LINE__, count($diff)); $this->assertTrue(count($diff) === 0); // Trace message - /* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); + //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); } } -- 2.39.5