diff --git a/src/EloquentIdentityStore.php b/src/EloquentIdentityStore.php new file mode 100644 index 0000000..abca964 --- /dev/null +++ b/src/EloquentIdentityStore.php @@ -0,0 +1,28 @@ +where('provider_user_id', $providerUser->id) + ->first(); + } + + public function flush($user, $provider) + { + OAuthIdentity::where('user_id', $user->getKey()) + ->where('provider', $provider) + ->delete(); + } + + public function store($identity) + { + $identity->save(); + } + + public function userExists($provider, $providerUser) + { + return (bool) $this->getByProvider($provider, $providerUser); + } +} diff --git a/src/IdentityStore.php b/src/IdentityStore.php index 0e27d91..414965a 100644 --- a/src/IdentityStore.php +++ b/src/IdentityStore.php @@ -1,28 +1,9 @@ where('provider_user_id', $providerUser->id) - ->first(); - } - - public function flush($user, $provider) - { - OAuthIdentity::where('user_id', $user->getKey()) - ->where('provider', $provider) - ->delete(); - } - - public function store($identity) - { - $identity->save(); - } - - public function userExists($provider, $providerUser) - { - return (bool) $this->getByProvider($provider, $providerUser); - } + public function getByProvider($provider, $providerUser); + public function flush($user, $provider); + public function store($identity); + public function userExists($provider, $providerUser); } diff --git a/tests/IdentityStoreTest.php b/tests/IdentityStoreTest.php index bc41ffc..952f48e 100644 --- a/tests/IdentityStoreTest.php +++ b/tests/IdentityStoreTest.php @@ -1,7 +1,7 @@ 'john.doe@example.com', 'avatar' => 'http://example.com/photos/john_doe.jpg', )); - $identities = new IdentityStore; + $identities = new EloquentIdentityStore; $identity = $identities->getByProvider('facebook', $details); $this->assertEquals(2, $identity->user_id); $this->assertEquals('facebook', $identity->provider); @@ -66,7 +66,7 @@ public function test_get_by_provider_when_no_match() 'email' => 'john.doe@example.com', 'avatar' => 'http://example.com/photos/john_doe.jpg', )); - $identities = new IdentityStore; + $identities = new EloquentIdentityStore; $identity = $identities->getByProvider('facebook', $details); $this->assertNull($identity); } @@ -88,7 +88,7 @@ public function test_flush() $this->assertEquals(1, OAuthIdentity::where('provider', 'facebook')->where('user_id', 2)->count()); - $identities = new IdentityStore; + $identities = new EloquentIdentityStore; $user = M::mock(); $user->shouldReceive('getKey')->andReturn(2); $identities->flush($user, 'facebook'); @@ -107,7 +107,7 @@ public function test_store() $this->assertEquals(0, OAuthIdentity::count()); - $identities = new IdentityStore; + $identities = new EloquentIdentityStore; $identities->store($identity); $this->assertEquals(1, OAuthIdentity::count()); @@ -129,7 +129,7 @@ public function test_user_exists_returns_true_when_user_exists() 'email' => 'john.doe@example.com', 'avatar' => 'http://example.com/photos/john_doe.jpg', )); - $identities = new IdentityStore; + $identities = new EloquentIdentityStore; $this->assertTrue($identities->userExists('facebook', $details)); } @@ -149,7 +149,7 @@ public function test_user_exists_returns_false_when_user_doesnt_exist() 'email' => 'john.doe@example.com', 'avatar' => 'http://example.com/photos/john_doe.jpg', )); - $identities = new IdentityStore; + $identities = new EloquentIdentityStore; $this->assertFalse($identities->userExists('facebook', $details)); } }