CreateFromDateTest.php 1.5 KB

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