<?php
/**
 * PhalApi_Mall\Domain\Pay_Test
 *
 * 针对 ../src/mall/Domain/Pay.php Mall\Domain\Pay 类的PHPUnit单元测试
 *
 * @author: dogstar 20200924
 */

namespace tests\Mall\Domain;
use Mall\Domain\Pay;

class PhpUnderControl_MallDomainPay_Test extends \PHPUnit\Framework\TestCase
{
    public $mallDomainPay;

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

        $this->mallDomainPay = new \Mall\Domain\Pay();
    }

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

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


    /**
     * @group testStartPay
     */ 
    public function testStartPay()
    {
        $sql = "insert into `pp_mall_order` ( `is_deliver`, `username`, `pay_time`, `product_type`, `product_key`, `member_id`, `order_status`, `pay_type`, `third_payment_id`, `product_expire_time`, `order_id`, `id`, `product_id`, `add_time`, `num`, `product_expire_time_desc`, `note`, `product_amount`, `price`, `order_name`) values ( '0', 'admin', '2020-09-21 21:58:55', 'api_buy', 'App.BarCode.Gen', '1', '0', 'cash', '', '86400', '2020091516064079999', '159', '4', '2020-09-15 16:06:40', '4', '1个月', 'test', '9', '2.00', '条形码流量套餐');";
        \PhalApi\DI()->notorm->demo->executeSql($sql);

        $order_id = '2020091516064079999';
        $pay_type = null;

        $rs = $this->mallDomainPay->startPay($order_id, $pay_type);

        $this->assertEquals('cash', $rs['pay_type']);
    }

    /**
     * @group testCheckPay
     */ 
    public function testCheckPay()
    {
        $orderInfo = array('order_id' => '2020091516064079999', 'pay_type' => 'cash');;

        $rs = $this->mallDomainPay->checkPay($orderInfo);

        $this->assertFalse($rs);
    }

    /**
     * @group testAlipayNotify
     */ 
    //public function testAlipayNotify()
    //{
    //    $rs = $this->mallDomainPay->alipayNotify();
    //}

    /**
     * @group testCapturePaypalOrder
     */ 
    public function testCapturePaypalOrder()
    {
        $sql = "insert into `pp_mall_order` ( `is_deliver`, `username`, `pay_time`, `product_type`, `product_key`, `member_id`, `order_status`, `pay_type`, `third_payment_id`, `product_expire_time`, `order_id`, `id`, `product_id`, `add_time`, `num`, `product_expire_time_desc`, `note`, `product_amount`, `price`, `order_name`) values ( '1', 'admin', '2020-09-22 16:11:02', 'api_buy', 'App.BarCode.Gen', '1', '20', 'paypal', '2D387077TH8550000', '86400', '2020091516064072543', '4', '4', '2020-09-15 16:06:40', '4', '1个月', 'test', '9', '2.00', '条形码流量套餐');";
        \PhalApi\DI()->notorm->demo->executeSql($sql);

        $orderInfo = \PhalApi\DI()->notorm->mall_order->where('order_id', '2D387077TH8550000')->fetchOne();

        $rs = $this->mallDomainPay->checkPay($orderInfo);

        $this->assertFalse($rs);

        //$payConfig = '';
        //$orderInfo = '';

        //$rs = $this->mallDomainPay->capturePaypalOrder($payConfig, $orderInfo);
    }

}
