2016-05-30 05:50:59 +00:00
|
|
|
<?php
|
|
|
|
|
2017-02-14 06:53:02 +00:00
|
|
|
namespace Tests\Feature;
|
|
|
|
|
2016-05-30 05:50:59 +00:00
|
|
|
use App\Models\User;
|
2018-08-22 19:46:36 +00:00
|
|
|
use Illuminate\Contracts\Hashing\Hasher;
|
2016-05-30 05:50:59 +00:00
|
|
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
2018-08-22 19:46:36 +00:00
|
|
|
use Mockery\MockInterface;
|
2016-05-30 05:50:59 +00:00
|
|
|
|
2017-08-05 16:56:11 +00:00
|
|
|
class ProfileTest extends TestCase
|
2016-05-30 05:50:59 +00:00
|
|
|
{
|
2017-08-05 16:56:11 +00:00
|
|
|
use WithoutMiddleware;
|
2016-05-30 05:50:59 +00:00
|
|
|
|
2018-08-22 19:46:36 +00:00
|
|
|
/** @var MockInterface */
|
|
|
|
private $hash;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->hash = $this->mockIocDependency(Hasher::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateProfileWithoutPassword()
|
2016-05-30 05:50:59 +00:00
|
|
|
{
|
2017-02-14 06:53:02 +00:00
|
|
|
$user = factory(User::class)->create();
|
2018-08-22 19:46:36 +00:00
|
|
|
|
|
|
|
$this->hash->shouldReceive('make')->never();
|
|
|
|
|
2017-02-14 06:53:02 +00:00
|
|
|
$this->putAsUser('api/me', ['name' => 'Foo', 'email' => 'bar@baz.com'], $user);
|
2016-05-30 05:50:59 +00:00
|
|
|
|
|
|
|
$this->seeInDatabase('users', ['name' => 'Foo', 'email' => 'bar@baz.com']);
|
|
|
|
}
|
2018-08-22 19:46:36 +00:00
|
|
|
|
|
|
|
public function testUpdateProfileWithPassword()
|
|
|
|
{
|
|
|
|
/** @var User $user */
|
|
|
|
$user = factory(User::class)->create();
|
|
|
|
|
|
|
|
$this->hash
|
|
|
|
->shouldReceive('make')
|
|
|
|
->once()
|
|
|
|
->with('qux')
|
|
|
|
->andReturn('hashed');
|
|
|
|
|
|
|
|
$this->putAsUser('api/me', [
|
|
|
|
'name' => 'Foo',
|
|
|
|
'email' => 'bar@baz.com',
|
|
|
|
'password' => 'qux',
|
|
|
|
], $user);
|
|
|
|
|
|
|
|
$this->seeInDatabase('users', [
|
|
|
|
'id' => $user->id,
|
|
|
|
'name' => 'Foo',
|
|
|
|
'email' => 'bar@baz.com',
|
|
|
|
'password' => 'hashed',
|
|
|
|
]);
|
|
|
|
}
|
2016-05-30 05:50:59 +00:00
|
|
|
}
|