TestsCarbonAddTest

The Simple Calendar Tests Carbon AddTest class.

Defined (1)

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

/vendor/nesbot/carbon/tests/Carbon/AddTest.php  
  1. class AddTest extends AbstractTestCase 
  2. public function testAddYearsPositive() 
  3. $this->assertSame(1976, Carbon::createFromDate(1975)->addYears(1)->year); 
  4.  
  5. public function testAddYearsZero() 
  6. $this->assertSame(1975, Carbon::createFromDate(1975)->addYears(0)->year); 
  7.  
  8. public function testAddYearsNegative() 
  9. $this->assertSame(1974, Carbon::createFromDate(1975)->addYears(-1)->year); 
  10.  
  11. public function testAddYear() 
  12. $this->assertSame(1976, Carbon::createFromDate(1975)->addYear()->year); 
  13.  
  14. public function testAddMonthsPositive() 
  15. $this->assertSame(1, Carbon::createFromDate(1975, 12)->addMonths(1)->month); 
  16.  
  17. public function testAddMonthsZero() 
  18. $this->assertSame(12, Carbon::createFromDate(1975, 12)->addMonths(0)->month); 
  19.  
  20. public function testAddMonthsNegative() 
  21. $this->assertSame(11, Carbon::createFromDate(1975, 12, 1)->addMonths(-1)->month); 
  22.  
  23. public function testAddMonth() 
  24. $this->assertSame(1, Carbon::createFromDate(1975, 12)->addMonth()->month); 
  25.  
  26. public function testAddMonthWithOverflow() 
  27. $this->assertSame(3, Carbon::createFromDate(2012, 1, 31)->addMonth()->month); 
  28.  
  29. public function testAddMonthsNoOverflowPositive() 
  30. $this->assertSame('2012-02-29', Carbon::createFromDate(2012, 1, 31)->addMonthNoOverflow()->toDateString()); 
  31. $this->assertSame('2012-03-31', Carbon::createFromDate(2012, 1, 31)->addMonthsNoOverflow(2)->toDateString()); 
  32. $this->assertSame('2012-03-29', Carbon::createFromDate(2012, 2, 29)->addMonthNoOverflow()->toDateString()); 
  33. $this->assertSame('2012-02-29', Carbon::createFromDate(2011, 12, 31)->addMonthsNoOverflow(2)->toDateString()); 
  34.  
  35. public function testAddMonthsNoOverflowZero() 
  36. $this->assertSame(12, Carbon::createFromDate(1975, 12)->addMonths(0)->month); 
  37.  
  38. public function testAddMonthsNoOverflowNegative() 
  39. $this->assertSame('2012-01-29', Carbon::createFromDate(2012, 2, 29)->addMonthsNoOverflow(-1)->toDateString()); 
  40. $this->assertSame('2012-01-31', Carbon::createFromDate(2012, 3, 31)->addMonthsNoOverflow(-2)->toDateString()); 
  41. $this->assertSame('2012-02-29', Carbon::createFromDate(2012, 3, 31)->addMonthsNoOverflow(-1)->toDateString()); 
  42. $this->assertSame('2011-12-31', Carbon::createFromDate(2012, 1, 31)->addMonthsNoOverflow(-1)->toDateString()); 
  43.  
  44. public function testAddDaysPositive() 
  45. $this->assertSame(1, Carbon::createFromDate(1975, 5, 31)->addDays(1)->day); 
  46.  
  47. public function testAddDaysZero() 
  48. $this->assertSame(31, Carbon::createFromDate(1975, 5, 31)->addDays(0)->day); 
  49.  
  50. public function testAddDaysNegative() 
  51. $this->assertSame(30, Carbon::createFromDate(1975, 5, 31)->addDays(-1)->day); 
  52.  
  53. public function testAddDay() 
  54. $this->assertSame(1, Carbon::createFromDate(1975, 5, 31)->addDay()->day); 
  55.  
  56. public function testAddWeekdaysPositive() 
  57. $this->assertSame(17, Carbon::createFromDate(2012, 1, 4)->addWeekdays(9)->day); 
  58.  
  59. public function testAddWeekdaysZero() 
  60. $this->assertSame(4, Carbon::createFromDate(2012, 1, 4)->addWeekdays(0)->day); 
  61.  
  62. public function testAddWeekdaysNegative() 
  63. $this->assertSame(18, Carbon::createFromDate(2012, 1, 31)->addWeekdays(-9)->day); 
  64.  
  65. public function testAddWeekday() 
  66. $this->assertSame(9, Carbon::createFromDate(2012, 1, 6)->addWeekday()->day); 
  67.  
  68. public function testAddWeekdayDuringWeekend() 
  69. $this->assertSame(9, Carbon::createFromDate(2012, 1, 7)->addWeekday()->day); 
  70.  
  71. public function testAddWeeksPositive() 
  72. $this->assertSame(28, Carbon::createFromDate(1975, 5, 21)->addWeeks(1)->day); 
  73.  
  74. public function testAddWeeksZero() 
  75. $this->assertSame(21, Carbon::createFromDate(1975, 5, 21)->addWeeks(0)->day); 
  76.  
  77. public function testAddWeeksNegative() 
  78. $this->assertSame(14, Carbon::createFromDate(1975, 5, 21)->addWeeks(-1)->day); 
  79.  
  80. public function testAddWeek() 
  81. $this->assertSame(28, Carbon::createFromDate(1975, 5, 21)->addWeek()->day); 
  82.  
  83. public function testAddHoursPositive() 
  84. $this->assertSame(1, Carbon::createFromTime(0)->addHours(1)->hour); 
  85.  
  86. public function testAddHoursZero() 
  87. $this->assertSame(0, Carbon::createFromTime(0)->addHours(0)->hour); 
  88.  
  89. public function testAddHoursNegative() 
  90. $this->assertSame(23, Carbon::createFromTime(0)->addHours(-1)->hour); 
  91.  
  92. public function testAddHour() 
  93. $this->assertSame(1, Carbon::createFromTime(0)->addHour()->hour); 
  94.  
  95. public function testAddMinutesPositive() 
  96. $this->assertSame(1, Carbon::createFromTime(0, 0)->addMinutes(1)->minute); 
  97.  
  98. public function testAddMinutesZero() 
  99. $this->assertSame(0, Carbon::createFromTime(0, 0)->addMinutes(0)->minute); 
  100.  
  101. public function testAddMinutesNegative() 
  102. $this->assertSame(59, Carbon::createFromTime(0, 0)->addMinutes(-1)->minute); 
  103.  
  104. public function testAddMinute() 
  105. $this->assertSame(1, Carbon::createFromTime(0, 0)->addMinute()->minute); 
  106.  
  107. public function testAddSecondsPositive() 
  108. $this->assertSame(1, Carbon::createFromTime(0, 0, 0)->addSeconds(1)->second); 
  109.  
  110. public function testAddSecondsZero() 
  111. $this->assertSame(0, Carbon::createFromTime(0, 0, 0)->addSeconds(0)->second); 
  112.  
  113. public function testAddSecondsNegative() 
  114. $this->assertSame(59, Carbon::createFromTime(0, 0, 0)->addSeconds(-1)->second); 
  115.  
  116. public function testAddSecond() 
  117. $this->assertSame(1, Carbon::createFromTime(0, 0, 0)->addSecond()->second); 
  118.  
  119. /***** Test non plural methods with non default args *****/ 
  120.  
  121. public function testAddYearPassingArg() 
  122. $this->assertSame(1977, Carbon::createFromDate(1975)->addYear(2)->year); 
  123.  
  124. public function testAddMonthPassingArg() 
  125. $this->assertSame(7, Carbon::createFromDate(1975, 5, 1)->addMonth(2)->month); 
  126.  
  127. public function testAddMonthNoOverflowPassingArg() 
  128. $dt = Carbon::createFromDate(2010, 12, 31)->addMonthNoOverflow(2); 
  129. $this->assertSame(2011, $dt->year); 
  130. $this->assertSame(2, $dt->month); 
  131. $this->assertSame(28, $dt->day); 
  132.  
  133. public function testAddDayPassingArg() 
  134. $this->assertSame(12, Carbon::createFromDate(1975, 5, 10)->addDay(2)->day); 
  135.  
  136. public function testAddHourPassingArg() 
  137. $this->assertSame(2, Carbon::createFromTime(0)->addHour(2)->hour); 
  138.  
  139. public function testAddMinutePassingArg() 
  140. $this->assertSame(2, Carbon::createFromTime(0)->addMinute(2)->minute); 
  141.  
  142. public function testAddSecondPassingArg() 
  143. $this->assertSame(2, Carbon::createFromTime(0)->addSecond(2)->second);