test(model): add tests for "User" model

This commit is contained in:
Pig Fang 2017-12-27 18:40:16 +08:00
parent b1fa8c098b
commit 776a0a67ae
2 changed files with 32 additions and 2 deletions

View File

@ -78,7 +78,7 @@ class User extends Model
{
// compare directly if any responses is returned by event dispatcher
if ($result = static::getEncryptedPwdFromEvent($rawPasswd, $this)) {
return hash_equals($this->password, $result);
return hash_equals($this->password, $result); // @codeCoverageIgnore
}
return app('cipher')->verify($rawPasswd, $this->password, config('secure.salt'));
@ -136,7 +136,7 @@ class User extends Model
$responses = event(new EncryptUserPassword($new_passwd, $this));
if (isset($responses[0])) {
$this->password = $responses[0];
$this->password = $responses[0]; // @codeCoverageIgnore
} else {
$this->password = app('cipher')->hash($new_passwd, config('secure.salt'));
}

View File

@ -0,0 +1,30 @@
<?php
use App\Models\User;
use App\Services\Utils;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class UserTest extends TestCase
{
use DatabaseTransactions;
public function testSign()
{
$user = factory(User::class)->make([
'last_sign_at' => Utils::getTimeFormatted(time())
]);
$user->sign();
$this->assertFalse($user->sign());
}
public function testGetNickName()
{
$user = new User();
$this->assertEquals(
trans('general.unexistent-user'),
$user->getNickName()
);
}
}