-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Daanra\LaravelLetsEncrypt\Tests\Encoders; | ||
|
||
use Daanra\LaravelLetsEncrypt\Encoders\PemEncoder; | ||
use Daanra\LaravelLetsEncrypt\Tests\TestCase; | ||
|
||
class PemEncoderTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function test_encoder() | ||
{ | ||
$this->assertEquals("test test\n", PemEncoder::encode(' test test ')); | ||
$this->assertEquals("2test1\n", PemEncoder::encode('2test1')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
namespace Daanra\LaravelLetsEncrypt\Tests\Models; | ||
|
||
use Daanra\LaravelLetsEncrypt\Builders\LetsEncryptCertificateBuilder; | ||
use Daanra\LaravelLetsEncrypt\Collections\LetsEncryptCertificateCollection; | ||
use Daanra\LaravelLetsEncrypt\Facades\LetsEncrypt; | ||
use Daanra\LaravelLetsEncrypt\Jobs\RegisterAccount; | ||
use Daanra\LaravelLetsEncrypt\Jobs\RequestAuthorization; | ||
use Daanra\LaravelLetsEncrypt\Jobs\RequestCertificate; | ||
use Daanra\LaravelLetsEncrypt\Models\LetsEncryptCertificate; | ||
use Daanra\LaravelLetsEncrypt\Tests\TestCase; | ||
use Illuminate\Foundation\Bus\PendingDispatch; | ||
use Illuminate\Support\Facades\Queue; | ||
|
||
class LetsEncryptCertificateTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function test_correct_builder_instance() | ||
{ | ||
$builder = LetsEncryptCertificate::query(); | ||
|
||
$this->assertInstanceOf(LetsEncryptCertificateBuilder::class, $builder); | ||
} | ||
|
||
/** @test */ | ||
public function test_correct_collection_instance() | ||
{ | ||
$collection = LetsEncryptCertificate::all(); | ||
|
||
$this->assertInstanceOf(LetsEncryptCertificateCollection::class, $collection); | ||
} | ||
|
||
/** @test */ | ||
public function test_has_expired_attribute() | ||
{ | ||
$certificate = LetsEncryptCertificate::create([ | ||
'domain' => 'test1.test', | ||
]); | ||
|
||
$this->assertFalse( | ||
$certificate->has_expired, | ||
'Certificate has not been issued so it should not be marked as expired.' | ||
); | ||
|
||
$certificate->update([ | ||
'last_renewed_at' => now(), | ||
'created' => true, | ||
]); | ||
|
||
$this->assertFalse($certificate->has_expired, 'Certificate has just been issued so should not be considered as expired.'); | ||
|
||
$certificate->update([ | ||
'last_renewed_at' => now()->subMonths(4), | ||
]); | ||
|
||
$this->assertTrue($certificate->has_expired, 'Certificate has been issued 4 months ago so should be marked as expired.'); | ||
} | ||
|
||
/** @test */ | ||
public function test_renew() | ||
{ | ||
$certificate = LetsEncryptCertificate::create([ | ||
'domain' => 'test2.test', | ||
]); | ||
|
||
Queue::fake(); | ||
|
||
$pendingDispatch = $certificate->renew(); | ||
|
||
$this->assertInstanceOf(PendingDispatch::class, $pendingDispatch); | ||
|
||
// Jobs are only pushed after the pending dispatch leaves memory. | ||
$pendingDispatch->__destruct(); | ||
|
||
Queue::assertPushedWithChain(RegisterAccount::class, [ | ||
new RequestAuthorization($certificate), | ||
new RequestCertificate($certificate), | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function test_renew_now() | ||
{ | ||
$certificate = LetsEncryptCertificate::create([ | ||
'domain' => 'test3.test', | ||
]); | ||
|
||
Queue::fake(); | ||
|
||
LetsEncrypt::shouldReceive('renewNow') | ||
->once() | ||
->with($certificate) | ||
->andReturn($certificate); | ||
|
||
$instance = $certificate->renewNow(); | ||
|
||
Queue::assertNothingPushed(); | ||
|
||
$this->assertEquals($certificate, $instance); | ||
} | ||
} |