CopyTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\CarbonImmutable;
  12. use Carbon\CarbonImmutable as Carbon;
  13. use Tests\AbstractTestCase;
  14. class CopyTest extends AbstractTestCase
  15. {
  16. public function testCopy()
  17. {
  18. $dating = Carbon::now();
  19. $dating2 = $dating->copy();
  20. $this->assertNotSame($dating, $dating2);
  21. }
  22. public function testClone()
  23. {
  24. $dating = Carbon::now();
  25. $dating2 = $dating->clone();
  26. $this->assertNotSame($dating, $dating2);
  27. }
  28. public function testCopyEnsureTzIsCopied()
  29. {
  30. $dating = Carbon::createFromDate(2000, 1, 1, 'Europe/London');
  31. $dating2 = $dating->copy();
  32. $this->assertSame($dating->tzName, $dating2->tzName);
  33. $this->assertSame($dating->offset, $dating2->offset);
  34. }
  35. public function testCopyEnsureMicrosAreCopied()
  36. {
  37. $micro = 254687;
  38. $dating = Carbon::createFromFormat('Y-m-d H:i:s.u', '2014-02-01 03:45:27.'.$micro);
  39. $dating2 = $dating->copy();
  40. $this->assertSame($micro, $dating2->micro);
  41. }
  42. }