Skip to content

Commit

Permalink
Use mock pest helper
Browse files Browse the repository at this point in the history
  • Loading branch information
joelbutcher committed Apr 2, 2024
1 parent c9715d8 commit 993b03b
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 34 deletions.
10 changes: 5 additions & 5 deletions tests/Feature/CreateAccountOnFirstLoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use Laravel\Socialite\Facades\Socialite;
use Laravel\Socialite\Two\GithubProvider;
use Laravel\Socialite\Two\User as SocialiteUser;
use Mockery;

use function Pest\Laravel\get;
use function Pest\Laravel\mock;

uses(RefreshDatabase::class);

Expand All @@ -36,7 +36,7 @@
->setRefreshToken('refresh-token')
->setExpiresIn(3600);

$provider = Mockery::mock(GithubProvider::class);
$provider = mock(GithubProvider::class);
$provider->shouldReceive('user')->once()->andReturn($user);

session()->put('socialstream.previous_url', route('login'));
Expand Down Expand Up @@ -77,7 +77,7 @@
->setRefreshToken('refresh-token')
->setExpiresIn(3600);

$provider = Mockery::mock(GithubProvider::class);
$provider = mock(GithubProvider::class);
$provider->shouldReceive('user')->once()->andReturn($user);

session()->put('socialstream.previous_url', '/random');
Expand Down Expand Up @@ -113,7 +113,7 @@
->setRefreshToken('refresh-token')
->setExpiresIn(3600);

$provider = Mockery::mock(GithubProvider::class);
$provider = mock(GithubProvider::class);
$provider->shouldReceive('user')->once()->andReturn($user);

session()->put('socialstream.previous_url', route('login'));
Expand Down Expand Up @@ -144,7 +144,7 @@
->setRefreshToken('refresh-token')
->setExpiresIn(3600);

$provider = Mockery::mock(GithubProvider::class);
$provider = mock(GithubProvider::class);
$provider->shouldReceive('user')->once()->andReturn($user);

session()->put('socialstream.previous_url', '/random');
Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/GenerateMissingEmailsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

namespace JoelButcher\Socialstream\Tests\Feature;

use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Config;
use JoelButcher\Socialstream\Features;
use JoelButcher\Socialstream\Tests\Fixtures\User;
use Laravel\Socialite\Facades\Socialite;
use Laravel\Socialite\Two\GithubProvider;
use Laravel\Socialite\Two\User as SocialiteUser;
use Mockery;

use function Pest\Laravel\get;
use function Pest\Laravel\mock;

uses(RefreshDatabase::class);

Expand All @@ -33,7 +33,7 @@
->setRefreshToken('refresh-token')
->setExpiresIn(3600);

$provider = Mockery::mock(GithubProvider::class);
$provider = mock(GithubProvider::class);
$provider->shouldReceive('user')->once()->andReturn($user);

Socialite::shouldReceive('driver')->once()->with('github')->andReturn($provider);
Expand Down
12 changes: 6 additions & 6 deletions tests/Feature/LoginOnRegistrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace JoelButcher\Socialstream\Tests\Feature;

use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Hash;
use JoelButcher\Socialstream\Features;
use JoelButcher\Socialstream\Tests\Fixtures\User;
use Laravel\Socialite\Facades\Socialite;
use Laravel\Socialite\Two\GithubProvider;
use Laravel\Socialite\Two\User as SocialiteUser;
use Mockery;

use function Pest\Laravel\get;
use function Pest\Laravel\mock;

uses(RefreshDatabase::class);

Expand Down Expand Up @@ -44,7 +44,7 @@
->setRefreshToken('refresh-token')
->setExpiresIn(3600);

$provider = Mockery::mock(GithubProvider::class);
$provider = mock(GithubProvider::class);
$provider->shouldReceive('user')->once()->andReturn($user);

Socialite::shouldReceive('driver')->once()->with('github')->andReturn($provider);
Expand Down Expand Up @@ -85,7 +85,7 @@
->setRefreshToken('refresh-token')
->setExpiresIn(3600);

