TestsCarbonSettersTest

The Simple Calendar Tests Carbon SettersTest class.

Defined (1)

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

/vendor/nesbot/carbon/tests/Carbon/SettersTest.php  
  1. class SettersTest extends AbstractTestCase 
  2. public function testYearSetter() 
  3. $d = Carbon::now(); 
  4. $d->year = 1995; 
  5. $this->assertSame(1995, $d->year); 
  6.  
  7. public function testMonthSetter() 
  8. $d = Carbon::now(); 
  9. $d->month = 3; 
  10. $this->assertSame(3, $d->month); 
  11.  
  12. public function testMonthSetterWithWrap() 
  13. $d = Carbon::now(); 
  14. $d->month = 13; 
  15. $this->assertSame(1, $d->month); 
  16.  
  17. public function testDaySetter() 
  18. $d = Carbon::now(); 
  19. $d->day = 2; 
  20. $this->assertSame(2, $d->day); 
  21.  
  22. public function testDaySetterWithWrap() 
  23. $d = Carbon::createFromDate(2012, 8, 5); 
  24. $d->day = 32; 
  25. $this->assertSame(1, $d->day); 
  26.  
  27. public function testHourSetter() 
  28. $d = Carbon::now(); 
  29. $d->hour = 2; 
  30. $this->assertSame(2, $d->hour); 
  31.  
  32. public function testHourSetterWithWrap() 
  33. $d = Carbon::now(); 
  34. $d->hour = 25; 
  35. $this->assertSame(1, $d->hour); 
  36.  
  37. public function testMinuteSetter() 
  38. $d = Carbon::now(); 
  39. $d->minute = 2; 
  40. $this->assertSame(2, $d->minute); 
  41.  
  42. public function testMinuteSetterWithWrap() 
  43. $d = Carbon::now(); 
  44. $d->minute = 65; 
  45. $this->assertSame(5, $d->minute); 
  46.  
  47. public function testSecondSetter() 
  48. $d = Carbon::now(); 
  49. $d->second = 2; 
  50. $this->assertSame(2, $d->second); 
  51.  
  52. public function testTimeSetter() 
  53. $d = Carbon::now(); 
  54. $d->setTime(1, 1, 1); 
  55. $this->assertSame(1, $d->second); 
  56. $d->setTime(1, 1); 
  57. $this->assertSame(0, $d->second); 
  58.  
  59. public function testTimeSetterWithChaining() 
  60. $d = Carbon::now(); 
  61. $d->setTime(2, 2, 2)->setTime(1, 1, 1); 
  62. $this->assertInstanceOf('Carbon\Carbon', $d); 
  63. $this->assertSame(1, $d->second); 
  64. $d->setTime(2, 2, 2)->setTime(1, 1); 
  65. $this->assertInstanceOf('Carbon\Carbon', $d); 
  66. $this->assertSame(0, $d->second); 
  67.  
  68. public function testTimeSetterWithZero() 
  69. $d = Carbon::now(); 
  70. $d->setTime(1, 1); 
  71. $this->assertSame(0, $d->second); 
  72.  
  73. public function testDateTimeSetter() 
  74. $d = Carbon::now(); 
  75. $d->setDateTime($d->year, $d->month, $d->day, 1, 1, 1); 
  76. $this->assertSame(1, $d->second); 
  77.  
  78. public function testDateTimeSetterWithZero() 
  79. $d = Carbon::now(); 
  80. $d->setDateTime($d->year, $d->month, $d->day, 1, 1); 
  81. $this->assertSame(0, $d->second); 
  82.  
  83. public function testDateTimeSetterWithChaining() 
  84. $d = Carbon::now(); 
  85. $d->setDateTime(2013, 9, 24, 17, 4, 29); 
  86. $this->assertInstanceOf('Carbon\Carbon', $d); 
  87. $d->setDateTime(2014, 10, 25, 18, 5, 30); 
  88. $this->assertInstanceOf('Carbon\Carbon', $d); 
  89. $this->assertCarbon($d, 2014, 10, 25, 18, 5, 30); 
  90.  
  91. public function testSecondSetterWithWrap() 
  92. $d = Carbon::now(); 
  93. $d->second = 65; 
  94. $this->assertSame(5, $d->second); 
  95.  
  96. public function testTimestampSetter() 
  97. $d = Carbon::now(); 
  98. $d->timestamp = 10; 
  99. $this->assertSame(10, $d->timestamp); 
  100.  
  101. $d->setTimestamp(11); 
  102. $this->assertSame(11, $d->timestamp); 
  103.  
  104. public function testSetTimezoneWithInvalidTimezone() 
  105. $this->setExpectedException('InvalidArgumentException'); 
  106. $d = Carbon::now(); 
  107. $d->setTimezone('sdf'); 
  108.  
  109. public function testTimezoneWithInvalidTimezone() 
  110. $d = Carbon::now(); 
  111.  
  112. try { 
  113. $d->timezone = 'sdf'; 
  114. $this->fail('InvalidArgumentException was not been raised.'); 
  115. } catch (InvalidArgumentException $expected) { 
  116.  
  117. try { 
  118. $d->timezone('sdf'); 
  119. $this->fail('InvalidArgumentException was not been raised.'); 
  120. } catch (InvalidArgumentException $expected) { 
  121. public function testTzWithInvalidTimezone() 
  122. $d = Carbon::now(); 
  123.  
  124. try { 
  125. $d->tz = 'sdf'; 
  126. $this->fail('InvalidArgumentException was not been raised.'); 
  127. } catch (InvalidArgumentException $expected) { 
  128.  
  129. try { 
  130. $d->tz('sdf'); 
  131. $this->fail('InvalidArgumentException was not been raised.'); 
  132. } catch (InvalidArgumentException $expected) { 
  133. public function testSetTimezoneUsingString() 
  134. $d = Carbon::now(); 
  135. $d->setTimezone('America/Toronto'); 
  136. $this->assertSame('America/Toronto', $d->tzName); 
  137.  
  138. public function testTimezoneUsingString() 
  139. $d = Carbon::now(); 
  140. $d->timezone = 'America/Toronto'; 
  141. $this->assertSame('America/Toronto', $d->tzName); 
  142.  
  143. $d->timezone('America/Vancouver'); 
  144. $this->assertSame('America/Vancouver', $d->tzName); 
  145.  
  146. public function testTzUsingString() 
  147. $d = Carbon::now(); 
  148. $d->tz = 'America/Toronto'; 
  149. $this->assertSame('America/Toronto', $d->tzName); 
  150.  
  151. $d->tz('America/Vancouver'); 
  152. $this->assertSame('America/Vancouver', $d->tzName); 
  153.  
  154. public function testSetTimezoneUsingDateTimeZone() 
  155. $d = Carbon::now(); 
  156. $d->setTimezone(new \DateTimeZone('America/Toronto')); 
  157. $this->assertSame('America/Toronto', $d->tzName); 
  158.  
  159. public function testTimezoneUsingDateTimeZone() 
  160. $d = Carbon::now(); 
  161. $d->timezone = new \DateTimeZone('America/Toronto'); 
  162. $this->assertSame('America/Toronto', $d->tzName); 
  163.  
  164. $d->timezone(new \DateTimeZone('America/Vancouver')); 
  165. $this->assertSame('America/Vancouver', $d->tzName); 
  166.  
  167. public function testTzUsingDateTimeZone() 
  168. $d = Carbon::now(); 
  169. $d->tz = new \DateTimeZone('America/Toronto'); 
  170. $this->assertSame('America/Toronto', $d->tzName); 
  171.  
  172. $d->tz(new \DateTimeZone('America/Vancouver')); 
  173. $this->assertSame('America/Vancouver', $d->tzName); 
  174.  
  175. public function testInvalidSetter() 
  176. $this->setExpectedException('InvalidArgumentException'); 
  177. $d = Carbon::now(); 
  178. $d->doesNotExit = 'bb'; 
  179.  
  180. public function testSetTimeFromTimeString() 
  181. $d = Carbon::now(); 
  182.  
  183. $d->setTimeFromTimeString('09:15:30'); 
  184.  
  185. $this->assertSame(9, $d->hour); 
  186. $this->assertSame(15, $d->minute); 
  187. $this->assertSame(30, $d->second);