CreateFromDateTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 DateTimeZone;
  14. use Tests\AbstractTestCase;
  15. class CreateFromDateTest extends AbstractTestCase
  16. {
  17. public function testCreateFromDateWithDefaults()
  18. {
  19. $d = Carbon::createFromDate();
  20. $this->assertSame($d->timestamp, Carbon::create(null, null, null, null, null, null)->timestamp);
  21. }
  22. public function testCreateFromDate()
  23. {
  24. $d = Carbon::createFromDate(1975, 5, 21);
  25. $this->assertCarbon($d, 1975, 5, 21);
  26. }
  27. public function testCreateFromDateWithYear()
  28. {
  29. $d = Carbon::createFromDate(1975);
  30. $this->assertSame(1975, $d->year);
  31. }
  32. public function testCreateFromDateWithMonth()
  33. {
  34. $d = Carbon::createFromDate(null, 5);
  35. $this->assertSame(5, $d->month);
  36. }
  37. public function testCreateFromDateWithDay()
  38. {
  39. $d = Carbon::createFromDate(null, null, 21);
  40. $this->assertSame(21, $d->day);
  41. }
  42. public function testCreateFromDateWithTimezone()
  43. {
  44. $d = Carbon::createFromDate(1975, 5, 21, 'Europe/London');
  45. $this->assertCarbon($d, 1975, 5, 21);
  46. $this->assertSame('Europe/London', $d->tzName);
  47. }
  48. public function testCreateFromDateWithDateTimeZone()
  49. {
  50. $d = Carbon::createFromDate(1975, 5, 21, new DateTimeZone('Europe/London'));
  51. $this->assertCarbon($d, 1975, 5, 21);
  52. $this->assertSame('Europe/London', $d->tzName);
  53. }
  54. }