This repository has been archived by the owner on Apr 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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
4 changed files
with
82 additions
and
0 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
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,66 @@ | ||
<?php | ||
|
||
namespace Test\Unit\Repository; | ||
|
||
use App\Model\User; | ||
use App\Repository\UserRepository; | ||
use Test\Traits\RunsMigrations; | ||
|
||
class UserRepositoryTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
use RunsMigrations; | ||
|
||
/** | ||
* @var UserRepository | ||
*/ | ||
private $repository; | ||
|
||
public function setUp() | ||
{ | ||
$this->repository = new UserRepository(); | ||
} | ||
|
||
|
||
public function test_finding_by_id() | ||
{ | ||
$user = factory(User::class)->create(['email' => '[email protected]']); | ||
$found = $this->repository->findUserById($user->id); | ||
$this->assertEquals($user->id, $found->id); | ||
} | ||
|
||
/** | ||
* @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException | ||
*/ | ||
public function test_failing_to_find_by_id() | ||
{ | ||
$user = factory(User::class)->create(['email' => '[email protected]']); | ||
$this->repository->findUserById($user->id + 10); | ||
} | ||
|
||
public function test_finding_by_email() | ||
{ | ||
$user = factory(User::class)->create(['email' => '[email protected]']); | ||
$found = $this->repository->findUserByEmail($user->email); | ||
$this->assertEquals($user->id, $found->id); | ||
|
||
$found = $this->repository->findUserByEmail('[email protected]'); | ||
$this->assertNull($found); | ||
} | ||
|
||
public function test_email_address_unique_check() | ||
{ | ||
$user = factory(User::class)->create(['email' => '[email protected]']); | ||
$email = '[email protected]'; | ||
$this->assertFalse($this->repository->emailAddressExists($email)); | ||
$this->assertTrue($this->repository->emailAddressExists($user->email)); | ||
$this->assertFalse($this->repository->emailAddressExists($user->email, $user->id)); | ||
} | ||
|
||
public function test_password_verification() | ||
{ | ||
$user = factory(User::class)->create(['password' => password_hash('password', PASSWORD_DEFAULT)]); | ||
$this->assertTrue($this->repository->passwordHashMatches($user->id, 'password')); | ||
$this->assertFalse($this->repository->passwordHashMatches($user->id, 'not-password')); | ||
$this->assertFalse($this->repository->passwordHashMatches($user->id + 10, 'password')); | ||
} | ||
} |