Skip to content

Commit

Permalink
Merge pull request #21 from eXolnet/feature/laravel11-support-revived
Browse files Browse the repository at this point in the history
feat: support Laravel 11
  • Loading branch information
exolnet-bot authored Oct 3, 2024
2 parents f206ba5 + 813e9b2 commit 441cfe5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [8.1, 8.2, 8.3]
laravel: [10.*]
php: [8.2, 8.3]
laravel: [10.*, 11.*]
dependency-version: [prefer-lowest, prefer-stable]
exclude:
- php: 8.1
laravel: 11.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
}
],
"require": {
"php": "^8.1",
"laravel/framework": "^10.0"
"php": "8.2.*|8.3.*",
"laravel/framework": "^10.0|^11.0"
},
"require-dev": {
"mockery/mockery": "^1.4",
"phpunit/phpunit": "^9.3.3",
"phpunit/phpunit": "^11.3",
"squizlabs/php_codesniffer": "^3.6"
},
"autoload": {
Expand Down
22 changes: 8 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
>
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<source>
<include>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</include>
</source>
</phpunit>
24 changes: 12 additions & 12 deletions tests/Auth/AuthEmailBrokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@ public function tearDown(): void
public function testIfUserIsNotFoundErrorRedirectIsReturnedWhenSending()
{
$mocks = $this->getMocks();
$broker = $this->getMockBuilder(EmailBroker::class)->setMethods(['getUser', 'makeErrorRedirect'])->setConstructorArgs(array_values($mocks))->getMock();
$broker = $this->getMockBuilder(EmailBroker::class)->onlyMethods(['getUser'])->setConstructorArgs(array_values($mocks))->getMock();

$this->assertEquals(EmailBroker::INVALID_USER, $broker->sendConfirmationLink(null, 'email'));
}

public function testIfUserIsNotFoundErrorRedirectIsReturnedWhenResending()
{
$mocks = $this->getMocks();
$broker = $this->getMockBuilder(EmailBroker::class)->setMethods(['getUser', 'makeErrorRedirect'])->setConstructorArgs(array_values($mocks))->getMock();
$broker->expects($this->once())->method('getUser')->will($this->returnValue(null));
$broker = $this->getMockBuilder(EmailBroker::class)->onlyMethods(['getUser'])->setConstructorArgs(array_values($mocks))->getMock();
$broker->expects($this->once())->method('getUser')->willReturn(null);

$this->assertEquals(EmailBroker::INVALID_USER, $broker->resendConfirmationLink(['credentials']));
}

public function testIfUserIsNotFoundErrorRedirectIsReturnedWhenUserIsAlreadyConfirmed()
{
$mocks = $this->getMocks();
$broker = $this->getMockBuilder(EmailBroker::class)->setMethods(['getUser', 'makeErrorRedirect'])->setConstructorArgs(array_values($mocks))->getMock();
$broker = $this->getMockBuilder(EmailBroker::class)->onlyMethods(['getUser'])->setConstructorArgs(array_values($mocks))->getMock();
$user = m::mock(CanConfirmEmail::class);
$broker->expects($this->once())->method('getUser')->will($this->returnValue($user));
$broker->expects($this->once())->method('getUser')->willReturn($user);
$user->shouldReceive('getConfirmedAtForEmailConfirmation')->once()->andReturn(Carbon::now());

$this->assertEquals(EmailBroker::INVALID_USER, $broker->resendConfirmationLink(['credentials']));
Expand All @@ -54,7 +54,7 @@ public function testIfTokenIsRecentlyCreated()
{
$mocks = $this->getMocks();
$mocks['tokens'] = m::mock(TestTokenRepositoryInterface::class);
$broker = $this->getMockBuilder('Exolnet\Auth\Emails\EmailBroker')->setMethods()->setConstructorArgs(array_values($mocks))->getMock();
$broker = $this->getMockBuilder('Exolnet\Auth\Emails\EmailBroker')->onlyMethods([])->setConstructorArgs(array_values($mocks))->getMock();
$mocks['tokens']->shouldReceive('recentlyCreatedToken')->once()->with($user = m::mock('Exolnet\Contracts\Auth\CanConfirmEmail'))->andReturn(true);
$user->shouldReceive('sendEmailConfirmationNotification')->with('token');

Expand Down Expand Up @@ -83,7 +83,7 @@ public function testUserIsRetrievedByCredentials()
public function testBrokerCreatesTokenAndRedirectsWithoutErrorWhenSending()
{
$mocks = $this->getMocks();
$broker = $this->getMockBuilder(EmailBroker::class)->setMethods()->setConstructorArgs(array_values($mocks))->getMock();
$broker = $this->getMockBuilder(EmailBroker::class)->onlyMethods([])->setConstructorArgs(array_values($mocks))->getMock();
$user = m::mock(CanConfirmEmail::class);
$mocks['tokens']->shouldReceive('create')->once()->with($user, 'email')->andReturn('token');
$user->shouldReceive('sendEmailConfirmationNotification')->with('email', 'token');
Expand All @@ -94,7 +94,7 @@ public function testBrokerCreatesTokenAndRedirectsWithoutErrorWhenSending()
public function testBrokerCreatesTokenAndRedirectsWithoutErrorWhenResending()
{
$mocks = $this->getMocks();
$broker = $this->getMockBuilder(EmailBroker::class)->setMethods()->setConstructorArgs(array_values($mocks))->getMock();
$broker = $this->getMockBuilder(EmailBroker::class)->onlyMethods([])->setConstructorArgs(array_values($mocks))->getMock();
$mocks['users']->shouldReceive('retrieveByCredentials')->once()->with(['foo'])->andReturn($user = m::mock(CanConfirmEmail::class));
$mocks['tokens']->shouldReceive('create')->once()->with($user, 'email')->andReturn('token');
$user->shouldReceive('getConfirmedAtForEmailConfirmation')->once()->andReturn(null);
Expand All @@ -116,7 +116,7 @@ public function testRedirectIsReturnedByConfirmWhenUserCredentialsInvalid()
public function testRedirectReturnedByRemindWhenRecordDoesntExistInTable()
{
$creds = ['token' => 'token'];
$broker = $this->getMockBuilder(EmailBroker::class)->setMethods()->setConstructorArgs(array_values($mocks = $this->getMocks()))->getMock();
$broker = $this->getMockBuilder(EmailBroker::class)->onlyMethods([])->setConstructorArgs(array_values($mocks = $this->getMocks()))->getMock();
$mocks['users']->shouldReceive('retrieveByCredentials')->once()->with(Arr::except($creds, ['token']))->andReturn($user = m::mock(CanConfirmEmail::class));
$mocks['tokens']->shouldReceive('exists')->with($user, 'token')->andReturn(false);

Expand All @@ -127,7 +127,7 @@ public function testRedirectReturnedByRemindWhenRecordDoesntExistInTable()
public function testIfEmailConfirmedRedirectIsReturned()
{
$creds = ['token' => 'token'];
$broker = $this->getMockBuilder(EmailBroker::class)->setMethods()->setConstructorArgs(array_values($mocks = $this->getMocks()))->getMock();
$broker = $this->getMockBuilder(EmailBroker::class)->onlyMethods([])->setConstructorArgs(array_values($mocks = $this->getMocks()))->getMock();
$mocks['users']->shouldReceive('retrieveByCredentials')->once()->with(Arr::except($creds, ['token']))->andReturn($user = m::mock(CanConfirmEmail::class));
$mocks['tokens']->shouldReceive('exists')->with($user, 'token')->andReturn(true);
$mocks['tokens']->shouldReceive('find')->once()->with($user)->andReturn(['email' => 'email']);
Expand All @@ -140,8 +140,8 @@ public function testIfEmailConfirmedRedirectIsReturned()
public function testConfirmRemovesRecordOnReminderTableAndCallsCallback()
{
unset($_SERVER['__email.confirm.test']);
$broker = $this->getMockBuilder(EmailBroker::class)->setMethods(['validateConfirm'])->setConstructorArgs(array_values($mocks = $this->getMocks()))->getMock();
$broker->expects($this->once())->method('validateConfirm')->will($this->returnValue($user = m::mock(CanConfirmEmail::class)));
$broker = $this->getMockBuilder(EmailBroker::class)->onlyMethods(['validateConfirm'])->setConstructorArgs(array_values($mocks = $this->getMocks()))->getMock();
$broker->expects($this->once())->method('validateConfirm')->willReturn($user = m::mock(CanConfirmEmail::class));
$mocks['tokens']->shouldReceive('find')->once()->with($user)->andReturn(['email' => 'email']);
$mocks['tokens']->shouldReceive('delete')->once()->with($user);
$callback = function ($user, $email) {
Expand Down

0 comments on commit 441cfe5

Please sign in to comment.