| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace Tests\Unit;
- use PHPUnit\Framework\Attributes\DataProvider;
- use PHPUnit\Framework\TestCase;
- class SharingFootballSettlementTest extends TestCase
- {
- protected function setUp(): void
- {
- parent::setUp();
- $servicePath = '/app/common/service/FootballSettlementService.php';
- $siteRoot = getenv('SHARING_TP_ROOT');
- if (!$siteRoot) {
- // 支持主检出旁的同级仓库,也支持仓库内部的嵌套工作树。
- $ancestor = dirname(__DIR__, 2);
- do {
- $ancestor = dirname($ancestor);
- $siteRoot = $ancestor . '/melbet_sport-api';
- } while (!is_file($siteRoot . $servicePath) && $ancestor !== dirname($ancestor));
- }
- $serviceFile = rtrim($siteRoot, '/\\') . $servicePath;
- if (!is_file($serviceFile)) {
- throw new \RuntimeException('FootballSettlementService.php not found; set SHARING_TP_ROOT to the melbet_sport-api repository.');
- }
- require_once $serviceFile;
- }
- #[DataProvider('footballOutcomes')]
- public function test_actual_wallet_return_includes_unlost_principal(string $selection, string $expectedProfit, string $expectedPayout): void
- {
- $detail = ['odds' => [['values' => [['value' => $selection, 'odd' => '1.80']]]]];
- $result = \app\common\service\FootballSettlementService::totalHomeOrAway('100.00', 2, $detail);
- $result['amount'] = '100.00';
- $this->assertEquals($expectedProfit, $result['profit_and_loss']);
- $this->assertSame($expectedPayout, \app\common\service\FootballSettlementService::payoutAmount($result));
- }
- public static function footballOutcomes(): array
- {
- return [
- ['Over 1.5', '80', '180.00'],
- ['Over 1.75', '40', '140.00'],
- ['Over 2', '0', '100.00'],
- ['Over 2.25', '-50', '50.00'],
- ['Over 2.5', '-100', '0.00'],
- ];
- }
- public function test_generic_draw_result_exposes_the_principal_refund(): void
- {
- $result = \app\common\service\FootballSettlementService::getResult(2, '100.00', '1.80');
- $this->assertSame('100.00', $result['return_amount']);
- $this->assertSame('100.00', \app\common\service\FootballSettlementService::payoutAmount($result + ['amount' => '100.00']));
- }
- }
|