SharingEffectiveBetTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Tests\Unit;
  3. use App\Services\Sharing\EffectiveBet;
  4. use App\Services\BetService;
  5. use PHPUnit\Framework\TestCase;
  6. class SharingEffectiveBetTest extends TestCase
  7. {
  8. /** @dataProvider outcomes */
  9. public function test_calculates_per_bet_net_exposure(string $stake, string $profit, bool $settled, bool $voided, string $expected): void
  10. {
  11. $this->assertSame($expected, EffectiveBet::amount($stake, $profit, $settled, $voided));
  12. }
  13. public function outcomes(): array
  14. {
  15. return [
  16. ['100', '80', true, false, '80.0000000000'],
  17. ['100', '150', true, false, '100.0000000000'],
  18. ['100', '-100', true, false, '100.0000000000'],
  19. ['100', '-50', true, false, '50.0000000000'],
  20. ['100', '0', true, false, '0.0000000000'],
  21. ['100', '80', false, false, '0.0000000000'],
  22. ['100', '-100', true, true, '0.0000000000'],
  23. ['100.0000000001', '0.1234567891', true, false, '0.1234567891'],
  24. ];
  25. }
  26. public function test_original_betting_day_is_converted_to_new_york_across_midnight(): void
  27. {
  28. $this->assertSame('2026-10-23', EffectiveBet::newYorkDate('2026-10-24 00:10:00'));
  29. $this->assertSame('2026-10-23', EffectiveBet::newYorkDate(1792771800));
  30. }
  31. public function test_missing_source_date_is_rejected_instead_of_becoming_today(): void
  32. {
  33. $this->expectException(\InvalidArgumentException::class);
  34. EffectiveBet::newYorkDate(null);
  35. }
  36. public function test_invalid_calendar_date_is_rejected(): void
  37. {
  38. $this->expectException(\InvalidArgumentException::class);
  39. EffectiveBet::newYorkDate('2026-02-31 10:00:00');
  40. }
  41. public function test_pc28_pending_filter_keeps_zero_so_retries_do_not_select_settled_bets(): void
  42. {
  43. $this->assertContains(['lottery_status', '=', 0], BetService::getWhere(['lottery_status' => 0]));
  44. }
  45. }