Created
March 25, 2021 23:46
-
-
Save TristanOrta/f9d02fd548a8c048614655d7263c54d3 to your computer and use it in GitHub Desktop.
code for a test in the registration module with phpUnit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} | |
} |
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
Very well! thanks so much! greetings my friend!