add Terminal related test

This commit is contained in:
crazywhalecc 2022-05-04 21:31:38 +08:00
parent 4defd8ac1b
commit b6742526aa
3 changed files with 38 additions and 5 deletions

View File

@ -9,6 +9,7 @@ use Closure;
use Doctrine\Common\Annotations\AnnotationException;
use Error;
use Exception;
use Throwable;
use ZM\Config\ZMConfig;
use ZM\Console\Console;
use ZM\Exception\InterruptException;
@ -110,7 +111,7 @@ class EventDispatcher
/**
* @param mixed ...$params
* @throws Exception
* @throws Throwable
*/
public function dispatchEvents(...$params)
{
@ -137,7 +138,7 @@ class EventDispatcher
} catch (InterruptException $e) {
$this->store = $e->return_var;
$this->status = self::STATUS_INTERRUPTED;
} catch (Exception|Error $e) {
} catch (Throwable $e) {
$this->status = self::STATUS_EXCEPTION;
throw $e;
}

View File

@ -7,10 +7,10 @@ declare(strict_types=1);
namespace ZM\Utils;
use Doctrine\Common\Annotations\AnnotationReader;
use Error;
use Exception;
use ReflectionClass;
use Swoole\Process;
use Throwable;
use ZM\Annotation\Command\TerminalCommand;
use ZM\ConnectionManager\ManagerGM;
use ZM\Console\Console;
@ -22,8 +22,7 @@ class Terminal
public static $default_commands = false;
/**
* @throws Exception
* @throws Error
* @throws Throwable
* @return bool
* @noinspection PhpMissingReturnTypeInspection
* @noinspection PhpUnused

View 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());
}
}