TestLoggerException.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Tests\Dev;
  3. use Tests\Unit\ProtoJsonRequestTest;
  4. use Tests\Unit\ProtoJsonRequest;
  5. use Uraus\Kku\Request;
  6. use Google\Protobuf\Internal\Message;
  7. /**
  8. * 测试Logger::exception格式化
  9. */
  10. class TestLoggerException extends ProtoJsonRequestTest implements ProtoJsonRequest
  11. {
  12. public $token = 'f4b3c51a583a601c3e6130710490f64a';
  13. /**
  14. * 测试异常日志格式
  15. */
  16. public function testLoggerExceptionFormat()
  17. {
  18. // 故意传入无效的商品ID来触发异常
  19. $response = $this->protobufRequest();
  20. // 验证响应
  21. $this->assertNotNull($response);
  22. // 打印响应以便查看
  23. echo json_encode([
  24. 'code' => $response->getCode(),
  25. 'msg' => $response->getMsg(),
  26. ], JSON_UNESCAPED_UNICODE);
  27. }
  28. /**
  29. * 构建请求数据
  30. */
  31. public function requestProtobufJson(): string
  32. {
  33. $request = new Request();
  34. $shopBuy = new \Uraus\Kku\Request\RequestShopBuy();
  35. // 使用不存在的商品ID来触发异常
  36. $shopBuy->setGoodId(99999);
  37. $shopBuy->setNumber(1);
  38. $request->setShopBuy($shopBuy);
  39. return $request->serializeToJsonString();
  40. }
  41. }