Skip to content

Commit

Permalink
feat:tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Player626 committed Jun 29, 2020
1 parent 8358f7f commit 0702e30
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* @author gaobinzhan <[email protected]>
*/


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);
}
}
39 changes: 39 additions & 0 deletions tests/LoggerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* @author gaobinzhan <[email protected]>
*/


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());
}
}
38 changes: 38 additions & 0 deletions tests/TriggerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* @author gaobinzhan <[email protected]>
*/


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

0 comments on commit 0702e30

Please sign in to comment.