LhcOrderTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Tests\Unit;
  3. use App\Models\LhcOrder;
  4. use PHPUnit\Framework\TestCase;
  5. class LhcOrderTest extends TestCase
  6. {
  7. public function test_it_preserves_stored_profit_and_loss(): void
  8. {
  9. $order = new LhcOrder();
  10. $order->setRawAttributes([
  11. 'profit_and_loss' => '12.345',
  12. 'lottery_status' => LhcOrder::STATUS_WIN,
  13. ]);
  14. $this->assertSame('12.345', $order->profit_and_loss);
  15. }
  16. public function test_it_calculates_missing_profit_and_loss_for_settled_order(): void
  17. {
  18. $order = new LhcOrder();
  19. $order->setRawAttributes([
  20. 'profit_and_loss' => null,
  21. 'lottery_status' => LhcOrder::STATUS_WIN,
  22. 'win_amount' => '150.00',
  23. 'total_amount' => '100.00',
  24. 'amount' => '50.00',
  25. ]);
  26. $this->assertSame('50.00', $order->profit_and_loss);
  27. }
  28. public function test_it_returns_zero_for_unsettled_order(): void
  29. {
  30. $order = new LhcOrder();
  31. $order->setRawAttributes([
  32. 'profit_and_loss' => null,
  33. 'lottery_status' => LhcOrder::STATUS_STAY,
  34. 'win_amount' => '0.00',
  35. 'total_amount' => '100.00',
  36. ]);
  37. $this->assertSame('0.00', $order->profit_and_loss);
  38. }
  39. }