PriceHelperTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Tests\Unit\Helpers;
  3. use App\Helpers\Price;
  4. use PHPUnit\Framework\TestCase;
  5. class PriceHelperTest extends TestCase
  6. {
  7. public function test_format_adds_currency_symbol(): void
  8. {
  9. $result = Price::format(100.00);
  10. $this->assertStringContainsString('₽', $result);
  11. }
  12. public function test_format_shows_two_decimal_places(): void
  13. {
  14. $result = Price::format(100);
  15. $this->assertStringContainsString('.00', $result);
  16. }
  17. public function test_format_handles_decimal_prices(): void
  18. {
  19. $result = Price::format(123.45);
  20. $this->assertStringContainsString('123.45', $result);
  21. }
  22. public function test_format_uses_nbsp_as_thousands_separator(): void
  23. {
  24. $result = Price::format(1234567.89);
  25. // &nbsp; is used as thousands separator
  26. $this->assertStringContainsString('&nbsp;', $result);
  27. $this->assertStringContainsString('1', $result);
  28. $this->assertStringContainsString('234', $result);
  29. $this->assertStringContainsString('567', $result);
  30. $this->assertStringContainsString('.89', $result);
  31. }
  32. public function test_format_handles_zero(): void
  33. {
  34. $result = Price::format(0);
  35. $this->assertEquals('0.00₽', $result);
  36. }
  37. public function test_format_handles_small_amounts(): void
  38. {
  39. $result = Price::format(0.01);
  40. $this->assertEquals('0.01₽', $result);
  41. }
  42. public function test_format_handles_large_amounts(): void
  43. {
  44. $result = Price::format(999999999.99);
  45. $this->assertStringContainsString('₽', $result);
  46. $this->assertStringContainsString('.99', $result);
  47. }
  48. }