SharingEffectiveBetTest.php 1.9 KB

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