koel/tests/Feature/ProfileTest.php

55 lines
1.2 KiB
PHP
Raw Normal View History

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
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
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-12-22 23:01:49 +00:00
$this->hash = self::mock(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
{
$user = User::factory()->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 = User::factory()->create();
2018-08-22 19:46:36 +00:00
$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
}