Skip to content

Commit

Permalink
feat: add Laravel v6-v10 support
Browse files Browse the repository at this point in the history
  • Loading branch information
t1k3 committed Jan 5, 2024
1 parent c2115bb commit 1e74608
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 51 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
vendor
/build
composer.lock
.idea
.idea
.phpunit.cache
17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@
"prefer-stable" : true,
"minimum-stability": "dev",
"require": {
"illuminate/support": "~5",
"illuminate/database": "~5",
"illuminate/notifications": "~5",
"illuminate/bus": "~5"
"illuminate/support": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0",
"illuminate/database": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0",
"illuminate/notifications": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0",
"illuminate/bus": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0"
},
"require-dev": {
"mockery/mockery": "^1.1",
"orchestra/testbench": "~3.0",
"mockery/mockery": "^1.1|^1.6",
"orchestra/testbench": "^3.0|^4.0|^5.0|^6.0|^7.0|^8.0",
"phpmd/phpmd": "^2.6",
"phpunit/phpunit": "^7.3",
"themsaid/laravel-mail-preview": "^2.0"
"phpunit/phpunit": "^7.3|^10.0",
"themsaid/laravel-mail-preview": "^2.0|^6.0",
"laravel/legacy-factories": "~1.3.2"
},
"autoload": {
"classmap": [
Expand Down
68 changes: 32 additions & 36 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Frameworks Laravel">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
<exclude>
<directory suffix=".php">src/Frameworks/Laravel/_publish</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="build/logs/html"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-text" target="build/logs/coverage.txt"/>
<log type="coverage-html" target="build/logs/coverage"/>
</logging>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="preview"/>
</php>
</phpunit>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/logs/html"/>
<text outputFile="build/logs/coverage.txt"/>
</report>
</coverage>
<testsuites>
<testsuite name="Frameworks Laravel">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-html" target="build/logs/coverage"/>
</logging>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="preview"/>
</php>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory suffix=".php">src/Frameworks/Laravel/_publish</directory>
</exclude>
</source>
</phpunit>
3 changes: 2 additions & 1 deletion src/Frameworks/Laravel/EmailVerificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Stylers\EmailVerification\Frameworks\Laravel\Models\EmailVerificationRequest;
use Stylers\EmailVerification\Frameworks\Laravel\Notifications\EmailVerificationRequestCreate;
use Stylers\EmailVerification\NotifiableInterface;
use Illuminate\Support\Str;

class EmailVerificationService implements EmailVerificationServiceInterface
{
Expand Down Expand Up @@ -38,7 +39,7 @@ public function createRequest(string $email, string $type = null): EmailVerifica
return $this->requestDAO->create([
'email' => $email,
'type' => $type,
'token' => uniqid() . str_random(),
'token' => uniqid() . Str::random(),
]);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Frameworks/Laravel/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Orchestra\Testbench\TestCase;
use Stylers\EmailVerification\Frameworks\Laravel\ServiceProvider as EmailVerificationServiceProvider;
use Themsaid\MailPreview\MailPreviewServiceProvider;
use Spatie\MailPreview\MailPreviewServiceProvider;

abstract class BaseTestCase extends TestCase
{
use DatabaseTransactions;

protected $consoleOutput;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->setUpFactory();
$this->setUpDatabase();
}

public function tearDown()
public function tearDown(): void
{
$this->consoleOutput = '';
$this->artisan('migrate:reset');
Expand Down
8 changes: 8 additions & 0 deletions tests/Frameworks/Laravel/EmailVerificationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ function(VerificationSuccess $e) use ($verificationRequest) {
*/
public function it_cannot_verify_non_existing()
{
$this->expectException(\InvalidArgumentException::class);

Event::fake();
$verificationService = new EmailVerificationService();
try {
Expand All @@ -65,6 +67,8 @@ public function it_cannot_verify_non_existing()
*/
public function it_cannot_verify_expired()
{
$this->expectException(\Stylers\EmailVerification\Exceptions\ExpiredVerificationException::class);

Event::fake();
/** @var EmailVerifiableInterface $verifiableUser */
$verifiableUser = factory(User::class)->create();
Expand Down Expand Up @@ -92,6 +96,8 @@ public function it_cannot_verify_expired()
*/
public function it_cannot_verify_already_verified()
{
$this->expectException(\Stylers\EmailVerification\Exceptions\AlreadyVerifiedException::class);

Event::fake();
/** @var EmailVerifiableInterface $verifiableUser */
$verifiableUser = factory(User::class)->create();
Expand Down Expand Up @@ -128,6 +134,8 @@ public function it_can_create_email_verification_request()
*/
public function it_cannot_create_email_verification_request_that_already_verified()
{
$this->expectException(\Stylers\EmailVerification\Exceptions\AlreadyVerifiedException::class);

$verifiableUser = factory(User::class)->create();
$verificationService = new EmailVerificationService();
$verificationRequest = $verificationService->createRequest($verifiableUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class EmailVerificationRequestTest extends BaseTestCase
/** @var EmailVerificationRequest */
private $verificationRequest;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->verificationRequest = factory(EmailVerificationRequest::class)->make([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function it_can_notify()
function (EmailVerificationRequestCreate $notification) use ($verifiableUser, $expectedUrl, $expectedName) {
$mailData = $notification->toMail($verifiableUser)->toArray();

$this->assertContains($expectedUrl, $mailData['actionUrl']);
$this->assertEquals($expectedUrl, $mailData['actionUrl']);

$expectedArray = $notification->toArray($verifiableUser);
$this->assertEquals($expectedUrl, $expectedArray['verification_url']);
Expand Down

0 comments on commit 1e74608

Please sign in to comment.