SharingFootballSettlementTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Tests\Unit;
  3. use PHPUnit\Framework\Attributes\DataProvider;
  4. use PHPUnit\Framework\TestCase;
  5. class SharingFootballSettlementTest extends TestCase
  6. {
  7. protected function setUp(): void
  8. {
  9. parent::setUp();
  10. $servicePath = '/app/common/service/FootballSettlementService.php';
  11. $siteRoot = getenv('SHARING_TP_ROOT');
  12. if (!$siteRoot) {
  13. // 支持主检出旁的同级仓库,也支持仓库内部的嵌套工作树。
  14. $ancestor = dirname(__DIR__, 2);
  15. do {
  16. $ancestor = dirname($ancestor);
  17. $siteRoot = $ancestor . '/melbet_sport-api';
  18. } while (!is_file($siteRoot . $servicePath) && $ancestor !== dirname($ancestor));
  19. }
  20. $serviceFile = rtrim($siteRoot, '/\\') . $servicePath;
  21. if (!is_file($serviceFile)) {
  22. throw new \RuntimeException('FootballSettlementService.php not found; set SHARING_TP_ROOT to the melbet_sport-api repository.');
  23. }
  24. require_once $serviceFile;
  25. }
  26. #[DataProvider('footballOutcomes')]
  27. public function test_actual_wallet_return_includes_unlost_principal(string $selection, string $expectedProfit, string $expectedPayout): void
  28. {
  29. $detail = ['odds' => [['values' => [['value' => $selection, 'odd' => '1.80']]]]];
  30. $result = \app\common\service\FootballSettlementService::totalHomeOrAway('100.00', 2, $detail);
  31. $result['amount'] = '100.00';
  32. $this->assertEquals($expectedProfit, $result['profit_and_loss']);
  33. $this->assertSame($expectedPayout, \app\common\service\FootballSettlementService::payoutAmount($result));
  34. }
  35. public static function footballOutcomes(): array
  36. {
  37. return [
  38. ['Over 1.5', '80', '180.00'],
  39. ['Over 1.75', '40', '140.00'],
  40. ['Over 2', '0', '100.00'],
  41. ['Over 2.25', '-50', '50.00'],
  42. ['Over 2.5', '-100', '0.00'],
  43. ];
  44. }
  45. public function test_generic_draw_result_exposes_the_principal_refund(): void
  46. {
  47. $result = \app\common\service\FootballSettlementService::getResult(2, '100.00', '1.80');
  48. $this->assertSame('100.00', $result['return_amount']);
  49. $this->assertSame('100.00', \app\common\service\FootballSettlementService::payoutAmount($result + ['amount' => '100.00']));
  50. }
  51. }