TestingAidsTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. * This file is part of the Carbon package.
  4. *
  5. * (c) Brian Nesbitt <brian@nesbot.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. use Carbon\Carbon;
  11. class TestingAidsTest extends TestFixture
  12. {
  13. public function testTestingAidsWithTestNowNotSet()
  14. {
  15. Carbon::setTestNow();
  16. $this->assertFalse(Carbon::hasTestNow());
  17. $this->assertNull(Carbon::getTestNow());
  18. }
  19. public function testTestingAidsWithTestNowSet()
  20. {
  21. $notNow = Carbon::yesterday();
  22. Carbon::setTestNow($notNow);
  23. $this->assertTrue(Carbon::hasTestNow());
  24. $this->assertSame($notNow, Carbon::getTestNow());
  25. }
  26. public function testConstructorWithTestValueSet()
  27. {
  28. $notNow = Carbon::yesterday();
  29. Carbon::setTestNow($notNow);
  30. $this->assertEquals($notNow, new Carbon());
  31. $this->assertEquals($notNow, new Carbon(null));
  32. $this->assertEquals($notNow, new Carbon(''));
  33. $this->assertEquals($notNow, new Carbon('now'));
  34. }
  35. public function testNowWithTestValueSet()
  36. {
  37. $notNow = Carbon::yesterday();
  38. Carbon::setTestNow($notNow);
  39. $this->assertEquals($notNow, Carbon::now());
  40. }
  41. public function testParseWithTestValueSet()
  42. {
  43. $notNow = Carbon::yesterday();
  44. Carbon::setTestNow($notNow);
  45. $this->assertEquals($notNow, Carbon::parse());
  46. $this->assertEquals($notNow, Carbon::parse(null));
  47. $this->assertEquals($notNow, Carbon::parse(''));
  48. $this->assertEquals($notNow, Carbon::parse('now'));
  49. }
  50. }