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;
|
|
|
|
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
|
|
|
{
|
2018-08-22 19:46:36 +00:00
|
|
|
/** @var MockInterface */
|
|
|
|
private $hash;
|
|
|
|
|
2019-07-22 07:03:23 +00:00
|
|
|
public function setUp(): void
|
2018-08-22 19:46:36 +00:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2020-04-27 18:55:12 +00:00
|
|
|
$this->hash = static::mockIocDependency(Hasher::class);
|
2018-08-22 19:46:36 +00:00
|
|
|
}
|
|
|
|
|
2019-07-22 07:03:23 +00:00
|
|
|
public function testUpdateProfileWithoutPassword(): void
|
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
|
|
|
|
2020-09-06 18:21:39 +00:00
|
|
|
self::assertDatabaseHas('users', ['name' => 'Foo', 'email' => 'bar@baz.com']);
|
2016-05-30 05:50:59 +00:00
|
|
|
}
|
2018-08-22 19:46:36 +00:00
|
|
|
|
2019-07-22 07:03:23 +00:00
|
|
|
public function testUpdateProfileWithPassword(): void
|
2018-08-22 19:46:36 +00:00
|
|
|
{
|
|
|
|
/** @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);
|
|
|
|
|
2020-09-06 18:21:39 +00:00
|
|
|
self::assertDatabaseHas('users', [
|
2018-08-22 19:46:36 +00:00
|
|
|
'id' => $user->id,
|
|
|
|
'name' => 'Foo',
|
|
|
|
'email' => 'bar@baz.com',
|
|
|
|
'password' => 'hashed',
|
|
|
|
]);
|
|
|
|
}
|
2016-05-30 05:50:59 +00:00
|
|
|
}
|