Skip to content

Instantly share code, notes, and snippets.

@deleugpn
Created April 8, 2018 16:19
Show Gist options
  • Save deleugpn/0fc627bf0f63fd151496b017b1955835 to your computer and use it in GitHub Desktop.
Save deleugpn/0fc627bf0f63fd151496b017b1955835 to your computer and use it in GitHub Desktop.
<?php
namespace Tests\Feature\Administrators;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\Hash;
use App\Eloquent\Auth\Administrator;
use App\Eloquent\Department;
use Tests\Concerns\AuthenticatesAdmin;
use Tests\TestCase;
class CreateAdminTest extends TestCase
{
use AuthenticatesAdmin, WithFaker;
/**
* @test
*/
public function an_admin_can_create_another_admin()
{
[$name, $email, $department] = [
$this->faker->name,
$this->faker->safeEmail,
create(Department::class)
];
$this->post('/administrators', [
'name' => $name,
'email' => $email,
'department' => $department->id,
'password' => '123456',
])
->assertStatus(302)
->assertRedirect('/administrators')
->assertSessionHas('success');
$this->assertDatabaseHas('administrators', [
'name' => $name,
'email' => $email,
'department_id' => $department->id,
]);
$this->assertTrue(
Hash::check('123456',
Administrator::where('email', $email)->first()->password
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment