TestsCarbonIntervalSettersTest

The Simple Calendar Tests CarbonInterval SettersTest class.

Defined (1)

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

/vendor/nesbot/carbon/tests/CarbonInterval/SettersTest.php  
  1. class SettersTest extends AbstractTestCase 
  2. public function testYearsSetter() 
  3. $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); 
  4. $d->years = 2; 
  5. $this->assertSame(2, $d->years); 
  6.  
  7. public function testMonthsSetter() 
  8. $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); 
  9. $d->months = 11; 
  10. $this->assertSame(11, $d->months); 
  11.  
  12. public function testWeeksSetter() 
  13. $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); 
  14. $d->weeks = 11; 
  15. $this->assertSame(11, $d->weeks); 
  16. $this->assertSame(7 * 11, $d->dayz); 
  17.  
  18. public function testDayzSetter() 
  19. $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); 
  20. $d->dayz = 11; 
  21. $this->assertSame(11, $d->dayz); 
  22. $this->assertSame(1, $d->weeks); 
  23. $this->assertSame(4, $d->dayzExcludeWeeks); 
  24.  
  25. public function testHoursSetter() 
  26. $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); 
  27. $d->hours = 12; 
  28. $this->assertSame(12, $d->hours); 
  29.  
  30. public function testMinutesSetter() 
  31. $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); 
  32. $d->minutes = 11; 
  33. $this->assertSame(11, $d->minutes); 
  34.  
  35. public function testSecondsSetter() 
  36. $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); 
  37. $d->seconds = 34; 
  38. $this->assertSame(34, $d->seconds); 
  39.  
  40. public function testFluentSetters() 
  41. $ci = CarbonInterval::years(4)->months(2)->dayz(5)->hours(3)->minute()->seconds(59); 
  42. $this->assertInstanceOfCarbonInterval($ci); 
  43. $this->assertCarbonInterval($ci, 4, 2, 5, 3, 1, 59); 
  44.  
  45. $ci = CarbonInterval::years(4)->months(2)->weeks(2)->hours(3)->minute()->seconds(59); 
  46. $this->assertInstanceOfCarbonInterval($ci); 
  47. $this->assertCarbonInterval($ci, 4, 2, 14, 3, 1, 59); 
  48.  
  49. public function testFluentSettersDaysOverwritesWeeks() 
  50. $ci = CarbonInterval::weeks(3)->days(5); 
  51. $this->assertCarbonInterval($ci, 0, 0, 5, 0, 0, 0); 
  52.  
  53. public function testFluentSettersWeeksOverwritesDays() 
  54. $ci = CarbonInterval::days(5)->weeks(3); 
  55. $this->assertCarbonInterval($ci, 0, 0, 3 * 7, 0, 0, 0); 
  56.  
  57. public function testFluentSettersWeeksAndDaysIsCumulative() 
  58. $ci = CarbonInterval::year(5)->weeksAndDays(2, 6); 
  59. $this->assertCarbonInterval($ci, 5, 0, 20, 0, 0, 0); 
  60. $this->assertSame(20, $ci->dayz); 
  61. $this->assertSame(2, $ci->weeks); 
  62. $this->assertSame(6, $ci->dayzExcludeWeeks);