Ajmal Nazer
Ajmal Nazer

Reputation: 1

How to Use Mockery for Unit Testing User Registration in Laravel

I'm new to writing test scripts and mocking in Laravel, and I'm trying to use Mockery to mock a test case for user registration. Previously, I wrote the following code to manually test user registration:

public function test_a_user_can_register()
{
    $this->postJson(route('register'),[
        'name' => "admin",
        'email' => '[email protected]',
        'password' => 'P@ssword',
        'password_confirmation' => 'P@ssword',
        'type' => 0,
        'status' => 1,
    ])->assertCreated();

    $this->assertDatabaseHas('users', ['name' => 'admin']);
}

I want to use Mockery to mock the user registration process instead of hitting the actual database. The goal is to create a user with the provided details or with any fake details. Could someone guide me on how to achieve this using Mockery?

Thank you!

Upvotes: 0

Views: 39

Answers (0)

Related Questions