<?php
/**
 * PhalApi_Base\Domain\RSA_Test
 *
 * 针对 ../src/base/Domain/RSA.php Base\Domain\RSA 类的PHPUnit单元测试
 *
 * @author: dogstar 20200414
 */

namespace tests\Base\Domain;
use Base\Domain\RSA;

class PhpUnderControl_BaseDomainRSA_Test extends \PHPUnit\Framework\TestCase
{
    public $baseDomainRSA;

    protected function setUp()
    {
        parent::setUp();

        $domain = new \Base\Domain\Apps();
        $domain->addApp('name_rsa', 'app_key_rsa', 'xxx');

        $this->baseDomainRSA = new \Base\Domain\RSA('app_key_rsa');
    }

    protected function tearDown()
    {
        // 输出本次单元测试所执行的SQL语句
        // var_dump(\PhalApi\DI()->tracer->getSqls());

        // 输出本次单元测试所涉及的追踪埋点
        // var_dump(\PhalApi\DI()->tracer->getStack());
    }


    /**
     * @group testEncrypt
     */ 
    public function testEncrypt()
    {
        $data = 'pro';

        $rs = $this->baseDomainRSA->encrypt($data);

        $this->assertTrue(is_string($rs));
        $this->assertNotEmpty($rs);

        $deRs = $this->baseDomainRSA->decrypt($rs);
        $this->assertEquals('pro', $deRs);

    }

    /**
     * @group testDecrypt
     */ 
    public function testDecrypt()
    {
        $data = 'mmmmm';

        $rs = $this->baseDomainRSA->decrypt($data);

        $this->assertNull($rs);
    }

}
