generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 42
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
10 changed files
with
273 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ build | |
composer.lock | ||
coverage | ||
docs | ||
phpunit.xml | ||
phpstan.neon | ||
testbench.yaml | ||
vendor | ||
|
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
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,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Test"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<source> | ||
<include> | ||
<directory>src</directory> | ||
</include> | ||
</source> | ||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
<env name="BCRYPT_ROUNDS" value="4"/> | ||
<env name="CACHE_DRIVER" value="array"/> | ||
<env name="DB_DATABASE" value="testing"/> | ||
<env name="MAIL_MAILER" value="array"/> | ||
<env name="QUEUE_CONNECTION" value="sync"/> | ||
<env name="SESSION_DRIVER" value="array"/> | ||
<env name="TELESCOPE_ENABLED" value="false"/> | ||
</php> | ||
</phpunit> |
This file was deleted.
Oops, something went wrong.
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,33 @@ | ||
<?php | ||
|
||
namespace DutchCodingCompany\FilamentSocialite\Tests\Fixtures; | ||
|
||
use Laravel\Socialite\Contracts\User; | ||
|
||
class TestSocialiteUser implements User | ||
{ | ||
public function getId() | ||
{ | ||
return 'test-socialite-user-id'; | ||
} | ||
|
||
public function getNickname() | ||
{ | ||
return 'test-socialite-user-nickname'; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'test-socialite-user-name'; | ||
} | ||
|
||
public function getEmail() | ||
{ | ||
return '[email protected]'; | ||
} | ||
|
||
public function getAvatar() | ||
{ | ||
return null; | ||
} | ||
} |
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,43 @@ | ||
<?php | ||
|
||
namespace DutchCodingCompany\FilamentSocialite\Tests\Fixtures; | ||
|
||
use Illuminate\Contracts\Auth\Authenticatable; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class TestUser extends Model implements Authenticatable | ||
{ | ||
protected $table = 'users'; | ||
|
||
protected $guarded = []; | ||
|
||
public function getAuthIdentifierName() | ||
{ | ||
// | ||
} | ||
|
||
public function getAuthIdentifier() | ||
{ | ||
// | ||
} | ||
|
||
public function getAuthPassword() | ||
{ | ||
// | ||
} | ||
|
||
public function getRememberToken() | ||
{ | ||
// | ||
} | ||
|
||
public function setRememberToken($value) | ||
{ | ||
// | ||
} | ||
|
||
public function getRememberTokenName() | ||
{ | ||
// | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
return new class extends Migration { | ||
public function up() | ||
{ | ||
Schema::create('socialite_users', function (Blueprint $table) { | ||
$table->id(); | ||
|
||
$table->foreignId('user_id'); | ||
$table->string('provider'); | ||
$table->string('provider_id'); | ||
|
||
$table->timestamps(); | ||
|
||
$table->unique([ | ||
'provider', | ||
'provider_id', | ||
]); | ||
}); | ||
} | ||
|
||
public function down() | ||
{ | ||
Schema::dropIfExists('socialite_users'); | ||
} | ||
}; |
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,58 @@ | ||
<?php | ||
|
||
namespace DutchCodingCompany\FilamentSocialite\Tests; | ||
|
||
use DutchCodingCompany\FilamentSocialite\Tests\Fixtures\TestSocialiteUser; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Facades\Crypt; | ||
use Laravel\Socialite\Contracts\Provider; | ||
use Laravel\Socialite\Facades\Socialite; | ||
use Mockery; | ||
|
||
class SocialiteLoginTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
public function testLogin(): void | ||
{ | ||
$response = $this | ||
->getJson("/$this->panelName/oauth/github") | ||
->assertStatus(302); | ||
|
||
$state = session()->get('state'); | ||
|
||
$location = $response->headers->get('location'); | ||
|
||
parse_str($location, $urlQuery); | ||
|
||
// Test if the correct state is sent to the endpoint in the "Location" header. | ||
$this->assertEquals($state, $urlQuery['state']); | ||
|
||
// Assert decrypting of the state gives the correct panel name. | ||
$this->assertEquals($this->panelName, Crypt::decrypt($state)); | ||
|
||
Socialite::shouldReceive('driver') | ||
->with('github') | ||
->andReturn( | ||
Mockery::mock(Provider::class) | ||
->shouldReceive('user') | ||
->andReturn(new TestSocialiteUser()) | ||
->getMock() | ||
); | ||
|
||
// Fake oauth response. | ||
$response = $this | ||
->getJson("/oauth/callback/github?state=$state") | ||
->assertStatus(302); | ||
|
||
$this->assertDatabaseHas('socialite_users', [ | ||
'provider' => 'github', | ||
'provider_id' => 'test-socialite-user-id', | ||
]); | ||
|
||
$this->assertDatabaseHas('users', [ | ||
'name' => 'test-socialite-user-name', | ||
'email' => '[email protected]', | ||
]); | ||
} | ||
} |
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