SettingsTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of the Carbon package.
  5. *
  6. * (c) Brian Nesbitt <brian@nesbot.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Tests\Carbon;
  12. use Carbon\Carbon;
  13. use Tests\AbstractTestCase;
  14. class SettingsTest extends AbstractTestCase
  15. {
  16. public function testSettings()
  17. {
  18. $paris = Carbon::parse('2018-01-31 00:00:00')->settings([
  19. 'timezone' => 'Europe/Paris',
  20. 'locale' => 'fr_FR',
  21. 'monthOverflow' => true,
  22. 'yearOverflow' => true,
  23. ]);
  24. $this->assertEquals([
  25. 'timezone' => 'Europe/Paris',
  26. 'locale' => 'fr_FR',
  27. 'monthOverflow' => true,
  28. 'yearOverflow' => true,
  29. ], $paris->getSettings());
  30. $saoPaulo = Carbon::parse('2018-01-31 00:00:00')->settings([
  31. 'timezone' => 'America/Sao_Paulo',
  32. 'locale' => 'pt',
  33. 'monthOverflow' => false,
  34. 'yearOverflow' => false,
  35. ]);
  36. $this->assertEquals([
  37. 'timezone' => 'America/Sao_Paulo',
  38. 'locale' => 'pt',
  39. 'monthOverflow' => false,
  40. 'yearOverflow' => false,
  41. ], $saoPaulo->getSettings());
  42. $this->assertSame('2 jours 1 heure avant', $paris->addMonth()->from(Carbon::parse('2018-03-05', 'UTC'), null, false, 3));
  43. $this->assertSame('4 dias 21 horas antes', $saoPaulo->addMonth()->from(Carbon::parse('2018-03-05', 'UTC'), null, false, 3));
  44. $this->assertSame('2 jours et une heure avant', $paris->from(Carbon::parse('2018-03-05', 'UTC'), ['parts' => 3, 'join' => true, 'aUnit' => true]));
  45. }
  46. }