Files
phalapi-pro/tests/base/Common/Context_Test.php
2022-03-21 11:16:38 +08:00

84 lines
1.7 KiB
PHP

<?php
/**
* PhalApi_App\Common\Context_Test
*
* 针对 ../src/app/Common/Context.php App\Common\Context 类的PHPUnit单元测试
*
* @author: dogstar 20191231
*/
namespace tests\Base\Common;
use Base\Common\Context;
class PhpUnderControl_BaseCommonContext_Test extends \PHPUnit\Framework\TestCase
{
public $appCommonContext;
protected function setUp()
{
parent::setUp();
$this->appCommonContext = new \Base\Common\Context('phpunit', 888);
}
protected function tearDown()
{
// 输出本次单元测试所执行的SQL语句
// var_dump(\PhalApi\DI()->tracer->getSqls());
// 输出本次单元测试所涉及的追踪埋点
// var_dump(\PhalApi\DI()->tracer->getStack());
}
/**
* @group testSetAppKey
*/
public function testSetAppKey()
{
$this->assertEquals('phpunit', $this->appCommonContext->getAppKey());
$appKey = 'phpunit2';
$rs = $this->appCommonContext->setAppKey($appKey);
$this->assertEquals($appKey, $this->appCommonContext->getAppKey());
}
/**
* @group testGetAppKey
*/
public function testGetAppKey()
{
$rs = $this->appCommonContext->getAppKey();
$this->assertEquals('phpunit', $rs);
}
/**
* @group testSetUid
*/
public function testSetUid()
{
$this->assertEquals(888, $this->appCommonContext->getUid());
$uid = '999';
$rs = $this->appCommonContext->setUid($uid);
$this->assertSame(999, $rs->getUid());
}
/**
* @group testGetUid
*/
public function testGetUid()
{
$rs = $this->appCommonContext->getUid();
$this->assertEquals(888, $rs);
}
}