Skip to content

Commit

Permalink
Merge pull request #3 from paulredmond/feature/assert-in-closure
Browse files Browse the repository at this point in the history
Add an Assertion to test Closure code
  • Loading branch information
rashidlaasri authored May 18, 2020
2 parents 967dbae + daedb8a commit e1ecbf3
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions tests/TravelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

class TravelTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();

Travel::back();
}

/** @test */
public function it_can_travel_to_a_datetime()
{
Expand All @@ -27,9 +34,19 @@ public function it_resets_to_current_datetime_if_callback_is_provided()
Travel::to('22-04-1994');
$this->assertEquals('22-04-1994', Carbon::now()->format('d-m-Y'));

Travel::to('22-04-1995', function () {
// Do something!
$calledCount = 0;

Travel::to('22-04-1995', function () use (&$calledCount) {
$this->assertEquals(
'22-04-1995',
Carbon::now()->format('d-m-Y'),
'Code inside the Closure should match the travel time.'
);

$calledCount++;
});

$this->assertEquals(1, $calledCount, 'Expect the closure to be called once.');
$this->assertNotEquals('22-04-1995', Carbon::now()->format('d-m-Y'));
}

Expand Down

0 comments on commit e1ecbf3

Please sign in to comment.