SharingFootballSettlementTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace Tests\Unit;
  3. use PHPUnit\Framework\TestCase;
  4. class SharingFootballSettlementTest extends TestCase
  5. {
  6. protected function setUp(): void
  7. {
  8. parent::setUp();
  9. require_once dirname(__DIR__, 3) . '/melbet_sport-api/app/common/service/FootballSettlementService.php';
  10. }
  11. /** @dataProvider footballOutcomes */
  12. public function test_actual_wallet_return_includes_unlost_principal(string $selection, string $expectedProfit, string $expectedPayout): void
  13. {
  14. $detail = ['odds' => [['values' => [['value' => $selection, 'odd' => '1.80']]]]];
  15. $result = \app\common\service\FootballSettlementService::totalHomeOrAway('100.00', 2, $detail);
  16. $result['amount'] = '100.00';
  17. $this->assertEquals($expectedProfit, $result['profit_and_loss']);
  18. $this->assertSame($expectedPayout, \app\common\service\FootballSettlementService::payoutAmount($result));
  19. }
  20. public function footballOutcomes(): array
  21. {
  22. return [
  23. ['Over 1.5', '80', '180.00'],
  24. ['Over 1.75', '40', '140.00'],
  25. ['Over 2', '0', '100.00'],
  26. ['Over 2.25', '-50', '50.00'],
  27. ['Over 2.5', '-100', '0.00'],
  28. ];
  29. }
  30. public function test_generic_draw_result_exposes_the_principal_refund(): void
  31. {
  32. $result = \app\common\service\FootballSettlementService::getResult(2, '100.00', '1.80');
  33. $this->assertSame('100.00', $result['return_amount']);
  34. $this->assertSame('100.00', \app\common\service\FootballSettlementService::payoutAmount($result + ['amount' => '100.00']));
  35. }
  36. }