Bez popisu

CreateFromDateTest.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. }