From 0702e30882f0b05d1e328a30be541737a1a82528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E5=BD=AC=E5=B1=95?= Date: Mon, 29 Jun 2020 13:23:59 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9Atests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/ConfigTest.php | 59 +++++++++++++++++++++++++++++++++++++++++++ tests/LoggerTest.php | 39 ++++++++++++++++++++++++++++ tests/TriggerTest.php | 38 ++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 tests/ConfigTest.php create mode 100644 tests/LoggerTest.php create mode 100644 tests/TriggerTest.php diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php new file mode 100644 index 00000000..6c4f06a5 --- /dev/null +++ b/tests/ConfigTest.php @@ -0,0 +1,59 @@ + + */ + + +namespace EasySwoole\EasySwoole\Test; + + +use EasySwoole\Config\AbstractConfig; +use EasySwoole\Config\TableConfig; +use EasySwoole\EasySwoole\Config; +use PHPUnit\Framework\TestCase; + +class ConfigTest extends TestCase +{ + public function testStorageHandler() + { + $config = new TableConfig(); + $this->assertInstanceOf(AbstractConfig::class, Config::getInstance()->storageHandler($config)); + } + + public function testGetConf() + { + $conf = Config::getInstance()->getConf(); + $this->assertEmpty($conf); + } + + public function testSetConf() + { + $bool = Config::getInstance()->setConf('test', 'easyswoole'); + $this->assertTrue($bool); + $this->assertEquals('easyswoole', Config::getInstance()->getConf('test')); + } + + public function testLoad() + { + $bool = Config::getInstance()->load(['test' => 'easyswoole']); + $this->assertTrue($bool); + + $conf = Config::getInstance()->getConf(); + $this->assertEquals(['test' => 'easyswoole'], $conf); + } + + public function testMerge() + { + $bool = Config::getInstance()->merge(['test' => 'easyswoole']); + $this->assertTrue($bool); + + $conf = Config::getInstance()->getConf(); + $this->assertEquals(['test' => 'easyswoole'], $conf); + } + + public function testClear() + { + $bool = Config::getInstance()->clear(); + $this->assertTrue($bool); + } +} \ No newline at end of file diff --git a/tests/LoggerTest.php b/tests/LoggerTest.php new file mode 100644 index 00000000..d9277558 --- /dev/null +++ b/tests/LoggerTest.php @@ -0,0 +1,39 @@ + + */ + + +namespace EasySwoole\EasySwoole\Test; + + +use EasySwoole\Component\Di; +use EasySwoole\Component\Event; +use EasySwoole\EasySwoole\Logger; +use EasySwoole\EasySwoole\SysConst; +use EasySwoole\Log\LoggerInterface; +use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\TestResult; + +class LoggerTest extends TestCase +{ + /** @var Logger */ + private $logger; + + public function runTest() + { + $logger = Di::getInstance()->get(SysConst::LOGGER_HANDLER); + $this->logger = Logger::getInstance($logger); + return parent::runTest(); // TODO: Change the autogenerated stub + } + + public function testSetLogConsole() + { + $this->assertInstanceOf(LoggerInterface::class, $this->logger->setLogConsole(true)); + } + + public function testOnLog() + { + $this->assertInstanceOf(Event::class, $this->logger->onLog()); + } +} \ No newline at end of file diff --git a/tests/TriggerTest.php b/tests/TriggerTest.php new file mode 100644 index 00000000..859c399a --- /dev/null +++ b/tests/TriggerTest.php @@ -0,0 +1,38 @@ + + */ + + +namespace EasySwoole\EasySwoole\Test; + + +use EasySwoole\Component\Di; +use EasySwoole\Component\Event; +use EasySwoole\EasySwoole\SysConst; +use EasySwoole\EasySwoole\Trigger; +use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\TestResult; + +class TriggerTest extends TestCase +{ + /** @var Trigger */ + private $trigger; + + public function runTest() + { + $trigger = Di::getInstance()->get(SysConst::TRIGGER_HANDLER); + $this->trigger = Trigger::getInstance($trigger); + return parent::runTest(); // TODO: Change the autogenerated stub + } + + public function testOnError() + { + $this->assertInstanceOf(Event::class, $this->trigger->onError()); + } + + public function testOnException() + { + $this->assertInstanceOf(Event::class, $this->trigger->onException()); + } +} \ No newline at end of file