Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Adds an ability for the Wormhole class to take us back to the present. #35261

Merged
merged 2 commits into from Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -44,8 +44,6 @@ public function travelTo(DateTimeInterface $date, $callback = null)
*/
public function travelBack()
{
Carbon::setTestNow();

return Carbon::now();
return Wormhole::back();
}
}
12 changes: 12 additions & 0 deletions src/Illuminate/Foundation/Testing/Wormhole.php
Expand Up @@ -115,6 +115,18 @@ public function years($callback = null)
return $this->handleCallback($callback);
}

/**
* Travel back to the current time.
*
* @return \DateTimeInterface
*/
public static function back()
{
Carbon::setTestNow();

return Carbon::now();
}

/**
* Handle the given optional execution callback.
*
Expand Down
25 changes: 25 additions & 0 deletions tests/Foundation/Testing/WormholeTest.php
@@ -0,0 +1,25 @@
<?php

namespace Illuminate\Tests\Foundation\Testing;

use Illuminate\Foundation\Testing\Wormhole;
use PHPUnit\Framework\TestCase;

class WormholeTest extends TestCase
{
public function testCanTravelBackToPresent()
{
// Preserve the timelines we want to compare the reality with..
$present = now();
$future = now()->addDays(10);

// Travel in time..
(new Wormhole(10))->days();

// Assert we are now in the future..
$this->assertEquals($future->format('Y-m-d'), now()->format('Y-m-d'));

// Assert we can go back to the present..
$this->assertEquals($present->format('Y-m-d'), Wormhole::back()->format('Y-m-d'));
}
}