Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
victore13 authored and github-actions[bot] committed Sep 17, 2024
1 parent 6ca9531 commit 802fbd8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 28 deletions.
1 change: 0 additions & 1 deletion database/migrations/modify_user_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Raiolanetworks\OAuth\Tests\Models\TestUser;

return new class extends Migration
{
Expand Down
5 changes: 2 additions & 3 deletions src/Commands/OAuthCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use function Laravel\Prompts\info;
use function Laravel\Prompts\select;
use function Laravel\Prompts\text;
use function Orchestra\Testbench\package_path;

class OAuthCommand extends Command
{
Expand Down Expand Up @@ -134,8 +133,8 @@ protected function modelNameValidation(string $value): ?string
$class = '\\' . Str::ucfirst(Str::replace('/', '\\', $value));
$authenticatableClass = 'Illuminate\Contracts\Auth\Authenticatable';

if(app()->environment() === 'testing') {
$path = 'Tests/Models/TestUser.php';
if (app()->environment() === 'testing') {
$path = 'Tests/Models/TestUser.php';
}

return match (true) {
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/OAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class OAuthController extends Controller
{
private OAuthService $provider;

public function __construct(OAuthService $provider = null)
public function __construct(?OAuthService $provider = null)
{
$this->provider = $provider ?? app(OAuthService::class);
}
Expand Down Expand Up @@ -76,7 +76,7 @@ public function callback(): RedirectResponse
]);

$callback = $this->provider->getResourceOwner($accessToken)->toArray();
$user = $this->updateOrCreateUser($callback, $accessToken);
$user = $this->updateOrCreateUser($callback, $accessToken);

EventsOAuthTokenUpdated::dispatch($user, $callback['groups']);
Session::remove('oauth2-state');
Expand Down
24 changes: 12 additions & 12 deletions tests/Feature/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@
$mockOAuthService->shouldReceive('getResourceOwner')
->andReturn(Mockery::mock([
'toArray' => [
'id' => 1,
'name' => 'user',
'email' => '[email protected]',
'id' => 1,
'name' => 'user',
'email' => '[email protected]',
'groups' => ['admin'],
'sub' => '123456abc',
'sub' => '123456abc',
],
]));

Expand All @@ -159,30 +159,30 @@
// $mockUser->oauth_refresh_token = 'valid_refresh_token';
// $mockUser->oauth_token_expires_at = Carbon::now()->subHour()->timestamp;
$mockUser = TestUser::factory(state: [
'oauth_token_expires_at' => Carbon::now()->subHour()
'oauth_token_expires_at' => Carbon::now()->subHour(),
])->create();

Auth::shouldReceive('guard')
->with(config('oauth.guard_name'))
->andReturn(Mockery::mock(Guard::class, ['check' => true, 'user' => $mockUser]));

$newOAuthToken = 'new_oauth_token';
$newOAuthToken = 'new_oauth_token';
$newRefreshToken = 'new_refresh_token';
$newExpiredDate = Carbon::now()->addHour()->timestamp;
$newExpiredDate = Carbon::now()->addHour()->timestamp;

$mockAccessToken = Mockery::mock(AccessToken::class);
$mockAccessToken->shouldReceive('getToken')->andReturn($newOAuthToken);
$mockAccessToken->shouldReceive('getRefreshToken')->andReturn($newRefreshToken);
$mockAccessToken->shouldReceive('getExpires')->andReturn($newExpiredDate);

$mockOAuthService->shouldReceive('getAccessToken')
->with('refresh_token', ['refresh_token' => 'oauth_refresh_token'])
->andReturn($mockAccessToken);
->with('refresh_token', ['refresh_token' => 'oauth_refresh_token'])
->andReturn($mockAccessToken);

$mockOAuthService->shouldReceive('getResourceOwner')
->andReturn(Mockery::mock(['toArray' => [
'groups' => ['admin'],
]]));
->andReturn(Mockery::mock(['toArray' => [
'groups' => ['admin'],
]]));

$this->instance(OAuthService::class, $mockOAuthService);

Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Raiolanetworks\OAuth\Tests;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Config;
use Orchestra\Testbench\TestCase as Orchestra;
Expand Down Expand Up @@ -42,7 +41,7 @@ public function getEnvironmentSetUp($app)
config()->set('database.default', 'testing');
config()->set('database.connections.testing', [
'driver' => 'sqlite',
'database' => ':memory:'
'database' => ':memory:',
]);
}
}
16 changes: 8 additions & 8 deletions tests/database/factories/TestUserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ class TestUserFactory extends Factory
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'type' => 'admin',
'password' => static::$password ??= Hash::make('password'),
'oauth_id' => 'oauth_id',
'oauth_token' => 'oauth_token',
'oauth_refresh_token' => 'oauth_refresh_token',
'oauth_token_expires_at' => Carbon::now()->addHours(2)
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'type' => 'admin',
'password' => static::$password ??= Hash::make('password'),
'oauth_id' => 'oauth_id',
'oauth_token' => 'oauth_token',
'oauth_refresh_token' => 'oauth_refresh_token',
'oauth_token_expires_at' => Carbon::now()->addHours(2),
];
}
}

0 comments on commit 802fbd8

Please sign in to comment.