$provider = Mockery::mock(GithubProvider::class);
$provider = mock(GithubProvider::class);
$provider->shouldReceive('user')->once()->andReturn($user);

Socialite::shouldReceive('driver')->once()->with('github')->andReturn($provider);
Expand Down Expand Up @@ -127,7 +127,7 @@
->setRefreshToken('refresh-token')
->setExpiresIn(3600);

$provider = Mockery::mock(GithubProvider::class);
$provider = mock(GithubProvider::class);
$provider->shouldReceive('user')->once()->andReturn($user);

Socialite::shouldReceive('driver')->once()->with('github')->andReturn($provider);
Expand All @@ -138,4 +138,4 @@

$this->assertGuest();
$response->assertSessionHasErrors();
});
});
10 changes: 5 additions & 5 deletions tests/Feature/RedirectTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

use App\Models\User;
use App\Models\ConnectedAccount;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Route;
use Illuminate\Validation\ValidationException;
use JoelButcher\Socialstream\Tests\Fixtures\User;
use Laravel\Socialite\Facades\Socialite;
use Laravel\Socialite\Two\GithubProvider;
use Laravel\Socialite\Two\User as SocialiteUser;
Expand Down Expand Up @@ -48,7 +48,7 @@
->setRefreshToken('refresh-token')
->setExpiresIn(3600);

$provider = Mockery::mock(GithubProvider::class);
$provider = mock(GithubProvider::class);
$provider->shouldReceive('user')->once()->andReturn($user);
Socialite::shouldReceive('driver')->once()->with('github')->andReturn($provider);

Expand All @@ -75,7 +75,7 @@
->setRefreshToken('refresh-token')
->setExpiresIn(3600);

$provider = Mockery::mock(GithubProvider::class);
$provider = mock(GithubProvider::class);
$provider->shouldReceive('user')->once()->andReturn($user);
Socialite::shouldReceive('driver')->once()->with('github')->andReturn($provider);

Expand Down Expand Up @@ -104,7 +104,7 @@
->setRefreshToken('refresh-token')
->setExpiresIn(3600);

$provider = Mockery::mock(GithubProvider::class);
$provider = mock(GithubProvider::class);
$provider->shouldReceive('user')->once()->andReturn($user);
Socialite::shouldReceive('driver')->once()->with('github')->andReturn($provider);

Expand Down Expand Up @@ -140,7 +140,7 @@
->setRefreshToken('refresh-token')
->setExpiresIn(3600);

$provider = Mockery::mock(GithubProvider::class);
$provider = mock(GithubProvider::class);
$provider->shouldReceive('user')->once()->andReturn($user);
Socialite::shouldReceive('driver')->once()->with('github')->andReturn($provider);

Expand Down
7 changes: 3 additions & 4 deletions tests/Feature/RouteCachingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
namespace JoelButcher\Socialstream\Tests\Feature;

use App\Providers\RouteServiceProvider;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Socialite\Facades\Socialite;
use Laravel\Socialite\Two\GithubProvider;
use Laravel\Socialite\Two\User as SocialiteUser;
use Mockery;

use function Illuminate\Filesystem\join_paths;
use function Pest\Laravel\get;
use function Pest\Laravel\mock;
use function Pest\Laravel\post;

uses(RefreshDatabase::class);
Expand Down Expand Up @@ -48,7 +47,7 @@
->setRefreshToken('refresh-token')
->setExpiresIn(3600);

$provider = Mockery::mock(GithubProvider::class);
$provider = mock(GithubProvider::class);
$provider->shouldReceive('user')->once()->andReturn($user);

Socialite::shouldReceive('driver')->once()->with('github')->andReturn($provider);
Expand All @@ -72,7 +71,7 @@
->setRefreshToken('refresh-token')
->setExpiresIn(3600);

$provider = Mockery::mock(GithubProvider::class);
$provider = mock(GithubProvider::class);
$provider->shouldReceive('user')->once()->andReturn($user);

