WormholeTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Illuminate\Tests\Foundation\Bootstrap\Testing;
  3. use Carbon\CarbonImmutable;
  4. use Illuminate\Foundation\Testing\Wormhole;
  5. use Illuminate\Support\Facades\Date;
  6. use PHPUnit\Framework\TestCase;
  7. class WormholeTest extends TestCase
  8. {
  9. public function testCanTravelBackToPresent()
  10. {
  11. // Preserve the timelines we want to compare the reality with...
  12. $present = now();
  13. $future = now()->addDays(10);
  14. // Travel in time...
  15. (new Wormhole(10))->days();
  16. // Assert we are now in the future...
  17. $this->assertEquals($future->format('Y-m-d'), now()->format('Y-m-d'));
  18. // Assert we can go back to the present...
  19. $this->assertEquals($present->format('Y-m-d'), Wormhole::back()->format('Y-m-d'));
  20. }
  21. public function testCarbonImmutableCompatibility()
  22. {
  23. // Tell the Date Factory to use CarbonImmutable...
  24. Date::use(CarbonImmutable::class);
  25. // Record what time it is in 10 days...
  26. $present = now();
  27. $future = $present->addDays(10);
  28. // Travel in time...
  29. (new Wormhole(10))->days();
  30. // Assert that the present time didn't get mutated...
  31. $this->assertNotEquals($future->format('Y-m-d'), $present->format('Y-m-d'));
  32. // Assert the time travel was successful...
  33. $this->assertEquals($future->format('Y-m-d'), now()->format('Y-m-d'));
  34. // Restore the default Date Factory...
  35. Date::useDefault();
  36. }
  37. }