ClientTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace Alipay\EasySDK\Test\payment\common;
  3. use Alipay\EasySDK\Kernel\Factory;
  4. use Alipay\EasySDK\Test\TestAccount;
  5. use PHPUnit\Framework\TestCase;
  6. class ClientTest extends TestCase
  7. {
  8. public function __construct($name = null, array $data = [], $dataName = '')
  9. {
  10. parent::__construct($name, $data, $dataName);
  11. $account = new TestAccount();
  12. Factory::setOptions($account->getTestAccount());
  13. }
  14. public function testCrate()
  15. {
  16. $result = Factory::payment()->common()->create("Iphone6 16G",
  17. microtime(), "88.88", "2088002656718920");
  18. $this->assertEquals('10000', $result->code);
  19. $this->assertEquals('Success', $result->msg);
  20. return $result->outTradeNo;
  21. }
  22. public function testCreateWithOptional(){
  23. $result = Factory::payment()->common()
  24. ->optional("goods_detail", $this->getGoodsDetail())
  25. ->create("Iphone6 16G",microtime(), "0.01", "2088002656718920");
  26. $this->assertEquals('10000', $result->code);
  27. $this->assertEquals('Success', $result->msg);
  28. }
  29. private function getGoodsDetail(){
  30. $goodDetail = array(
  31. "goods_id" => "apple-01",
  32. "goods_name" => "iPhone6 16G",
  33. "quantity" => 1,
  34. "price" => "0.01"
  35. );
  36. $goodsDetail[0] = $goodDetail;
  37. return $goodsDetail;
  38. }
  39. public function testQuery()
  40. {
  41. $result = Factory::payment()->common()->query('6f149ddb-ab8c-4546-81fb-5880b4aaa318');
  42. $this->assertEquals('10000', $result->code);
  43. $this->assertEquals('Success', $result->msg);
  44. }
  45. public function testCancel()
  46. {
  47. $result = Factory::payment()->common()->cancel($this->testCrate());
  48. $this->assertEquals('10000', $result->code);
  49. $this->assertEquals('Success', $result->msg);
  50. }
  51. public function testClose()
  52. {
  53. $result = Factory::payment()->common()->close($this->testCrate());
  54. $this->assertEquals('10000', $result->code);
  55. $this->assertEquals('Success', $result->msg);
  56. }
  57. public function testRefund()
  58. {
  59. $result = Factory::payment()->common()->refund($this->testCrate(), '0.01');
  60. $this->assertEquals('40004', $result->code);
  61. $this->assertEquals('Business Failed', $result->msg);
  62. $this->assertEquals('ACQ.TRADE_STATUS_ERROR', $result->subCode);
  63. $this->assertEquals('交易状态不合法', $result->subMsg);
  64. }
  65. public function testRefundQuery()
  66. {
  67. $result = Factory::payment()->common()->queryRefund($this->testCrate(), "20200401010101001");
  68. $this->assertEquals('10000', $result->code);
  69. $this->assertEquals('Success', $result->msg);
  70. }
  71. public function testDownloadBill()
  72. {
  73. $result = Factory::payment()->common()->downloadBill("trade", "2020-01");
  74. $this->assertEquals('10000', $result->code);
  75. $this->assertEquals('Success', $result->msg);
  76. }
  77. }