koel/tests/Feature/ProfileTest.php

57 lines
1.3 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;
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();
$this->hash = $this->mockIocDependency(Hasher::class);
}
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
$this->seeInDatabase('users', ['name' => 'Foo', 'email' => 'bar@baz.com']);
}
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);
$this->seeInDatabase('users', [
'id' => $user->id,
'name' => 'Foo',
'email' => 'bar@baz.com',
'password' => 'hashed',
]);
}
2016-05-30 05:50:59 +00:00
}