Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Commit

Permalink
add user repository test
Browse files Browse the repository at this point in the history
  • Loading branch information
spekkionu committed Apr 16, 2017
1 parent 373405b commit 72536ff
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
7 changes: 7 additions & 0 deletions codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ settings:
memory_limit: 1024M
strict_xml: true
backup_globals: false
coverage:
enabled: false
remote: false
include:
- app/*
exclude:
- app/configs/*
extensions:
enabled:
- Codeception\Extension\RunFailed
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
],
"psr-4": {
"Test\\Model\\": "tests/_support/Helper",
"Test\\Unit\\": "tests/Unit",
"Test\\Traits\\": "tests/Traits"
}
},
Expand Down
8 changes: 8 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
<directory suffix=".php">./tests/unit/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
<exclude>
<directory>./app/configs</directory>
</exclude>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_NAME" value="Test"/>
Expand Down
66 changes: 66 additions & 0 deletions tests/unit/Repository/UserRepositoryTest.php
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'));
}
}

0 comments on commit 72536ff

Please sign in to comment.