diff --git a/codeception.yml b/codeception.yml index 2f2c202..254b8e9 100644 --- a/codeception.yml +++ b/codeception.yml @@ -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 diff --git a/composer.json b/composer.json index 357fc3f..7a86777 100644 --- a/composer.json +++ b/composer.json @@ -70,6 +70,7 @@ ], "psr-4": { "Test\\Model\\": "tests/_support/Helper", + "Test\\Unit\\": "tests/Unit", "Test\\Traits\\": "tests/Traits" } }, diff --git a/phpunit.xml b/phpunit.xml index bf77072..e11c5f5 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -15,6 +15,14 @@ ./tests/unit/ + + + ./app + + ./app/configs + + + diff --git a/tests/unit/Repository/UserRepositoryTest.php b/tests/unit/Repository/UserRepositoryTest.php new file mode 100644 index 0000000..f75306f --- /dev/null +++ b/tests/unit/Repository/UserRepositoryTest.php @@ -0,0 +1,66 @@ +repository = new UserRepository(); + } + + + public function test_finding_by_id() + { + $user = factory(User::class)->create(['email' => 'steve@example.com']); + $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' => 'steve@example.com']); + $this->repository->findUserById($user->id + 10); + } + + public function test_finding_by_email() + { + $user = factory(User::class)->create(['email' => 'steve@example.com']); + $found = $this->repository->findUserByEmail($user->email); + $this->assertEquals($user->id, $found->id); + + $found = $this->repository->findUserByEmail('bob@example.com'); + $this->assertNull($found); + } + + public function test_email_address_unique_check() + { + $user = factory(User::class)->create(['email' => 'steve@example.com']); + $email = 'bob@example.com'; + $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')); + } +}