Skip to content

Instantly share code, notes, and snippets.

@TristanOrta
Created March 25, 2021 23:46
Show Gist options
  • Save TristanOrta/f9d02fd548a8c048614655d7263c54d3 to your computer and use it in GitHub Desktop.
Save TristanOrta/f9d02fd548a8c048614655d7263c54d3 to your computer and use it in GitHub Desktop.
code for a test in the registration module with phpUnit
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use App\User;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class RegisterModuleTest extends TestCase
{
use DatabaseTransactions;
/**
* A basic feature test example.
*
* @return void
*/
public function testRegisterFormDisplayed()
{
$response = $this->get('/register');
$response->assertStatus(200);
}
public function test_user_register()
{
$user = factory(User::class)->make();
$response = $this->post('register', [
'name' => $user->name,
'email' => $user->email,
'password' => 'password',
'password_confirmation' => 'password'
]);
$response->assertRedirect('/');
$response->assertStatus(302);
$response = $this->get('/home');
}
public function test_register_invalidUser()
{
$user = factory(User::class)->make();
$response = $this->post('register', [
'name' => $user->name,
'email' => $user->email,
'password' => 'passworD',
'password_confirmation' => 'Password'
]);
$response->assertSessionHasErrors();
$this->assertGuest();
}
}
@x0nu11byt3
Copy link

Very well! thanks so much! greetings my friend!

@TristanOrta
Copy link
Author

hey d4rk6h05t thank you for your comments, i see you in your code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment