FluidSettersTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 FluidSettersTest extends TestFixture
  12. {
  13. public function testFluidYearSetter()
  14. {
  15. $d = Carbon::now();
  16. $this->assertTrue($d->year(1995) instanceof Carbon);
  17. $this->assertSame(1995, $d->year);
  18. }
  19. public function testFluidMonthSetter()
  20. {
  21. $d = Carbon::now();
  22. $this->assertTrue($d->month(3) instanceof Carbon);
  23. $this->assertSame(3, $d->month);
  24. }
  25. public function testFluidMonthSetterWithWrap()
  26. {
  27. $d = Carbon::createFromDate(2012, 8, 21);
  28. $this->assertTrue($d->month(13) instanceof Carbon);
  29. $this->assertSame(1, $d->month);
  30. }
  31. public function testFluidDaySetter()
  32. {
  33. $d = Carbon::now();
  34. $this->assertTrue($d->day(2) instanceof Carbon);
  35. $this->assertSame(2, $d->day);
  36. }
  37. public function testFluidDaySetterWithWrap()
  38. {
  39. $d = Carbon::createFromDate(2000, 1, 1);
  40. $this->assertTrue($d->day(32) instanceof Carbon);
  41. $this->assertSame(1, $d->day);
  42. }
  43. public function testFluidSetDate()
  44. {
  45. $d = Carbon::createFromDate(2000, 1, 1);
  46. $this->assertTrue($d->setDate(1995, 13, 32) instanceof Carbon);
  47. $this->assertCarbon($d, 1996, 2, 1);
  48. }
  49. public function testFluidHourSetter()
  50. {
  51. $d = Carbon::now();
  52. $this->assertTrue($d->hour(2) instanceof Carbon);
  53. $this->assertSame(2, $d->hour);
  54. }
  55. public function testFluidHourSetterWithWrap()
  56. {
  57. $d = Carbon::now();
  58. $this->assertTrue($d->hour(25) instanceof Carbon);
  59. $this->assertSame(1, $d->hour);
  60. }
  61. public function testFluidMinuteSetter()
  62. {
  63. $d = Carbon::now();
  64. $this->assertTrue($d->minute(2) instanceof Carbon);
  65. $this->assertSame(2, $d->minute);
  66. }
  67. public function testFluidMinuteSetterWithWrap()
  68. {
  69. $d = Carbon::now();
  70. $this->assertTrue($d->minute(61) instanceof Carbon);
  71. $this->assertSame(1, $d->minute);
  72. }
  73. public function testFluidSecondSetter()
  74. {
  75. $d = Carbon::now();
  76. $this->assertTrue($d->second(2) instanceof Carbon);
  77. $this->assertSame(2, $d->second);
  78. }
  79. public function testFluidSecondSetterWithWrap()
  80. {
  81. $d = Carbon::now();
  82. $this->assertTrue($d->second(62) instanceof Carbon);
  83. $this->assertSame(2, $d->second);
  84. }
  85. public function testFluidSetTime()
  86. {
  87. $d = Carbon::createFromDate(2000, 1, 1);
  88. $this->assertTrue($d->setTime(25, 61, 61) instanceof Carbon);
  89. $this->assertCarbon($d, 2000, 1, 2, 2, 2, 1);
  90. }
  91. public function testFluidTimestampSetter()
  92. {
  93. $d = Carbon::now();
  94. $this->assertTrue($d->timestamp(10) instanceof Carbon);
  95. $this->assertSame(10, $d->timestamp);
  96. }
  97. }