SetDateAndTimeFromTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of the Carbon package.
  5. *
  6. * (c) Brian Nesbitt <brian@nesbot.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Tests\Carbon;
  12. use Carbon\Carbon;
  13. use Tests\AbstractTestCase;
  14. class SetDateAndTimeFromTest extends AbstractTestCase
  15. {
  16. public function testSetDateFrom()
  17. {
  18. $source = Carbon::now();
  19. $target = $source->copy()
  20. ->addDays(rand(1, 6))
  21. ->addHours(rand(1, 23))
  22. ->addMinutes(rand(1, 59))
  23. ->addSeconds(rand(1, 59));
  24. $this->assertCarbon(
  25. $target->copy()->setDateFrom($source),
  26. $source->year,
  27. $source->month,
  28. $source->day,
  29. $target->hour,
  30. $target->minute,
  31. $target->second
  32. );
  33. }
  34. public function testSetTimeFrom()
  35. {
  36. $source = Carbon::now();
  37. $target = $source->copy()
  38. ->addDays(rand(1, 6))
  39. ->addHours(rand(1, 23))
  40. ->addMinutes(rand(1, 59))
  41. ->addSeconds(rand(1, 59));
  42. $this->assertCarbon(
  43. $target->copy()->setTimeFrom($source),
  44. $target->year,
  45. $target->month,
  46. $target->day,
  47. $source->hour,
  48. $source->minute,
  49. $source->second
  50. );
  51. }
  52. }