Skip to content

Commit

Permalink
Merge pull request #49 from mikemand/feature/other-dates
Browse files Browse the repository at this point in the history
Allow all kinds of dates to be used for expiresOn
  • Loading branch information
clarkeash authored Feb 4, 2020
2 parents 79bd56d + 71d5648 commit a7b2e56
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor
/.idea
coverage.xml
.phpunit.result.cache
4 changes: 2 additions & 2 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ public function for(string $email)
}

/**
* @param \Carbon\Carbon $date
* @param \DateTimeInterface $date
*
* @return $this
*/
public function expiresOn(Carbon $date)
public function expiresOn(\DateTimeInterface $date)
{
$this->expiry = $date;

Expand Down
49 changes: 46 additions & 3 deletions tests/Feature/GenerateInvitesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Clarkeash\Doorman\Test\Feature;

use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Clarkeash\Doorman\Exceptions\DuplicateException;
use Clarkeash\Doorman\Models\Invite;
use Doorman;
Expand Down Expand Up @@ -63,7 +64,7 @@ public function it_can_have_multiple_uses()
*/
public function it_can_have_an_expiry_date()
{
$date = Carbon::now( 'UTC')->endOfDay();
$date = Carbon::now('UTC')->endOfDay();

Doorman::generate()->expiresOn($date)->make();

Expand All @@ -72,6 +73,48 @@ public function it_can_have_an_expiry_date()
Assert::assertLessThan(1, $date->floatDiffInSeconds($invite->valid_until));
}

/**
* @test
*/
public function it_can_accept_immutable_date()
{
$date = CarbonImmutable::now('UTC')->endOfDay();

Doorman::generate()->expiresOn($date)->make();

$invite = Invite::first();

Assert::assertLessThan(1, $date->floatDiffInSeconds($invite->valid_until));
}

/**
* @test
*/
public function it_can_accept_vanilla_date()
{
$date = (new \DateTime)->setTime(23, 59, 59);

Doorman::generate()->expiresOn($date)->make();

$invite = Invite::first();

Assert::assertLessThan(1, $date->diff($invite->valid_until)->format('%s'));
}

/**
* @test
*/
public function it_can_accept_vanilla_immutable_date()
{
$date = (new \DateTimeImmutable)->setTime(23, 59, 59);

Doorman::generate()->expiresOn($date)->make();

$invite = Invite::first();

Assert::assertLessThan(1, $date->diff($invite->valid_until)->format('%s'));
}

/**
* @test
*/
Expand Down Expand Up @@ -120,8 +163,8 @@ public function only_one_invite_per_email_can_be_generated_2()
}

/**
* @test
*/
* @test
*/
public function generated_codes_should_always_be_uppercase()
{
Doorman::generate()->make();
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/CleanupCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Clarkeash\Doorman\Test\Unit;

use Carbon\Carbon;
use Clarkeash\Doorman\Test\TestCase;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\DatabaseMigrations;
Expand Down

0 comments on commit a7b2e56

Please sign in to comment.