koel/tests/Feature/ProfileTest.php

55 lines
1.2 KiB
PHP
Raw Normal View History

2016-05-30 13:50:59 +08:00
<?php
2017-02-14 14:53:02 +08:00
namespace Tests\Feature;
2016-05-30 13:50:59 +08:00
use App\Models\User;
2018-08-22 21:46:36 +02:00
use Illuminate\Contracts\Hashing\Hasher;
2016-05-30 13:50:59 +08:00
2017-08-05 17:56:11 +01:00
class ProfileTest extends TestCase
2016-05-30 13:50:59 +08:00
{
2018-08-22 21:46:36 +02:00
private $hash;
2019-07-22 09:03:23 +02:00
public function setUp(): void
2018-08-22 21:46:36 +02:00
{
parent::setUp();
2020-12-23 00:01:49 +01:00
$this->hash = self::mock(Hasher::class);
2018-08-22 21:46:36 +02:00
}
2019-07-22 09:03:23 +02:00
public function testUpdateProfileWithoutPassword(): void
2016-05-30 13:50:59 +08:00
{
$user = User::factory()->create();
2018-08-22 21:46:36 +02:00
$this->hash->shouldReceive('make')->never();
2017-02-14 14:53:02 +08:00
$this->putAsUser('api/me', ['name' => 'Foo', 'email' => 'bar@baz.com'], $user);
2016-05-30 13:50:59 +08:00
2020-09-06 20:21:39 +02:00
self::assertDatabaseHas('users', ['name' => 'Foo', 'email' => 'bar@baz.com']);
2016-05-30 13:50:59 +08:00
}
2018-08-22 21:46:36 +02:00
2019-07-22 09:03:23 +02:00
public function testUpdateProfileWithPassword(): void
2018-08-22 21:46:36 +02:00
{
/** @var User $user */
$user = User::factory()->create();
2018-08-22 21:46:36 +02: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 20:21:39 +02:00
self::assertDatabaseHas('users', [
2018-08-22 21:46:36 +02:00
'id' => $user->id,
'name' => 'Foo',
'email' => 'bar@baz.com',
'password' => 'hashed',
]);
}
2016-05-30 13:50:59 +08:00
}