mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-24 00:55:35 +08:00
add Terminal related test
This commit is contained in:
@@ -9,6 +9,7 @@ use Closure;
|
|||||||
use Doctrine\Common\Annotations\AnnotationException;
|
use Doctrine\Common\Annotations\AnnotationException;
|
||||||
use Error;
|
use Error;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Throwable;
|
||||||
use ZM\Config\ZMConfig;
|
use ZM\Config\ZMConfig;
|
||||||
use ZM\Console\Console;
|
use ZM\Console\Console;
|
||||||
use ZM\Exception\InterruptException;
|
use ZM\Exception\InterruptException;
|
||||||
@@ -110,7 +111,7 @@ class EventDispatcher
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed ...$params
|
* @param mixed ...$params
|
||||||
* @throws Exception
|
* @throws Throwable
|
||||||
*/
|
*/
|
||||||
public function dispatchEvents(...$params)
|
public function dispatchEvents(...$params)
|
||||||
{
|
{
|
||||||
@@ -137,7 +138,7 @@ class EventDispatcher
|
|||||||
} catch (InterruptException $e) {
|
} catch (InterruptException $e) {
|
||||||
$this->store = $e->return_var;
|
$this->store = $e->return_var;
|
||||||
$this->status = self::STATUS_INTERRUPTED;
|
$this->status = self::STATUS_INTERRUPTED;
|
||||||
} catch (Exception|Error $e) {
|
} catch (Throwable $e) {
|
||||||
$this->status = self::STATUS_EXCEPTION;
|
$this->status = self::STATUS_EXCEPTION;
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ declare(strict_types=1);
|
|||||||
namespace ZM\Utils;
|
namespace ZM\Utils;
|
||||||
|
|
||||||
use Doctrine\Common\Annotations\AnnotationReader;
|
use Doctrine\Common\Annotations\AnnotationReader;
|
||||||
use Error;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use Swoole\Process;
|
use Swoole\Process;
|
||||||
|
use Throwable;
|
||||||
use ZM\Annotation\Command\TerminalCommand;
|
use ZM\Annotation\Command\TerminalCommand;
|
||||||
use ZM\ConnectionManager\ManagerGM;
|
use ZM\ConnectionManager\ManagerGM;
|
||||||
use ZM\Console\Console;
|
use ZM\Console\Console;
|
||||||
@@ -22,8 +22,7 @@ class Terminal
|
|||||||
public static $default_commands = false;
|
public static $default_commands = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Throwable
|
||||||
* @throws Error
|
|
||||||
* @return bool
|
* @return bool
|
||||||
* @noinspection PhpMissingReturnTypeInspection
|
* @noinspection PhpMissingReturnTypeInspection
|
||||||
* @noinspection PhpUnused
|
* @noinspection PhpUnused
|
||||||
|
|||||||
33
tests/ZM/Utils/TerminalTest.php
Normal file
33
tests/ZM/Utils/TerminalTest.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\ZM\Utils;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Throwable;
|
||||||
|
use ZM\Console\Console;
|
||||||
|
use ZM\Utils\Terminal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
class TerminalTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testInit()
|
||||||
|
{
|
||||||
|
Console::setLevel(4);
|
||||||
|
Terminal::init();
|
||||||
|
$this->assertStringContainsString('Initializing Terminal', $this->getActualOutput());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
public function testExecuteCommand()
|
||||||
|
{
|
||||||
|
Console::setLevel(2);
|
||||||
|
Terminal::executeCommand('echo zhamao-framework');
|
||||||
|
$this->assertStringContainsString('zhamao-framework', $this->getActualOutput());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user