<?php
/**
 * PhalApi_Admin\Api\Index_Test
 *
 * 针对 ./src/admin/Api/Index.php Admin\Api\Index 类的PHPUnit单元测试
 *
 * @author: dogstar 20200113
 */

namespace tests\Admin\Api;
use Admin\Api\Index;
use App\Common\TimeUtil;
use PhalApi\Helper\TestRunner;

class PhpUnderControl_AdminApiIndex_Test extends \PHPUnit\Framework\TestCase
{
    public $adminApiIndex;

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

        $this->adminApiIndex = new \Admin\Api\Index();
    }

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

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


    /**
     * @ runInSeparateProcess
     * @group testGetRules
     */ 
    public function testGetRules()
    {
        $rs = $this->adminApiIndex->getRules();
    }

    /**
     * @group testGetIndexData
     */ 
    public function testGetIndexData()
    {
        $url = 's=Admin.Index.GetIndexData';

        @$rs = TestRunner::go($url);

        $this->assertNotEmpty($rs['systemInfo']);
        $this->assertGreaterThanOrEqual(0, $rs['requestTime']);
        $this->assertGreaterThanOrEqual(0, $rs['apiNum']);
        $this->assertGreaterThanOrEqual(0, $rs['users']);
        $this->assertGreaterThanOrEqual(0, $rs['files']);

    }

    /**
     * @group testGetDataFlow
     */ 
    public function testGetDataFlow()
    {

        $url = "s=Admin.Index.GetDataFlow";

        $rs = TestRunner::go($url);

        $this->assertNotEmpty($rs);

        $this->assertGreaterThanOrEqual(0, $rs[0]['total']);
    }

}
