mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-03-17 20:54:52 +08:00
remove old tests
This commit is contained in:
parent
443ed115b0
commit
c6bbba6051
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace ZM\Utils;
|
||||
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ZM\Config\ZMConfig;
|
||||
|
||||
class DataProviderTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void {
|
||||
ZMConfig::setDirectory(realpath(__DIR__ . "/../Mock"));
|
||||
if (!defined('ZM_DATA'))
|
||||
define("ZM_DATA", DataProvider::getWorkingDir() . "/zm_data/");
|
||||
|
||||
}
|
||||
|
||||
public function testScanDirFiles() {
|
||||
zm_dump(DataProvider::scanDirFiles("/fwef/wegweg"));
|
||||
$this->assertContains("Example/Hello.php", DataProvider::scanDirFiles(DataProvider::getSourceRootDir() . '/src/Module', true, true));
|
||||
}
|
||||
|
||||
public function testGetDataFolder() {
|
||||
DataProvider::getDataFolder("testFolder");
|
||||
$this->assertDirectoryExists(DataProvider::getWorkingDir() . "/zm_data/testFolder");
|
||||
rmdir(DataProvider::getWorkingDir() . "/zm_data/testFolder");
|
||||
}
|
||||
}
|
||||
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ZM\Utils\Manager;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ZM\Config\ZMConfig;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Utils\DataProvider;
|
||||
|
||||
class ModuleManagerTest extends TestCase
|
||||
{
|
||||
public function setUp(): void {
|
||||
file_put_contents(DataProvider::getSourceRootDir()."/src/Module/zm.json", json_encode([
|
||||
"name" => "示例模块2"
|
||||
]));
|
||||
|
||||
ZMConfig::setDirectory(DataProvider::getSourceRootDir() . '/config');
|
||||
ZMConfig::setEnv($args["env"] ?? "");
|
||||
if (ZMConfig::get("global") === false) {
|
||||
die (zm_internal_errcode("E00007") . "Global config load failed: " . ZMConfig::$last_error . "\nPlease init first!\nSee: https://github.com/zhamao-robot/zhamao-framework/issues/37\n");
|
||||
}
|
||||
|
||||
//定义常量
|
||||
include_once DataProvider::getFrameworkRootDir()."/src/ZM/global_defines.php";
|
||||
|
||||
Console::init(
|
||||
ZMConfig::get("global", "info_level") ?? 2,
|
||||
null,
|
||||
$args["log-theme"] ?? "default",
|
||||
($o = ZMConfig::get("console_color")) === false ? [] : $o
|
||||
);
|
||||
|
||||
$timezone = ZMConfig::get("global", "timezone") ?? "Asia/Shanghai";
|
||||
date_default_timezone_set($timezone);
|
||||
}
|
||||
|
||||
public function tearDown(): void {
|
||||
unlink(DataProvider::getSourceRootDir()."/src/Module/zm.json");
|
||||
}
|
||||
|
||||
public function testGetConfiguredModules() {
|
||||
zm_dump(ModuleManager::getConfiguredModules());
|
||||
$this->assertArrayHasKey("示例模块", ModuleManager::getConfiguredModules());
|
||||
}
|
||||
|
||||
public function testPackModule() {
|
||||
$list = ModuleManager::getConfiguredModules();
|
||||
$this->assertTrue(ModuleManager::packModule(current($list)));
|
||||
}
|
||||
}
|
||||
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ZM\Utils;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Swoole\WebSocket\Frame;
|
||||
use ZM\Requests\ZMRequest;
|
||||
|
||||
class MessageUtilTest extends TestCase
|
||||
{
|
||||
public function setUp(): void {
|
||||
ZMRequest::websocket();
|
||||
$a = new Frame();
|
||||
|
||||
$a->opcode = WEBSOCKET_OPCODE_PONG;
|
||||
}
|
||||
|
||||
public function testGetImageCQFromLocal() {
|
||||
file_put_contents("/tmp/a.jpg", "fake photo");
|
||||
$this->assertEquals(
|
||||
MessageUtil::getImageCQFromLocal("/tmp/a.jpg"),
|
||||
"[CQ:image,file=base64://".base64_encode("fake photo")."]"
|
||||
);
|
||||
}
|
||||
|
||||
public function testSplitCommand() {
|
||||
$msg_sample_1 = "你好啊 233\n\nhello";
|
||||
$msg_sample_2 = "";
|
||||
$this->assertCount(3, MessageUtil::splitCommand($msg_sample_1));
|
||||
$this->assertCount(1, MessageUtil::splitCommand($msg_sample_2));
|
||||
}
|
||||
|
||||
public function testIsAtMe() {
|
||||
$this->assertTrue(MessageUtil::isAtMe("[CQ:at,qq=123]", 123));
|
||||
$this->assertFalse(MessageUtil::isAtMe("[CQ:at,qq=]", 0));
|
||||
}
|
||||
|
||||
public function testDownloadCQImage() {
|
||||
if (file_exists(WORKING_DIR."/zm_data/images/abc.jpg"))
|
||||
unlink(WORKING_DIR."/zm_data/images/abc.jpg");
|
||||
ob_start();
|
||||
$msg = "[CQ:image,file=abc.jpg,url=https://zhamao.xin/file/hello.jpg]";
|
||||
$result = MessageUtil::downloadCQImage($msg, "/home/jerry/fweewfwwef/wef");
|
||||
$this->assertFalse($result);
|
||||
$this->assertStringContainsString("E00059", ob_get_clean());
|
||||
$result = MessageUtil::downloadCQImage($msg);
|
||||
$this->assertIsArray($result);
|
||||
$this->assertFileExists(WORKING_DIR."/zm_data/images/abc.jpg");
|
||||
$result = MessageUtil::downloadCQImage($msg.$msg);
|
||||
$this->assertIsArray($result);
|
||||
$this->assertCount(2, $result);
|
||||
}
|
||||
|
||||
public function testContainsImage() {
|
||||
$msg_sample = "hello\n[CQ:imag2]";
|
||||
$this->assertFalse(MessageUtil::containsImage($msg_sample));
|
||||
$this->assertTrue(MessageUtil::containsImage($msg_sample."[CQ:image,file=123]"));
|
||||
}
|
||||
|
||||
public function testMatchCommand() {
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ZM\Utils;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ZM\Config\ZMConfig;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Store\LightCacheInside;
|
||||
use ZM\Store\ZMAtomic;
|
||||
|
||||
class TerminalTest extends TestCase
|
||||
{
|
||||
public function setUp(): void {
|
||||
}
|
||||
|
||||
public function testExecuteCommand() {
|
||||
ob_start();
|
||||
Terminal::executeCommand("logtest");
|
||||
$this->assertStringContainsString("debug msg", ob_get_clean());
|
||||
}
|
||||
|
||||
public function testBc() {
|
||||
ob_start();
|
||||
Terminal::executeCommand("bc ".base64_encode("echo 'hello';"));
|
||||
$this->assertStringContainsString("hello", ob_get_clean());
|
||||
}
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace ZM\Utils;
|
||||
|
||||
|
||||
use Module\Example\Hello;
|
||||
use Module\Middleware\TimerMiddleware;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ZM\Framework;
|
||||
|
||||
class ZMUtilTest extends TestCase
|
||||
{
|
||||
public function testGetClassesPsr4() {
|
||||
$this->assertContains(Hello::class, ZMUtil::getClassesPsr4(DataProvider::getSourceRootDir()."/src/Module", "Module"));
|
||||
$this->assertContains(TimerMiddleware::class, ZMUtil::getClassesPsr4(DataProvider::getSourceRootDir()."/src/Module", "Module"));
|
||||
$this->assertContains(Framework::class, ZMUtil::getClassesPsr4(DataProvider::getSourceRootDir()."/src/ZM", "ZM"));
|
||||
}
|
||||
|
||||
public function testGetModInstance() {
|
||||
$class = Hello::class;
|
||||
$this->assertTrue(ZMUtil::getModInstance($class) instanceof Hello);
|
||||
}
|
||||
}
|
||||
@ -1,2 +0,0 @@
|
||||
<?php
|
||||
|
||||
@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace ZMTest\PassedTest;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Module\Example\Hello;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ReflectionException;
|
||||
use ZM\Annotation\AnnotationParser;
|
||||
use ZM\Annotation\Swoole\OnStart;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Event\EventTracer;
|
||||
|
||||
class AnnotationParserRegisterTest extends TestCase
|
||||
{
|
||||
private $parser;
|
||||
|
||||
public function setUp(): void {
|
||||
if (!defined("WORKING_DIR"))
|
||||
define("WORKING_DIR", realpath(__DIR__ . "/../../../"));
|
||||
if (!defined("LOAD_MODE"))
|
||||
define("LOAD_MODE", 0);
|
||||
Console::init(4);
|
||||
$this->parser = new AnnotationParser();
|
||||
$this->parser->addRegisterPath(WORKING_DIR . "/src/Module/", "Module");
|
||||
try {
|
||||
$this->parser->registerMods();
|
||||
} catch (ReflectionException $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function testAnnotation() {
|
||||
ob_start();
|
||||
$gen = $this->parser->generateAnnotationEvents();
|
||||
//zm_dump($gen);
|
||||
$m = $gen[OnStart::class][0]->method;
|
||||
$class = $gen[OnStart::class][0]->class;
|
||||
$c = new $class();
|
||||
try {
|
||||
$c->$m();
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
$result = ob_get_clean();
|
||||
$this->assertStringContainsString("我开始了!", $result);
|
||||
}
|
||||
|
||||
public function testAnnotation2() {
|
||||
foreach ($this->parser->generateAnnotationEvents() as $k => $v) {
|
||||
foreach ($v as $vs) {
|
||||
$this->assertTrue($vs->method === null || $vs->method != '');
|
||||
$this->assertTrue(strlen($vs->class) > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testMiddlewares() {
|
||||
$wares = $this->parser->getMiddlewares();
|
||||
zm_dump($wares);
|
||||
$this->assertArrayHasKey("timer", $wares);
|
||||
}
|
||||
}
|
||||
@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace ZMTest\Testing;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationException;
|
||||
use Module\Example\Hello;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ReflectionException;
|
||||
use Swoole\Atomic;
|
||||
use ZM\Annotation\AnnotationParser;
|
||||
use ZM\Annotation\CQ\CQCommand;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Event\EventDispatcher;
|
||||
use ZM\Event\EventManager;
|
||||
use ZM\Store\LightCacheInside;
|
||||
use ZM\Store\ZMAtomic;
|
||||
|
||||
class EventDispatcherTest extends TestCase
|
||||
{
|
||||
|
||||
public function testDispatch() {
|
||||
Console::init(2);
|
||||
if (!defined("WORKING_DIR"))
|
||||
define("WORKING_DIR", realpath(__DIR__ . "/../../../"));
|
||||
if (!defined("LOAD_MODE"))
|
||||
define("LOAD_MODE", 0);
|
||||
Console::init(4);
|
||||
ZMAtomic::$atomics["_event_id"] = new Atomic(0);
|
||||
LightCacheInside::init();
|
||||
$parser = new AnnotationParser();
|
||||
$parser->addRegisterPath(WORKING_DIR . "/src/Module/", "Module");
|
||||
try {
|
||||
$parser->registerMods();
|
||||
} catch (ReflectionException $e) {
|
||||
throw $e;
|
||||
}
|
||||
EventManager::loadEventByParser($parser);
|
||||
$dispatcher = new EventDispatcher(CQCommand::class);
|
||||
$dispatcher->setReturnFunction(function ($result) {
|
||||
echo $result . PHP_EOL;
|
||||
});
|
||||
//$dispatcher->setRuleFunction(function ($v) { return $v->match == "qwe"; });
|
||||
$dispatcher->setRuleFunction(function ($v) { return $v->match == "你好"; });
|
||||
//$dispatcher->setRuleFunction(fn ($v) => $v->match == "qwe");
|
||||
ob_start();
|
||||
$dispatcher->dispatchEvents();
|
||||
$r = ob_get_clean();
|
||||
echo $r;
|
||||
$this->assertStringContainsString("你好啊", $r);
|
||||
$dispatcher = new EventDispatcher(CQCommand::class);
|
||||
$dispatcher->setReturnFunction(function ($result) {
|
||||
//echo $result . PHP_EOL;
|
||||
});
|
||||
//$dispatcher->setRuleFunction(function ($v) { return $v->match == "qwe"; });
|
||||
$dispatcher->setRuleFunction(function ($v) { return $v->match == "qwe"; });
|
||||
//$dispatcher->setRuleFunction(fn ($v) => $v->match == "qwe");
|
||||
$dispatcher->dispatchEvents();
|
||||
}
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace ZMTest\Testing;
|
||||
|
||||
|
||||
use Module\Example\Hello;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ZM\Config\ZMConfig;
|
||||
use ZM\ConsoleApplication;
|
||||
use ZM\Utils\ZMUtil;
|
||||
|
||||
class ModuleTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void {
|
||||
ZMConfig::setDirectory(realpath(__DIR__."/../Mock"));
|
||||
set_coroutine_params([]);
|
||||
(new ConsoleApplication('zhamao-test'))->initEnv();
|
||||
require_once __DIR__ . '/../../../src/ZM/global_defines.php';
|
||||
}
|
||||
|
||||
public function testCtx() {
|
||||
$r = ZMUtil::getModInstance(Hello::class);
|
||||
ob_start();
|
||||
$r->randNum(["随机数", "1", "5"]);
|
||||
$out = ob_get_clean();
|
||||
$this->assertEquals("随机数是:1\n", $out);
|
||||
}
|
||||
}
|
||||
@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . "/../vendor/autoload.php";
|
||||
|
||||
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
|
||||
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
||||
use Symfony\Component\Routing\Matcher\UrlMatcher;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\Route;
|
||||
$root = new RouteCollection();
|
||||
$route = new Route('/foo', array('controller' => 'MyController'));
|
||||
$routes = new RouteCollection();
|
||||
|
||||
|
||||
$routes->add('route_name', $route);
|
||||
|
||||
|
||||
|
||||
$route = new Route(
|
||||
'/archive/{month}', // path
|
||||
array('controller' => 'showArchive', 'asd' => 'feswf'), // default values
|
||||
array('month' => '[0-9]{4}-[0-9]{2}', 'subdomain' => 'www|m'), // requirements
|
||||
array(), // options
|
||||
'', // host
|
||||
array(), // schemes
|
||||
array() // methods
|
||||
);
|
||||
|
||||
// ...
|
||||
|
||||
$routes->add('date', new Route(
|
||||
'/archive/{month}', // path
|
||||
array('controller' => 'showArchive', 'asd' => 'feswf'), // default values
|
||||
array('month' => '[0-9]{4}-[0-9]{2}', 'subdomain' => 'www|m'), // requirements
|
||||
array(), // options
|
||||
'', // host
|
||||
array(), // schemes
|
||||
array() // methods
|
||||
));
|
||||
|
||||
|
||||
|
||||
$route = new Route('/archive/test');
|
||||
|
||||
$routes->add('qwerty', $route);
|
||||
|
||||
$route = new Route('/{aas}/{test}', ['_class' => stdClass::class, '_method' => 'foo'],[],["class" => stdClass::class]);
|
||||
|
||||
$routes->add('root', $route);
|
||||
|
||||
$context = new RequestContext();
|
||||
|
||||
//$root->addCollection($routes);
|
||||
$matcher = new UrlMatcher($root, $context);
|
||||
$root->addCollection($routes);
|
||||
|
||||
dump($root->all());
|
||||
//$parameters = $matcher->match('/test/foo');var_dump($parameters);
|
||||
// array(
|
||||
// 'controller' => 'showArchive',
|
||||
// 'month' => '2012-01',
|
||||
// 'subdomain' => 'www',
|
||||
// '_route' => ...
|
||||
// )
|
||||
try {
|
||||
$parameters = $matcher->match('/fooss/%20');
|
||||
var_dump($parameters);
|
||||
} catch (ResourceNotFoundException $e) {
|
||||
echo $e->getMessage().PHP_EOL;
|
||||
} catch (MethodNotAllowedException $e) {
|
||||
}
|
||||
|
||||
|
||||
$sub = new RouteCollection();
|
||||
Loading…
x
Reference in New Issue
Block a user