diff --git a/src/annotation/src/Resource/AnnotationResource.php b/src/annotation/src/Resource/AnnotationResource.php index 83769476e..75115712a 100644 --- a/src/annotation/src/Resource/AnnotationResource.php +++ b/src/annotation/src/Resource/AnnotationResource.php @@ -122,7 +122,7 @@ public function __construct(array $config = []) { // Init $excludedPsr4Prefixes $this->excludedPsr4Prefixes = self::DEFAULT_EXCLUDED_PSR4_PREFIXES; - + // Can set property by array ObjectHelper::init($this, $config); diff --git a/src/console/src/Input/AbstractInput.php b/src/console/src/Input/AbstractInput.php index 5bbc4da19..6f5d9065d 100644 --- a/src/console/src/Input/AbstractInput.php +++ b/src/console/src/Input/AbstractInput.php @@ -5,9 +5,11 @@ use Swoft\Console\Contract\InputInterface; use Swoft\Console\Exception\CommandFlagException; use function array_merge; +use function array_values; use function getcwd; use function is_bool; use function is_int; +use function strpos; use function trim; /** @@ -93,26 +95,27 @@ abstract public function toString(): string; /** * find command name. it is first argument. + * + * @param array $flags + * + * @return array */ - protected function findCommand(): void + protected function findCommand(array $flags): array { - if (!isset($this->args[0])) { - return; + if (!isset($flags[0])) { + return $flags; } - $newArgs = []; - - foreach ($this->args as $key => $value) { - if ($key === 0) { - $this->command = trim($value); - } elseif (is_int($key)) { - $newArgs[] = $value; - } else { - $newArgs[$key] = $value; - } + // Not input command name + if (strpos($flags[0], '-') === 0) { + return $flags; } - $this->args = $newArgs; + $this->command = trim($flags[0]); + + // remove first element, reset index key. + unset($flags[0]); + return array_values($flags); } /*********************************************************************************** diff --git a/src/console/src/Input/Input.php b/src/console/src/Input/Input.php index 5a61c982f..7a396d080 100644 --- a/src/console/src/Input/Input.php +++ b/src/console/src/Input/Input.php @@ -57,15 +57,13 @@ public function __construct(array $args = null, bool $parsing = true) $this->scriptFile = array_shift($args); $this->fullScript = implode(' ', $args); - $this->flags = $args; + // find command name, other is flags + $this->flags = $this->findCommand($args); $this->pwd = $this->getPwd(); if ($parsing) { // list($this->args, $this->sOpts, $this->lOpts) = InputParser::fromArgv($args); - [$this->args, $this->sOpts, $this->lOpts] = Flags::parseArgv($args); - - // find command name - $this->findCommand(); + [$this->args, $this->sOpts, $this->lOpts] = Flags::parseArgv($this->flags); } } @@ -133,6 +131,7 @@ public function parseFlags(array $info, bool $binding = false): void } } + // re-parsing if ($this->flags) { [$this->args, $this->sOpts, $this->lOpts] = Flags::parseArgv($this->flags, $config); diff --git a/src/console/test/unit/Input/InputTest.php b/src/console/test/unit/Input/InputTest.php index 9dec7ba04..dcd096802 100644 --- a/src/console/test/unit/Input/InputTest.php +++ b/src/console/test/unit/Input/InputTest.php @@ -14,6 +14,9 @@ public function testInput(): void $in = new Input($args); $this->assertSame('input:test', $in->getCommand()); + $this->assertSame([], $in->getArgs()); + $this->assertSame(['-d', '12'], $in->getFlags()); + $this->assertSame(['d' => '12'], $in->getOpts()); } /** diff --git a/src/framework/run.php b/src/framework/run.php index c56feecb0..f4841bb88 100644 --- a/src/framework/run.php +++ b/src/framework/run.php @@ -36,28 +36,21 @@ } unset($file); if (!defined('PHPUNIT_COMPOSER_INSTALL')) { - fwrite(STDERR, - 'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL . ' composer install' . PHP_EOL . PHP_EOL . 'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL); + $tips = << 1, + * ] + * + * @var array + */ + private $disabledProcessors = []; + + /** + * Can disable AutoLoader class before handle. + * eg. + * [ + * Swoft\Console\AutoLoader::class => 1, + * ] + * + * @var array + */ + private $disabledAutoLoaders = []; + + /** + * Scans containing these namespace prefixes will be excluded. + * + * @var array + * eg. + * [ + * 'PHPUnit\\', + * ] + */ + private $disabledPsr4Prefixes = []; + /** * Get env name * @@ -186,4 +224,68 @@ public function afterConsole(): bool { return true; } + + /** + * @return array + */ + public function getDisabledProcessors(): array + { + return $this->disabledProcessors; + } + + /** + * @return array + */ + public function getDisabledAutoLoaders(): array + { + return $this->disabledAutoLoaders; + } + + /** + * @return array + */ + public function getDisabledPsr4Prefixes(): array + { + return $this->disabledPsr4Prefixes; + } + + /** + * @param array $disabledAutoLoaders + */ + public function setDisabledAutoLoaders(array $disabledAutoLoaders): void + { + $this->disabledAutoLoaders = $disabledAutoLoaders; + } + + /** + * @param array $disabledPsr4Prefixes + */ + public function setDisabledPsr4Prefixes(array $disabledPsr4Prefixes): void + { + $this->disabledPsr4Prefixes = $disabledPsr4Prefixes; + } + + /** + * @param array $disabledProcessors + */ + public function setDisabledProcessors(array $disabledProcessors): void + { + $this->disabledProcessors = $disabledProcessors; + } + + /** + * @return bool + */ + public function isStartConsole(): bool + { + return $this->startConsole; + } + + /** + * @param bool $startConsole + */ + public function setStartConsole($startConsole): void + { + $this->startConsole = (bool)$startConsole; + } } diff --git a/src/framework/src/Contract/SwoftInterface.php b/src/framework/src/Contract/SwoftInterface.php index 4646e830f..594d317cf 100644 --- a/src/framework/src/Contract/SwoftInterface.php +++ b/src/framework/src/Contract/SwoftInterface.php @@ -11,8 +11,6 @@ */ interface SwoftInterface { - public const VERSION = '1.0.0'; - /** * Get env name * diff --git a/src/framework/src/Processor/ConsoleProcessor.php b/src/framework/src/Processor/ConsoleProcessor.php index 87bbde2ef..a61adf418 100644 --- a/src/framework/src/Processor/ConsoleProcessor.php +++ b/src/framework/src/Processor/ConsoleProcessor.php @@ -36,7 +36,9 @@ public function handle(): bool CLog::info('Console command route registered (group %d, command %d)', $router->groupCount(), $router->count()); // Run console application - bean('cliApp')->run(); + if ($this->application->isStartConsole()) { + bean('cliApp')->run(); + } return $this->application->afterConsole(); } diff --git a/src/framework/src/Swoft.php b/src/framework/src/Swoft.php index f250c53a0..f634f597f 100644 --- a/src/framework/src/Swoft.php +++ b/src/framework/src/Swoft.php @@ -25,7 +25,7 @@ final class Swoft /** * Swoft version */ - public const VERSION = '2.0.7'; + public const VERSION = '2.0.8'; /** * Swoft terminal logo diff --git a/src/framework/src/SwoftApplication.php b/src/framework/src/SwoftApplication.php index 3a0f4c3b2..addadcbac 100644 --- a/src/framework/src/SwoftApplication.php +++ b/src/framework/src/SwoftApplication.php @@ -91,47 +91,14 @@ class SwoftApplication implements SwoftInterface, ApplicationInterface */ private $processor; - /** - * Can disable processor class before handle. - * eg. - * [ - * Swoft\Processor\ConsoleProcessor::class => 1, - * ] - * - * @var array - */ - private $disabledProcessors = []; - - /** - * Can disable AutoLoader class before handle. - * eg. - * [ - * Swoft\Console\AutoLoader::class => 1, - * ] - * - * @var array - */ - private $disabledAutoLoaders = []; - - /** - * Scans containing these namespace prefixes will be excluded. - * - * @var array - * eg. - * [ - * 'PHPUnit\\', - * ] - */ - private $disabledPsr4Prefixes = []; - /** * Get the application version * * @return string */ - public static function getVersion(): string + public function getVersion(): string { - return self::VERSION; + return Swoft::VERSION; } /** @@ -304,30 +271,6 @@ protected function processors(): array ]; } - /** - * @return array - */ - public function getDisabledProcessors(): array - { - return $this->disabledProcessors; - } - - /** - * @return array - */ - public function getDisabledAutoLoaders(): array - { - return $this->disabledAutoLoaders; - } - - /** - * @return array - */ - public function getDisabledPsr4Prefixes(): array - { - return $this->disabledPsr4Prefixes; - } - /** * @param string $beanFile */ diff --git a/src/framework/test/testing/TestApplication.php b/src/framework/test/testing/TestApplication.php index e7f0ee87b..e43a5a63b 100644 --- a/src/framework/test/testing/TestApplication.php +++ b/src/framework/test/testing/TestApplication.php @@ -2,11 +2,6 @@ namespace SwoftTest\Testing; -use Swoft\Processor\AnnotationProcessor; -use Swoft\Processor\BeanProcessor; -use Swoft\Processor\ConfigProcessor; -use Swoft\Processor\EnvProcessor; -use Swoft\Processor\EventProcessor; use Swoft\SwoftApplication; /** @@ -16,6 +11,14 @@ */ class TestApplication extends SwoftApplication { + public function __construct(array $config = []) + { + // tests: disable run console application + $this->setStartConsole(false); + + parent::__construct($config); + } + public function getCLoggerConfig(): array { $config = parent::getCLoggerConfig(); @@ -25,21 +28,4 @@ public function getCLoggerConfig(): array return $config; } - - /** - * Rewrite processors - * - * @return array - */ - protected function processors(): array - { - return [ - new EnvProcessor($this), - new ConfigProcessor($this), - new AnnotationProcessor($this), - new BeanProcessor($this), - new EventProcessor($this), - new ConsoleProcessor($this), - ]; - } } diff --git a/src/i18n/test/testing/TestApplication.php b/src/i18n/test/testing/TestApplication.php index 08f39c286..c81e10f7f 100644 --- a/src/i18n/test/testing/TestApplication.php +++ b/src/i18n/test/testing/TestApplication.php @@ -1,6 +1,5 @@ + bootstrap="test/bootstrap.php" + backupGlobals="false" + backupStaticAttributes="false" + colors="true" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" + processIsolation="false" + stopOnFailure="false"> ./test/unit @@ -19,4 +19,4 @@ ./src/* - \ No newline at end of file + diff --git a/src/log/src/AutoLoader.php b/src/log/src/AutoLoader.php index ebfe60527..08aa3013c 100644 --- a/src/log/src/AutoLoader.php +++ b/src/log/src/AutoLoader.php @@ -2,9 +2,9 @@ namespace Swoft\Log; -use function dirname; use Swoft\Helper\ComposerJSON; use Swoft\SwoftComponent; +use function dirname; /** * Class AutoLoader diff --git a/src/log/src/CLogger.php b/src/log/src/CLogger.php index d156692cf..d9ee05522 100644 --- a/src/log/src/CLogger.php +++ b/src/log/src/CLogger.php @@ -1,11 +1,10 @@ 'INFO', self::DEBUG => 'DEBUG', self::WARNING => 'WARNING', self::ERROR => 'ERROR', - ); + ]; /** * Logger constructor. @@ -63,7 +62,7 @@ public function __construct() * * @return bool */ - public function addRecord($level, $message, array $context = array()): bool + public function addRecord($level, $message, array $context = []): bool { if (!$this->enable) { return true; diff --git a/src/log/src/Handler/CEchoHandler.php b/src/log/src/Handler/CEchoHandler.php index 160e0f681..1e3af9415 100644 --- a/src/log/src/Handler/CEchoHandler.php +++ b/src/log/src/Handler/CEchoHandler.php @@ -1,17 +1,16 @@ levelValues)) { return true; @@ -128,4 +127,4 @@ public function isHandling(array $record) return in_array($record['level'], $this->levelValues, true); } -} \ No newline at end of file +} diff --git a/src/log/src/Handler/CFileHandler.php b/src/log/src/Handler/CFileHandler.php index b939509f9..928fea5a4 100644 --- a/src/log/src/Handler/CFileHandler.php +++ b/src/log/src/Handler/CFileHandler.php @@ -1,12 +1,16 @@ logFile[0] === '@') { + if (strpos($this->logFile, '@') === 0) { $this->init(); $this->bootingRecords[] = $record; @@ -57,17 +61,14 @@ protected function write(array $record): void } else { $records = array_column($records, 'formatted'); } - $messageText = implode("\n", $records) . "\n"; + $message = implode("\n", $records) . "\n"; $logFile = $this->formatFile($this->logFile); // Not all console log in coroutine - $res = file_put_contents($logFile, $messageText, FILE_APPEND); - - if ($res === false) { - throw new InvalidArgumentException( - sprintf('Unable to append to log file: %s', $logFile) - ); + $count = file_put_contents($logFile, $message, FILE_APPEND); + if ($count === false) { + throw new InvalidArgumentException(sprintf('Unable to append to log file: %s', $logFile)); } } @@ -76,7 +77,8 @@ protected function write(array $record): void */ public function setLevels(string $levels): void { - $levelNames = explode(',', $levels); + $levelNames = explode(',', $levels); + $this->levelValues = Logger::getLevelByNames($levelNames); $this->levels = $levels; diff --git a/src/log/src/Handler/FileHandler.php b/src/log/src/Handler/FileHandler.php index 93583eaf3..727632e59 100644 --- a/src/log/src/Handler/FileHandler.php +++ b/src/log/src/Handler/FileHandler.php @@ -1,17 +1,15 @@ format('Y-m-d H:i:s'); } + return JsonHelper::encode($record, JSON_UNESCAPED_UNICODE); } @@ -169,9 +163,8 @@ private function createDir(): void if ($logDir !== null && !is_dir($logDir)) { $status = mkdir($logDir, 0777, true); if ($status === false) { - throw new UnexpectedValueException( - sprintf('There is no existing directory at "%s" and its not buildable: ', $logDir) - ); + $errMsg = sprintf('There is no existing directory at "%s" and its not buildable', $logDir); + throw new UnexpectedValueException($errMsg); } } } diff --git a/src/log/src/Helper/CLog.php b/src/log/src/Helper/CLog.php index 40fcf424c..71c404649 100644 --- a/src/log/src/Helper/CLog.php +++ b/src/log/src/Helper/CLog.php @@ -1,12 +1,12 @@ debug($message, []); + self::$cLogger->debug($message, $context); } } @@ -83,11 +89,17 @@ public static function debug(string $message, ...$params): void */ public static function info(string $message, ...$params): void { + $context = []; + if ($params) { - $message = sprintf($message, ...$params); + if (is_array($params[0])) { + $context = $params[0]; + } else { + $message = sprintf($message, ...$params); + } } - self::$cLogger->info($message, []); + self::$cLogger->info($message, $context); } /** @@ -98,11 +110,17 @@ public static function info(string $message, ...$params): void */ public static function warning(string $message, ...$params): void { + $context = []; + if ($params) { - $message = sprintf($message, ...$params); + if (is_array($params[0])) { + $context = $params[0]; + } else { + $message = sprintf($message, ...$params); + } } - self::$cLogger->warning($message, []); + self::$cLogger->warning($message, $context); } /** @@ -113,10 +131,16 @@ public static function warning(string $message, ...$params): void */ public static function error(string $message, ...$params): void { + $context = []; + if ($params) { - $message = sprintf($message, ...$params); + if (is_array($params[0])) { + $context = $params[0]; + } else { + $message = sprintf($message, ...$params); + } } - self::$cLogger->error($message, []); + self::$cLogger->error($message, $context); } } diff --git a/src/log/src/Helper/Log.php b/src/log/src/Helper/Log.php index f2904e903..0774cb0a3 100644 --- a/src/log/src/Helper/Log.php +++ b/src/log/src/Helper/Log.php @@ -1,9 +1,7 @@ emergency($message, $context); } @@ -30,7 +29,8 @@ public static function emergency(string $message, ...$params): bool */ public static function debug(string $message, ...$params): bool { - [$message, $context] = self::formatLog($message, ...$params); + [$message, $context] = self::formatLog($message, $params); + if (APP_DEBUG) { return self::getLogger()->debug($message, $context); } @@ -46,7 +46,8 @@ public static function debug(string $message, ...$params): bool */ public static function alert(string $message, ...$params): bool { - [$message, $context] = self::formatLog($message, ...$params); + [$message, $context] = self::formatLog($message, $params); + return self::getLogger()->alert($message, $context); } @@ -58,7 +59,8 @@ public static function alert(string $message, ...$params): bool */ public static function info(string $message, ...$params): bool { - [$message, $context] = self::formatLog($message, ...$params); + [$message, $context] = self::formatLog($message, $params); + return self::getLogger()->info($message, $context); } @@ -70,7 +72,8 @@ public static function info(string $message, ...$params): bool */ public static function warning(string $message, ...$params): bool { - [$message, $context] = self::formatLog($message, ...$params); + [$message, $context] = self::formatLog($message, $params); + return self::getLogger()->warning($message, $context); } @@ -82,7 +85,8 @@ public static function warning(string $message, ...$params): bool */ public static function error(string $message, ...$params): bool { - [$message, $context] = self::formatLog($message, ...$params); + [$message, $context] = self::formatLog($message, $params); + return self::getLogger()->error($message, $context); } @@ -107,7 +111,7 @@ public static function pushLog(string $key, $val): void */ public static function profileStart(string $name, ...$params): void { - if (!empty($params)) { + if ($params) { $name = sprintf($name, ...$params); } @@ -134,7 +138,7 @@ public static function counting(string $name, int $hit, int $total = null): void */ public static function profileEnd(string $name, ...$params): void { - if (!empty($params)) { + if ($params) { $name = sprintf($name, ...$params); } @@ -155,18 +159,18 @@ public static function getLogger(): Logger * * @return array */ - public static function formatLog(string $message, ...$params): array + public static function formatLog(string $message, array $params): array { - $firstParam = $params[0] ?? null; - if (is_array($firstParam)) { - return [$message, $firstParam]; - } - - if (!empty($params)) { - $message = sprintf($message, ...$params); - return [$message, []]; + $context = []; + + if ($params) { + if (is_array($params[0])) { + $context = $params[0]; + } else { + $message = sprintf($message, ...$params); + } } - return [$message, []]; + return [$message, $context]; } } diff --git a/src/log/src/Logger.php b/src/log/src/Logger.php index bd367f10f..24d67c820 100644 --- a/src/log/src/Logger.php +++ b/src/log/src/Logger.php @@ -1,16 +1,17 @@ messages[] = $record; - if (count($this->messages) >= $this->flushInterval) { $this->flushLog(); } @@ -208,8 +205,6 @@ public function addRecord($level, $message, array $context = []): bool * @param array $extra * * @return array - * @throws SwoftException - * @throws SwoftException */ public function formatRecord( string $message, @@ -219,7 +214,6 @@ public function formatRecord( DateTime $ts, array $extra ): array { - $record = [ 'messages' => $message, 'context' => $context, @@ -238,7 +232,6 @@ public function formatRecord( $record[$item] = context()->get($item, ''); } - return $record; } @@ -323,6 +316,7 @@ public function getProfilesInfos(): string continue; } $cost = sprintf('%.2f', $profile['cost'] * 1000); + $profileAry[] = "$key=" . $cost . '(ms)/' . $profile['total']; } @@ -338,7 +332,11 @@ public function getProfilesInfos(): string */ public function counting(string $name, int $hit, int $total = null): void { - if (!is_string($name) || empty($name)) { + if (!$this->enable) { + return; + } + + if (!$name) { return; } @@ -441,7 +439,6 @@ public function flushLog(): void $this->messages = []; reset($this->handlers); - while ($handler = current($this->handlers)) { $handler->handleBatch($messages); next($this->handlers); @@ -460,6 +457,7 @@ public function appendNoticeLog($flush = false): void if (!$this->enable) { return; } + $cid = Co::tid(); $ts = $this->getLoggerTime(); @@ -494,9 +492,6 @@ public function appendNoticeLog($flush = false): void * Format notice message * * @return array - * @throws SwoftException - * @throws SwoftException - * @throws SwoftException */ private function formatNoticeMessage(): array { @@ -514,7 +509,7 @@ private function formatNoticeMessage(): array if ($this->json) { $messageAry = [ - 'cost(ms)' => (float)$timeUsed, + 'cost(ms)' => (float)$timeUsed, 'mem(MB)' => (float)$memUsed, 'uri' => $this->getUri(), 'pushLog' => implode(' ', $pushLogs), @@ -651,7 +646,6 @@ public function getItems(): array * Request uri * * @return string - * @throws SwoftException */ private function getUri(): string { @@ -662,7 +656,6 @@ private function getUri(): string * Request time * * @return float - * @throws SwoftException */ private function getRequestTime(): float { diff --git a/src/log/test/testing/bean.php b/src/log/test/testing/bean.php index 1a6c808f4..98bd2f54f 100644 --- a/src/log/test/testing/bean.php +++ b/src/log/test/testing/bean.php @@ -5,7 +5,7 @@ use Swoft\Log\Logger; return [ - 'lineFormatter' => [ + 'lineFormatter' => [ 'class' => LineFormatter::class, 'format' => '%datetime% [%level_name%] [%channel%] [%event%] [tid:%tid%] [cid:%cid%] [traceid:%traceid%] [spanid:%spanid%] [parentid:%parentid%] %messages%', 'dateFormat' => 'Y-m-d H:i:s', @@ -16,7 +16,7 @@ 'formatter' => bean('lineFormatter'), 'levels' => 'error,warning', ], - 'logger' => [ + 'logger' => [ 'class' => Logger::class, 'flushRequest' => false, 'enable' => false, @@ -25,4 +25,4 @@ 'notice' => bean('noticeHandler'), ], ] -]; \ No newline at end of file +]; diff --git a/src/log/test/unit/FileHandlerTest.php b/src/log/test/unit/FileHandlerTest.php index ee1302f57..1ddbc9539 100644 --- a/src/log/test/unit/FileHandlerTest.php +++ b/src/log/test/unit/FileHandlerTest.php @@ -1,9 +1,7 @@ getHandler()->formatFile("notice-%d{Y-m-d}.log"); + $result = $this->getHandler()->formatFile('notice-%d{Y-m-d}.log'); $this->assertEquals($result, 'notice-' . date('Y-m-d') . '.log'); - $result = $this->getHandler()->formatFile("notice.log"); + $result = $this->getHandler()->formatFile('notice.log'); $this->assertEquals($result, 'notice.log'); - $result = $this->getHandler()->formatFile("%d{Y-m-d}notice.log"); + $result = $this->getHandler()->formatFile('%d{Y-m-d}notice.log'); $this->assertEquals($result, date('Y-m-d') . 'notice.log'); - $result = $this->getHandler()->formatFile("notice.log%d{Y-m-d}"); + $result = $this->getHandler()->formatFile('notice.log%d{Y-m-d}'); $this->assertEquals($result, 'notice.log' . date('Y-m-d')); } @@ -34,4 +32,4 @@ private function getHandler(): FileHandler { return BeanFactory::getBean('testFileHandler'); } -} \ No newline at end of file +} diff --git a/src/log/test/unit/LogTest.php b/src/log/test/unit/LogTest.php index e8a67fa41..63c0404e2 100644 --- a/src/log/test/unit/LogTest.php +++ b/src/log/test/unit/LogTest.php @@ -1,9 +1,7 @@ assertEquals($result, ['messageabc', []]); + $result = Log::formatLog('message %s%s%s', ['a', 'b', 'c']); + $this->assertEquals($result, ['message abc', []]); - $result = Log::formatLog('message%s'); + $result = Log::formatLog('message%s', []); $this->assertEquals($result, ['message%s', []]); - $result = Log::formatLog('message%s', ['a' => 'b']); + $result = Log::formatLog('message%s', [['a' => 'b']]); $this->assertEquals($result, ['message%s', ['a' => 'b']]); } -} \ No newline at end of file +} diff --git a/src/stdlib/src/Helper/ArrayHelper.php b/src/stdlib/src/Helper/ArrayHelper.php index e2307cabf..881d5ab26 100644 --- a/src/stdlib/src/Helper/ArrayHelper.php +++ b/src/stdlib/src/Helper/ArrayHelper.php @@ -187,7 +187,7 @@ public static function getValue($array, $key, $default = null) return $array[$key]; } - if (($pos = strrpos($key, '.')) !== false) { + if (is_string($key) && ($pos = strrpos($key, '.')) !== false) { $array = static::getValue($array, substr($key, 0, $pos), $default); $key = (string)substr($key, $pos + 1); } diff --git a/src/stdlib/test/unit/Helper/ArrayHelperTest.php b/src/stdlib/test/unit/Helper/ArrayHelperTest.php index 4638776a8..b8d3bbfd4 100644 --- a/src/stdlib/test/unit/Helper/ArrayHelperTest.php +++ b/src/stdlib/test/unit/Helper/ArrayHelperTest.php @@ -53,9 +53,10 @@ public function testMerge(): void public function testGetValue(): void { //test base - $arr = ['a' => 1, 'b' => 2]; + $arr = ['a' => 1, 'b' => 2, 3]; $rs = ArrayHelper::getValue($arr, 'b'); $this->assertSame(2, $rs); + $this->assertSame(3, ArrayHelper::getValue($arr, 0)); //test get not exist key $rs2 = ArrayHelper::getValue($arr, 'c'); diff --git a/src/tcp-server/test/bootstrap.php b/src/tcp-server/test/bootstrap.php index d0c933fba..b65b3f166 100644 --- a/src/tcp-server/test/bootstrap.php +++ b/src/tcp-server/test/bootstrap.php @@ -37,37 +37,8 @@ exit('Please run "composer install" to install the dependencies' . PHP_EOL); } -// php run.php -c src/tcp-server/phpunit.xml -// SWOFT_TEST_TCP_SERVER=1 -if (1 === (int)getenv('SWOFT_TEST_TCP_SERVER')) { - // Output: "php is /usr/local/bin/php" - [$ok, $ret,] = Sys::run('type php'); - if (0 !== $ok) { - exit('php not found'); - } - - $type = 'tcp'; - $php = substr(trim($ret), 7); - $proc = new Process(function (Process $proc) use ($php, $type) { - // $proc->exec($php, [ $dir . '/test/bin/swoft', 'ws:start'); - $proc->exec($php, ['test/bin/swoft', $type . ':start']); - }); - $pid = $proc->start(); - echo "Swoft test server started, PID $pid\n"; - - // wait server starting... - sleep(2); - echo file_get_contents('http://127.0.0.1:28308/hi'); -} - $application = new TestApplication([ 'basePath' => __DIR__ ]); $application->setBeanFile(__DIR__ . '/testing/bean.php'); $application->run(); - -if (isset($pid) && $pid > 0) { - echo "Stop server on tests end. PID $pid"; - $ok = Process::kill($pid, 15); - echo $ok ? " OK\n" : " FAIL\n"; -} diff --git a/test/config/base.php b/test/config/base.php index 97b18431e..7c916369a 100644 --- a/test/config/base.php +++ b/test/config/base.php @@ -1,8 +1,8 @@ 'baseData', + 'data' => 'baseData', 'array' => [ 'arr', 'arr2', ] -]; \ No newline at end of file +]; diff --git a/test/testing/Aop/Aspect/BeanAspect.php b/test/testing/Aop/Aspect/BeanAspect.php index 640e7d2f1..ca67e448e 100644 --- a/test/testing/Aop/Aspect/BeanAspect.php +++ b/test/testing/Aop/Aspect/BeanAspect.php @@ -52,8 +52,8 @@ public function after() * * @param JoinPoint $joinPoint * - * @throws \Throwable * @return mixed + * @throws \Throwable */ public function afterReturn(JoinPoint $joinPoint) { @@ -111,4 +111,4 @@ public function clear() { $this->trace = ''; } -} \ No newline at end of file +} diff --git a/test/testing/Aop/Aspect/ExecutionAspect.php b/test/testing/Aop/Aspect/ExecutionAspect.php index e2fc41570..4cce97e24 100644 --- a/test/testing/Aop/Aspect/ExecutionAspect.php +++ b/test/testing/Aop/Aspect/ExecutionAspect.php @@ -53,8 +53,8 @@ public function after() * * @param JoinPoint $joinPoint * - * @throws \Throwable * @return mixed + * @throws \Throwable */ public function afterReturn(JoinPoint $joinPoint) { @@ -112,4 +112,4 @@ public function clear() { $this->trace = ''; } -} \ No newline at end of file +} diff --git a/test/testing/Aop/Aspect/OrderAspect.php b/test/testing/Aop/Aspect/OrderAspect.php index 511bf74b0..56a8b0759 100644 --- a/test/testing/Aop/Aspect/OrderAspect.php +++ b/test/testing/Aop/Aspect/OrderAspect.php @@ -53,8 +53,8 @@ public function after() * * @param JoinPoint $joinPoint * - * @throws \Throwable * @return mixed + * @throws \Throwable */ public function afterReturn(JoinPoint $joinPoint) { @@ -116,4 +116,4 @@ public function clear() { $this->trace = ''; } -} \ No newline at end of file +} diff --git a/test/testing/Aop/Aspect/OrderAspect2.php b/test/testing/Aop/Aspect/OrderAspect2.php index 558f56018..a824b2009 100644 --- a/test/testing/Aop/Aspect/OrderAspect2.php +++ b/test/testing/Aop/Aspect/OrderAspect2.php @@ -54,8 +54,8 @@ public function after() * * @param JoinPoint $joinPoint * - * @throws \Throwable * @return mixed + * @throws \Throwable */ public function afterReturn(JoinPoint $joinPoint) { @@ -113,4 +113,4 @@ public function clear() { $this->trace = ''; } -} \ No newline at end of file +} diff --git a/test/testing/Aop/Aspect/RegAspect.php b/test/testing/Aop/Aspect/RegAspect.php index 8a7df5357..fca85dbbe 100644 --- a/test/testing/Aop/Aspect/RegAspect.php +++ b/test/testing/Aop/Aspect/RegAspect.php @@ -27,11 +27,11 @@ class RegAspect * * @param JoinPoint $joinPoint * - * @throws \Throwable * @return mixed + * @throws \Throwable */ public function afterReturn(JoinPoint $joinPoint) { - return 'RegAspect='.$joinPoint->getReturn(); + return 'RegAspect=' . $joinPoint->getReturn(); } -} \ No newline at end of file +} diff --git a/test/testing/Aop/ParamsAop.php b/test/testing/Aop/ParamsAop.php index 0a093255e..36f49bc30 100644 --- a/test/testing/Aop/ParamsAop.php +++ b/test/testing/Aop/ParamsAop.php @@ -14,8 +14,8 @@ */ class ParamsAop { - public function method(string $name, int $count, int $type = 2, int $max = null):string + public function method(string $name, int $count, int $type = 2, int $max = null): string { return 'method'; } -} \ No newline at end of file +} diff --git a/test/testing/Config/BeanInitConfig.php b/test/testing/Config/BeanInitConfig.php index 5a8447602..ffea2f2a0 100644 --- a/test/testing/Config/BeanInitConfig.php +++ b/test/testing/Config/BeanInitConfig.php @@ -1,11 +1,8 @@ configValue = config('data'); } /** - * @return array + * @return string */ public function getConfigValue(): string { return $this->configValue; } -} \ No newline at end of file +} diff --git a/test/testing/Config/DemoConfig.php b/test/testing/Config/DemoConfig.php index d633d2d3f..a1670c52e 100644 --- a/test/testing/Config/DemoConfig.php +++ b/test/testing/Config/DemoConfig.php @@ -1,11 +1,9 @@ otherArray; } -} \ No newline at end of file +}