TestsCarbonTestingAidsTest

The Simple Calendar Tests Carbon TestingAidsTest class.

Defined (1)

The class is defined in the following location(s).

/vendor/nesbot/carbon/tests/Carbon/TestingAidsTest.php  
  1. class TestingAidsTest extends AbstractTestCase 
  2. public function testTestingAidsWithTestNowNotSet() 
  3. Carbon::setTestNow(); 
  4.  
  5. $this->assertFalse(Carbon::hasTestNow()); 
  6. $this->assertNull(Carbon::getTestNow()); 
  7.  
  8. public function testTestingAidsWithTestNowSet() 
  9. $notNow = Carbon::yesterday(); 
  10. Carbon::setTestNow($notNow); 
  11.  
  12. $this->assertTrue(Carbon::hasTestNow()); 
  13. $this->assertSame($notNow, Carbon::getTestNow()); 
  14.  
  15. public function testConstructorWithTestValueSet() 
  16. $notNow = Carbon::yesterday(); 
  17. Carbon::setTestNow($notNow); 
  18.  
  19. $this->assertEquals($notNow, new Carbon()); 
  20. $this->assertEquals($notNow, new Carbon(null)); 
  21. $this->assertEquals($notNow, new Carbon('')); 
  22. $this->assertEquals($notNow, new Carbon('now')); 
  23.  
  24. public function testNowWithTestValueSet() 
  25. $notNow = Carbon::yesterday(); 
  26. Carbon::setTestNow($notNow); 
  27.  
  28. $this->assertEquals($notNow, Carbon::now()); 
  29.  
  30. public function testParseWithTestValueSet() 
  31. $notNow = Carbon::yesterday(); 
  32. Carbon::setTestNow($notNow); 
  33.  
  34. $this->assertEquals($notNow, Carbon::parse()); 
  35. $this->assertEquals($notNow, Carbon::parse(null)); 
  36. $this->assertEquals($notNow, Carbon::parse('')); 
  37. $this->assertEquals($notNow, Carbon::parse('now')); 
  38.  
  39. public function testParseRelativeWithTestValueSet() 
  40. $notNow = Carbon::parse('2013-09-01 05:15:05'); 
  41. Carbon::setTestNow($notNow); 
  42.  
  43. $this->assertSame('2013-09-01 05:10:05', Carbon::parse('5 minutes ago')->toDateTimeString()); 
  44.  
  45. $this->assertSame('2013-08-25 05:15:05', Carbon::parse('1 week ago')->toDateTimeString()); 
  46.  
  47. $this->assertSame('2013-09-02 00:00:00', Carbon::parse('tomorrow')->toDateTimeString()); 
  48. $this->assertSame('2013-08-31 00:00:00', Carbon::parse('yesterday')->toDateTimeString()); 
  49.  
  50. $this->assertSame('2013-09-02 05:15:05', Carbon::parse('+1 day')->toDateTimeString()); 
  51. $this->assertSame('2013-08-31 05:15:05', Carbon::parse('-1 day')->toDateTimeString()); 
  52.  
  53. $this->assertSame('2013-09-02 00:00:00', Carbon::parse('next monday')->toDateTimeString()); 
  54. $this->assertSame('2013-09-03 00:00:00', Carbon::parse('next tuesday')->toDateTimeString()); 
  55. $this->assertSame('2013-09-04 00:00:00', Carbon::parse('next wednesday')->toDateTimeString()); 
  56. $this->assertSame('2013-09-05 00:00:00', Carbon::parse('next thursday')->toDateTimeString()); 
  57. $this->assertSame('2013-09-06 00:00:00', Carbon::parse('next friday')->toDateTimeString()); 
  58. $this->assertSame('2013-09-07 00:00:00', Carbon::parse('next saturday')->toDateTimeString()); 
  59. $this->assertSame('2013-09-08 00:00:00', Carbon::parse('next sunday')->toDateTimeString()); 
  60.  
  61. $this->assertSame('2013-08-26 00:00:00', Carbon::parse('last monday')->toDateTimeString()); 
  62. $this->assertSame('2013-08-27 00:00:00', Carbon::parse('last tuesday')->toDateTimeString()); 
  63. $this->assertSame('2013-08-28 00:00:00', Carbon::parse('last wednesday')->toDateTimeString()); 
  64. $this->assertSame('2013-08-29 00:00:00', Carbon::parse('last thursday')->toDateTimeString()); 
  65. $this->assertSame('2013-08-30 00:00:00', Carbon::parse('last friday')->toDateTimeString()); 
  66. $this->assertSame('2013-08-31 00:00:00', Carbon::parse('last saturday')->toDateTimeString()); 
  67. $this->assertSame('2013-08-25 00:00:00', Carbon::parse('last sunday')->toDateTimeString()); 
  68.  
  69. $this->assertSame('2013-09-02 00:00:00', Carbon::parse('this monday')->toDateTimeString()); 
  70. $this->assertSame('2013-09-03 00:00:00', Carbon::parse('this tuesday')->toDateTimeString()); 
  71. $this->assertSame('2013-09-04 00:00:00', Carbon::parse('this wednesday')->toDateTimeString()); 
  72. $this->assertSame('2013-09-05 00:00:00', Carbon::parse('this thursday')->toDateTimeString()); 
  73. $this->assertSame('2013-09-06 00:00:00', Carbon::parse('this friday')->toDateTimeString()); 
  74. $this->assertSame('2013-09-07 00:00:00', Carbon::parse('this saturday')->toDateTimeString()); 
  75. $this->assertSame('2013-09-01 00:00:00', Carbon::parse('this sunday')->toDateTimeString()); 
  76.  
  77. $this->assertSame('2013-10-01 05:15:05', Carbon::parse('first day of next month')->toDateTimeString()); 
  78. $this->assertSame('2013-09-30 05:15:05', Carbon::parse('last day of this month')->toDateTimeString()); 
  79.  
  80. public function testParseRelativeWithMinusSignsInDate() 
  81. $notNow = Carbon::parse('2013-09-01 05:15:05'); 
  82. Carbon::setTestNow($notNow); 
  83.  
  84. $this->assertSame('2000-01-03 00:00:00', Carbon::parse('2000-1-3')->toDateTimeString()); 
  85. $this->assertSame('2000-10-10 00:00:00', Carbon::parse('2000-10-10')->toDateTimeString()); 
  86.  
  87. public function testTimeZoneWithTestValueSet() 
  88. $notNow = Carbon::parse('2013-07-01 12:00:00', 'America/New_York'); 
  89. Carbon::setTestNow($notNow); 
  90.  
  91. $this->assertSame('2013-07-01T12:00:00-0400', Carbon::parse('now')->toIso8601String()); 
  92. $this->assertSame('2013-07-01T11:00:00-0500', Carbon::parse('now', 'America/Mexico_City')->toIso8601String()); 
  93. $this->assertSame('2013-07-01T09:00:00-0700', Carbon::parse('now', 'America/Vancouver')->toIso8601String());