Socialite::shouldReceive('driver')->once()->with('github')->andReturn($provider);
Expand Down
10 changes: 5 additions & 5 deletions tests/Feature/SocialstreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace JoelButcher\Socialstream\Tests\Feature;

use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Config;
Expand All @@ -11,13 +10,14 @@
use Illuminate\Support\Str;
use JoelButcher\Socialstream\Contracts\GeneratesProviderRedirect;
use JoelButcher\Socialstream\Socialstream;
use JoelButcher\Socialstream\Tests\Fixtures\User;
use Laravel\Socialite\Facades\Socialite;
use Laravel\Socialite\Two\GithubProvider;
use Laravel\Socialite\Two\User as SocialiteUser;
use Mockery;
use Symfony\Component\HttpFoundation\RedirectResponse;

use function Pest\Laravel\get;
use function Pest\Laravel\mock;

uses(RefreshDatabase::class);

Expand Down Expand Up @@ -84,7 +84,7 @@ public function generate(string $provider): RedirectResponse
->setRefreshToken('refresh-token')
->setExpiresIn(3600);

$provider = Mockery::mock(GithubProvider::class);
$provider = mock(GithubProvider::class);
$provider->shouldReceive('user')->once()->andReturn($user);

Socialite::shouldReceive('driver')->once()->with('github')->andReturn($provider);
Expand Down Expand Up @@ -138,7 +138,7 @@ public function generate(string $provider): RedirectResponse
->setRefreshToken('refresh-token')
->setExpiresIn(3600);

$provider = Mockery::mock(GithubProvider::class);
$provider = mock(GithubProvider::class);
$provider->shouldReceive('user')->once()->andReturn($user);

Socialite::shouldReceive('driver')->once()->with('github')->andReturn($provider);
Expand Down Expand Up @@ -174,7 +174,7 @@ public function generate(string $provider): RedirectResponse
->setRefreshToken('refresh-token')
->setExpiresIn(3600);

$provider = Mockery::mock(GithubProvider::class);
$provider = mock(GithubProvider::class);
$provider->shouldReceive('user')->once()->andReturn($user);

Socialite::shouldReceive('driver')->once()->with('github')->andReturn($provider);
Expand Down
24 changes: 24 additions & 0 deletions tests/Fixtures/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace JoelButcher\Socialstream\Tests\Fixtures;

use App\Models\User as BaseUser;
use JoelButcher\Socialstream\HasConnectedAccounts;
use Laravel\Jetstream\HasProfilePhoto;
use Laravel\Jetstream\HasTeams;
use Laravel\Sanctum\HasApiTokens;

class User extends BaseUser
{
use HasApiTokens;
use HasConnectedAccounts;
use HasTeams;
use HasProfilePhoto;

/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [];
}
11 changes: 5 additions & 6 deletions tests/OrchestraTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use JoelButcher\Socialstream\SocialstreamServiceProvider;
use JoelButcher\Socialstream\Tests\Fixtures\User;
use Laravel\Jetstream\Jetstream;
use Laravel\Jetstream\JetstreamServiceProvider;
use Laravel\Socialite\SocialiteServiceProvider;
use Orchestra\Testbench\Concerns\WithWorkbench;
Expand All @@ -13,12 +15,7 @@ abstract class OrchestraTestCase extends BaseTestCase
{
use LazilyRefreshDatabase, WithWorkbench;

protected function setUp(): void
{
parent::setUp();
}

protected function getEnvironmentSetUp($app): void
protected function defineEnvironment($app): void
{
$app['migrator']->path(__DIR__.'/../database/migrations/2022_12_21_000000_make_password_nullable_on_users_table.php');
$app['migrator']->path(__DIR__.'/../database/migrations/2020_12_22_000000_create_connected_accounts_table.php');
Expand All @@ -37,6 +34,8 @@ protected function getEnvironmentSetUp($app): void
'client_secret' => 'github-client-secret',
'redirect' => 'https://example.test/oauth/github/callback',
]);

Jetstream::useUserModel(User::class);
}

protected function getPackageProviders($app): array
Expand Down

0 comments on commit 993b03b

Please sign in to comment.