Skip to content

Instantly share code, notes, and snippets.

@owenvoke
Last active June 10, 2020 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owenvoke/b9e09290fe55737be8168c9d961a772f to your computer and use it in GitHub Desktop.
Save owenvoke/b9e09290fe55737be8168c9d961a772f to your computer and use it in GitHub Desktop.
A patch for updating the TALL stack preset tests to use Pest syntax.

Tall Stack Pest Syntax

This is a patch for updating the Laravel TALL stack preset tests to use the Pest syntax.

Usage

curl https://gist.githubusercontent.com/owenvoke/b9e09290fe55737be8168c9d961a772f/raw/tall-stack-pest-syntax-changes.diff | git apply
From 68aa01f4ed296415d4058781505b58b481b3e09c Mon Sep 17 00:00:00 2001
From: Owen Voke <development@voke.dev>
Date: Mon, 11 May 2020 13:05:43 +0100
Subject: [PATCH] Update all tests to use Pest syntax
---
tests/Feature/Auth/LoginTest.php | 179 +++++++--------
tests/Feature/Auth/LogoutTest.php | 37 ++-
tests/Feature/Auth/Passwords/ConfirmTest.php | 119 +++++-----
tests/Feature/Auth/Passwords/EmailTest.php | 82 +++----
tests/Feature/Auth/Passwords/ResetTest.php | 223 ++++++++----------
tests/Feature/Auth/RegisterTest.php | 228 +++++++++----------
tests/Feature/Auth/VerifyTest.php | 71 +++---
7 files changed, 408 insertions(+), 531 deletions(-)
diff --git a/tests/Feature/Auth/LoginTest.php b/tests/Feature/Auth/LoginTest.php
index 62ec2a0..39b5660 100644
--- a/tests/Feature/Auth/LoginTest.php
+++ b/tests/Feature/Auth/LoginTest.php
@@ -1,107 +1,84 @@
<?php
-namespace Tests\Feature\Auth;
-
use App\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
-use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Livewire\Livewire;
-use Tests\TestCase;
-
-class LoginTest extends TestCase
-{
- use RefreshDatabase;
-
- /** @test */
- public function can_view_login_page()
- {
- $this->get(route('login'))
- ->assertSuccessful()
- ->assertSeeLivewire('auth.login');
- }
-
- /** @test */
- public function is_redirected_if_already_logged_in()
- {
- $user = factory(User::class)->create();
-
- $this->be($user);
-
- $this->get(route('login'))
- ->assertRedirect(route('home'));
- }
-
- /** @test */
- public function a_user_can_login()
- {
- $user = factory(User::class)->create(['password' => Hash::make('password')]);
-
- Livewire::test('auth.login')
- ->set('email', $user->email)
- ->set('password', 'password')
- ->call('authenticate');
-
- $this->assertAuthenticatedAs($user);
- }
-
- /** @test */
- public function is_redirected_to_the_home_page_after_login()
- {
- $user = factory(User::class)->create(['password' => Hash::make('password')]);
-
- Livewire::test('auth.login')
- ->set('email', $user->email)
- ->set('password', 'password')
- ->call('authenticate')
- ->assertRedirect(route('home'));
- }
-
- /** @test */
- public function email_is_required()
- {
- $user = factory(User::class)->create(['password' => Hash::make('password')]);
-
- Livewire::test('auth.login')
- ->set('password', 'password')
- ->call('authenticate')
- ->assertHasErrors(['email' => 'required']);
- }
-
- /** @test */
- public function email_must_be_valid_email()
- {
- $user = factory(User::class)->create(['password' => Hash::make('password')]);
-
- Livewire::test('auth.login')
- ->set('email', 'invalid-email')
- ->set('password', 'password')
- ->call('authenticate')
- ->assertHasErrors(['email' => 'email']);
- }
-
- /** @test */
- public function password_is_required()
- {
- $user = factory(User::class)->create(['password' => Hash::make('password')]);
-
- Livewire::test('auth.login')
- ->set('email', $user->email)
- ->call('authenticate')
- ->assertHasErrors(['password' => 'required']);
- }
-
- /** @test */
- public function bad_login_attempt_shows_message()
- {
- $user = factory(User::class)->create();
-
- Livewire::test('auth.login')
- ->set('email', $user->email)
- ->set('password', 'bad-password')
- ->call('authenticate')
- ->assertHasErrors('email');
-
- $this->assertFalse(Auth::check());
- }
-}
+
+uses(RefreshDatabase::class);
+
+it('can view the login page', function () {
+ $this->get(route('login'))
+ ->assertSuccessful()
+ ->assertSeeLivewire('auth.login');
+});
+
+it('is redirected if already logged in', function () {
+ $user = factory(User::class)->create();
+
+ $this->be($user);
+
+ $this->get(route('login'))
+ ->assertRedirect(route('home'));
+});
+
+it('allows a user to log in', function () {
+ $user = factory(User::class)->create(['password' => Hash::make('password')]);
+
+ Livewire::test('auth.login')
+ ->set('email', $user->email)
+ ->set('password', 'password')
+ ->call('authenticate');
+
+ $this->assertAuthenticatedAs($user);
+});
+
+it('redirects to the homepage after logging in', function () {
+ $user = factory(User::class)->create(['password' => Hash::make('password')]);
+
+ Livewire::test('auth.login')
+ ->set('email', $user->email)
+ ->set('password', 'password')
+ ->call('authenticate')
+ ->assertRedirect(route('home'));
+});
+
+it('requires an email address', function () {
+ $user = factory(User::class)->create(['password' => Hash::make('password')]);
+
+ Livewire::test('auth.login')
+ ->set('password', 'password')
+ ->call('authenticate')
+ ->assertHasErrors(['email' => 'required']);
+});
+
+it('requires a valid email address', function () {
+ $user = factory(User::class)->create(['password' => Hash::make('password')]);
+
+ Livewire::test('auth.login')
+ ->set('email', 'invalid-email')
+ ->set('password', 'password')
+ ->call('authenticate')
+ ->assertHasErrors(['email' => 'email']);
+});
+
+it('requires a valid password', function () {
+ $user = factory(User::class)->create(['password' => Hash::make('password')]);
+
+ Livewire::test('auth.login')
+ ->set('email', $user->email)
+ ->call('authenticate')
+ ->assertHasErrors(['password' => 'required']);
+});
+
+it('shows a message on a bad login attempt', function () {
+ $user = factory(User::class)->create();
+
+ Livewire::test('auth.login')
+ ->set('email', $user->email)
+ ->set('password', 'bad-password')
+ ->call('authenticate')
+ ->assertHasErrors('email');
+
+ $this->assertFalse(Auth::check());
+});
diff --git a/tests/Feature/Auth/LogoutTest.php b/tests/Feature/Auth/LogoutTest.php
index 2c4d211..5a4d924 100644
--- a/tests/Feature/Auth/LogoutTest.php
+++ b/tests/Feature/Auth/LogoutTest.php
@@ -1,34 +1,25 @@
<?php
-namespace Tests\Feature\Auth;
-
use App\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Auth;
-use Tests\TestCase;
-class LogoutTest extends TestCase
-{
- use RefreshDatabase;
+uses(RefreshDatabase::class);
+
+it('allows an authenticated user to log out', function () {
+ $user = factory(User::class)->create();
+ $this->be($user);
- /** @test */
- public function an_authenticated_user_can_log_out()
- {
- $user = factory(User::class)->create();
- $this->be($user);
+ $this->post(route('logout'))
+ ->assertRedirect(route('home'));
- $this->post(route('logout'))
- ->assertRedirect(route('home'));
+ $this->assertFalse(Auth::check());
+});
- $this->assertFalse(Auth::check());
- }
+it('does not allow an unauthenticated user to log out', function () {
- /** @test */
- public function an_unauthenticated_user_can_not_log_out()
- {
- $this->post(route('logout'))
- ->assertRedirect(route('login'));
+ $this->post(route('logout'))
+ ->assertRedirect(route('login'));
- $this->assertFalse(Auth::check());
- }
-}
+ $this->assertFalse(Auth::check());
+});
diff --git a/tests/Feature/Auth/Passwords/ConfirmTest.php b/tests/Feature/Auth/Passwords/ConfirmTest.php
index bc1e886..d93a9e6 100644
--- a/tests/Feature/Auth/Passwords/ConfirmTest.php
+++ b/tests/Feature/Auth/Passwords/ConfirmTest.php
@@ -1,76 +1,59 @@
<?php
-namespace Tests\Feature\Auth\Passwords;
-
use App\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Route;
use Livewire\Livewire;
-use Tests\TestCase;
-
-class ConfirmTest extends TestCase
-{
- use RefreshDatabase;
-
- protected function setUp(): void
- {
- parent::setUp();
-
- Route::get('/must-be-confirmed', function () {
- return 'You must be confirmed to see this page.';
- })->middleware(['web', 'password.confirm']);
- }
-
- /** @test */
- public function a_user_must_confirm_their_password_before_visiting_a_protected_page()
- {
- $user = factory(User::class)->create();
- $this->be($user);
-
- $this->get('/must-be-confirmed')
- ->assertRedirect(route('password.confirm'));
-
- $this->followingRedirects()
- ->get('/must-be-confirmed')
- ->assertSeeLivewire('auth.passwords.confirm');
- }
-
- /** @test */
- public function a_user_must_enter_a_password_to_confirm_it()
- {
- Livewire::test('auth.passwords.confirm')
- ->call('confirm')
- ->assertHasErrors(['password' => 'required']);
- }
-
- /** @test */
- public function a_user_must_enter_their_own_password_to_confirm_it()
- {
- $user = factory(User::class)->create([
- 'password' => Hash::make('password'),
- ]);
-
- Livewire::test('auth.passwords.confirm')
- ->set('password', 'not-password')
- ->call('confirm')
- ->assertHasErrors(['password' => 'password']);
- }
-
- /** @test */
- public function a_user_who_confirms_their_password_will_get_redirected()
- {
- $user = factory(User::class)->create([
- 'password' => Hash::make('password'),
- ]);
-
- $this->be($user);
-
- $this->withSession(['url.intended' => '/must-be-confirmed']);
- Livewire::test('auth.passwords.confirm')
- ->set('password', 'password')
- ->call('confirm')
- ->assertRedirect('/must-be-confirmed');
- }
-}
+uses(RefreshDatabase::class);
+
+beforeEach(function () {
+ Route::get('/must-be-confirmed', function () {
+ return 'You must be confirmed to see this page.';
+ })->middleware(['web', 'password.confirm']);
+});
+
+it('requires a user to confirm their password before visiting a protected page', function () {
+ $user = factory(User::class)->create();
+ $this->be($user);
+
+ $this->get('/must-be-confirmed')
+ ->assertRedirect(route('password.confirm'));
+
+ $this->followingRedirects()
+ ->get('/must-be-confirmed')
+ ->assertSeeLivewire('auth.passwords.confirm');
+});
+
+it('requires a user to enter a password to confirm it', function () {
+ Livewire::test('auth.passwords.confirm')
+ ->call('confirm')
+ ->assertHasErrors(['password' => 'required']);
+});
+
+it('requires a user to enter their own password to confirm it', function () {
+ $user = factory(User::class)->create([
+ 'password' => Hash::make('password'),
+ ]);
+
+ Livewire::test('auth.passwords.confirm')
+ ->set('password', 'not-password')
+ ->call('confirm')
+ ->assertHasErrors(['password' => 'password']);
+});
+
+it('redirects a user who correctly confirms their own password', function () {
+ $user = factory(User::class)->create([
+ 'password' => Hash::make('password'),
+ ]);
+
+ $this->be($user);
+
+ $this->withSession(['url.intended' => '/must-be-confirmed']);
+
+ Livewire::test('auth.passwords.confirm')
+ ->set('password', 'password')
+ ->call('confirm')
+ ->assertRedirect('/must-be-confirmed');
+});
diff --git a/tests/Feature/Auth/Passwords/EmailTest.php b/tests/Feature/Auth/Passwords/EmailTest.php
index 055f753..b1867c5 100644
--- a/tests/Feature/Auth/Passwords/EmailTest.php
+++ b/tests/Feature/Auth/Passwords/EmailTest.php
@@ -1,53 +1,39 @@
<?php
-namespace Tests\Feature\Auth\Passwords;
-
use App\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
-use Tests\TestCase;
-
-class EmailTest extends TestCase
-{
- use RefreshDatabase;
-
- /** @test */
- public function can_view_password_request_page()
- {
- $this->get(route('password.request'))
- ->assertSuccessful()
- ->assertSeeLivewire('auth.passwords.email');
- }
-
- /** @test */
- public function a_user_must_enter_an_email_address()
- {
- Livewire::test('auth.passwords.email')
- ->call('sendResetPasswordLink')
- ->assertHasErrors(['email' => 'required']);
- }
-
- /** @test */
- public function a_user_must_enter_a_valid_email_address()
- {
- Livewire::test('auth.passwords.email')
- ->set('email', 'email')
- ->call('sendResetPasswordLink')
- ->assertHasErrors(['email' => 'email']);
- }
-
- /** @test */
- public function a_user_who_enters_a_valid_email_address_will_get_sent_an_email()
- {
- $user = factory(User::class)->create();
-
- Livewire::test('auth.passwords.email')
- ->set('email', $user->email)
- ->call('sendResetPasswordLink')
- ->assertNotSet('emailSentMessage', false);
-
- $this->assertDatabaseHas('password_resets', [
- 'email' => $user->email,
- ]);
- }
-}
+
+uses(RefreshDatabase::class);
+
+it('can view the password request page', function () {
+ $this->get(route('password.request'))
+ ->assertSuccessful()
+ ->assertSeeLivewire('auth.passwords.email');
+});
+
+it('requires a user to enter an email', function () {
+ Livewire::test('auth.passwords.email')
+ ->call('sendResetPasswordLink')
+ ->assertHasErrors(['email' => 'required']);
+});
+
+it('requires a user to enter a valid email', function () {
+ Livewire::test('auth.passwords.email')
+ ->set('email', 'email')
+ ->call('sendResetPasswordLink')
+ ->assertHasErrors(['email' => 'email']);
+});
+
+it('sends an email to a user that enters a valid email', function () {
+ $user = factory(User::class)->create();
+
+ Livewire::test('auth.passwords.email')
+ ->set('email', $user->email)
+ ->call('sendResetPasswordLink')
+ ->assertNotSet('emailSentMessage', false);
+
+ $this->assertDatabaseHas('password_resets', [
+ 'email' => $user->email,
+ ]);
+});
diff --git a/tests/Feature/Auth/Passwords/ResetTest.php b/tests/Feature/Auth/Passwords/ResetTest.php
index bf088ce..dcea540 100644
--- a/tests/Feature/Auth/Passwords/ResetTest.php
+++ b/tests/Feature/Auth/Passwords/ResetTest.php
@@ -1,132 +1,109 @@
<?php
-namespace Tests\Feature\Auth\Passwords;
-
use App\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
-use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Livewire\Livewire;
-use Tests\TestCase;
-
-class ResetTest extends TestCase
-{
- use RefreshDatabase;
-
- /** @test */
- public function can_view_password_reset_page()
- {
- $user = factory(User::class)->create();
-
- $token = Str::random(16);
-
- DB::table('password_resets')->insert([
- 'email' => $user->email,
- 'token' => Hash::make($token),
- 'created_at' => Carbon::now(),
- ]);
-
- $this->get(route('password.reset', [
- 'email' => $user->email,
- 'token' => $token,
- ]))
- ->assertSuccessful()
- ->assertSeeLivewire('auth.passwords.reset');
- }
-
- /** @test */
- public function can_reset_password()
- {
- $user = factory(User::class)->create();
-
- $token = Str::random(16);
-
- DB::table('password_resets')->insert([
- 'email' => $user->email,
- 'token' => Hash::make($token),
- 'created_at' => Carbon::now(),
- ]);
-
- Livewire::test('auth.passwords.reset', [
- 'token' => $token,
- ])
- ->set('email', $user->email)
- ->set('password', 'new-password')
- ->set('passwordConfirmation', 'new-password')
- ->call('resetPassword');
-
- $this->assertTrue(Auth::attempt([
- 'email' => $user->email,
- 'password' => 'new-password',
- ]));
- }
-
- /** @test */
- public function token_is_required()
- {
- Livewire::test('auth.passwords.reset', [
- 'token' => null,
- ])
- ->call('resetPassword')
- ->assertHasErrors(['token' => 'required']);
- }
-
- /** @test */
- public function email_is_required()
- {
- Livewire::test('auth.passwords.reset', [
- 'token' => Str::random(16),
- ])
- ->set('email', null)
- ->call('resetPassword')
- ->assertHasErrors(['email' => 'required']);
- }
-
- /** @test */
- public function email_is_valid_email()
- {
- Livewire::test('auth.passwords.reset', [
- 'token' => Str::random(16),
- ])
- ->set('email', 'email')
- ->call('resetPassword')
- ->assertHasErrors(['email' => 'email']);
- }
-
- /** @test */
- function password_is_required()
- {
- Livewire::test('auth.passwords.reset', [
- 'token' => Str::random(16),
- ])
- ->set('password', '')
- ->call('resetPassword')
- ->assertHasErrors(['password' => 'required']);
- }
-
- /** @test */
- function password_is_minimum_of_eight_characters()
- {
- Livewire::test('auth.passwords.reset', [
- 'token' => Str::random(16),
- ])
- ->set('password', 'secret')
- ->call('resetPassword')
- ->assertHasErrors(['password' => 'min']);
- }
-
- /** @test */
- function password_matches_password_confirmation()
- {
- Livewire::test('auth.passwords.reset', [
- 'token' => Str::random(16),
- ])
- ->set('password', 'new-password')
- ->set('passwordConfirmation', 'not-new-password')
- ->call('resetPassword')
- ->assertHasErrors(['password' => 'same']);
- }
-}
+
+uses(RefreshDatabase::class);
+
+it('can view the password reset page', function () {
+ $user = factory(User::class)->create();
+
+ $token = Str::random(16);
+
+ DB::table('password_resets')->insert([
+ 'email' => $user->email,
+ 'token' => Hash::make($token),
+ 'created_at' => Carbon::now(),
+ ]);
+
+ $this->get(route('password.reset', [
+ 'email' => $user->email,
+ 'token' => $token,
+ ]))
+ ->assertSuccessful()
+ ->assertSeeLivewire('auth.passwords.reset');
+});
+
+it('can reset a users password', function () {
+ $user = factory(User::class)->create();
+
+ $token = Str::random(16);
+
+ DB::table('password_resets')->insert([
+ 'email' => $user->email,
+ 'token' => Hash::make($token),
+ 'created_at' => Carbon::now(),
+ ]);
+
+ Livewire::test('auth.passwords.reset', [
+ 'token' => $token,
+ ])
+ ->set('email', $user->email)
+ ->set('password', 'new-password')
+ ->set('passwordConfirmation', 'new-password')
+ ->call('resetPassword');
+
+ $this->assertTrue(Auth::attempt([
+ 'email' => $user->email,
+ 'password' => 'new-password',
+ ]));
+});
+
+it('requires a token', function () {
+ Livewire::test('auth.passwords.reset', [
+ 'token' => null,
+ ])
+ ->call('resetPassword')
+ ->assertHasErrors(['token' => 'required']);
+});
+
+it('requires an email', function () {
+ Livewire::test('auth.passwords.reset', [
+ 'token' => Str::random(16),
+ ])
+ ->set('email', null)
+ ->call('resetPassword')
+ ->assertHasErrors(['email' => 'required']);
+});
+
+it('requires a valid email', function () {
+ Livewire::test('auth.passwords.reset', [
+ 'token' => Str::random(16),
+ ])
+ ->set('email', 'email')
+ ->call('resetPassword')
+ ->assertHasErrors(['email' => 'email']);
+});
+
+it('requires a password', function () {
+ Livewire::test('auth.passwords.reset', [
+ 'token' => Str::random(16),
+ ])
+ ->set('password', '')
+ ->call('resetPassword')
+ ->assertHasErrors(['password' => 'required']);
+});
+
+it('requires a password that is at least the minimum length', function () {
+ Livewire::test('auth.passwords.reset', [
+ 'token' => Str::random(16),
+ ])
+ ->set('password', 'secret')
+ ->call('resetPassword')
+ ->assertHasErrors(['password' => 'min']);
+});
+
+it('requires the password confirmation to match the password', function () {
+ Livewire::test('auth.passwords.reset', [
+ 'token' => Str::random(16),
+ ])
+ ->set('password', 'new-password')
+ ->set('passwordConfirmation', 'not-new-password')
+ ->call('resetPassword')
+ ->assertHasErrors(['password' => 'same']);
+});
diff --git a/tests/Feature/Auth/RegisterTest.php b/tests/Feature/Auth/RegisterTest.php
index 3f5843c..759d85d 100644
--- a/tests/Feature/Auth/RegisterTest.php
+++ b/tests/Feature/Auth/RegisterTest.php
@@ -1,132 +1,108 @@
<?php
-namespace Tests\Feature\Auth;
-
use App\User;
-use Tests\TestCase;
-use Livewire\Livewire;
-use Illuminate\Support\Facades\Hash;
-use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Auth;
+use Livewire\Livewire;
-class RegisterTest extends TestCase
-{
- use RefreshDatabase;
-
- /** @test */
- function registration_page_contains_livewire_component()
- {
- $this->get(route('register'))
- ->assertSuccessful()
- ->assertSeeLivewire('auth.register');
- }
-
- /** @test */
- public function is_redirected_if_already_logged_in()
- {
- $user = factory(User::class)->create();
-
- $this->be($user);
-
- $this->get(route('register'))
- ->assertRedirect(route('home'));
- }
-
- /** @test */
- function a_user_can_register()
- {
- Livewire::test('auth.register')
- ->set('name', 'Tall Stack')
- ->set('email', 'tallstack@example.com')
- ->set('password', 'password')
- ->set('passwordConfirmation', 'password')
- ->call('register')
- ->assertRedirect(route('home'));
-
- $this->assertTrue(User::whereEmail('tallstack@example.com')->exists());
- $this->assertEquals('tallstack@example.com', Auth::user()->email);
- }
-
- /** @test */
- function name_is_required()
- {
- Livewire::test('auth.register')
- ->set('name', '')
- ->call('register')
- ->assertHasErrors(['email' => 'required']);
- }
-
- /** @test */
- function email_is_required()
- {
- Livewire::test('auth.register')
- ->set('email', '')
- ->call('register')
- ->assertHasErrors(['email' => 'required']);
- }
-
- /** @test */
- function email_is_valid_email()
- {
- Livewire::test('auth.register')
- ->set('email', 'tallstack')
- ->call('register')
- ->assertHasErrors(['email' => 'email']);
- }
-
- /** @test */
- function email_hasnt_been_taken_already()
- {
- factory(User::class)->create(['email' => 'tallstack@example.com']);
-
- Livewire::test('auth.register')
- ->set('email', 'tallstack@example.com')
- ->call('register')
- ->assertHasErrors(['email' => 'unique']);
- }
-
- /** @test */
- function see_email_hasnt_already_been_taken_validation_message_as_user_types()
- {
- factory(User::class)->create(['email' => 'tallstack@example.com']);
-
- Livewire::test('auth.register')
- ->set('email', 'smallstack@gmail.com')
- ->assertHasNoErrors()
- ->set('email', 'tallstack@example.com')
- ->call('register')
- ->assertHasErrors(['email' => 'unique']);
- }
-
- /** @test */
- function password_is_required()
- {
- Livewire::test('auth.register')
- ->set('password', '')
- ->set('passwordConfirmation', 'password')
- ->call('register')
- ->assertHasErrors(['password' => 'required']);
- }
-
- /** @test */
- function password_is_minimum_of_eight_characters()
- {
- Livewire::test('auth.register')
- ->set('password', 'secret')
- ->set('passwordConfirmation', 'secret')
- ->call('register')
- ->assertHasErrors(['password' => 'min']);
- }
-
- /** @test */
- function password_matches_password_confirmation()
- {
- Livewire::test('auth.register')
- ->set('email', 'tallstack@example.com')
- ->set('password', 'password')
- ->set('passwordConfirmation', 'not-password')
- ->call('register')
- ->assertHasErrors(['password' => 'same']);
- }
-}
+uses(RefreshDatabase::class);
+
+it('checks the registration page contains Livewire component', function () {
+ $this->get(route('register'))
+ ->assertSuccessful()
+ ->assertSeeLivewire('auth.register');
+});
+
+it('redirects if the user is already logged in', function () {
+ $user = factory(User::class)->create();
+
+ $this->be($user);
+
+ $this->get(route('register'))
+ ->assertRedirect(route('home'));
+});
+
+it('allows a user to register', function () {
+ Livewire::test('auth.register')
+ ->set('name', 'Tall Stack')
+ ->set('email', 'tallstack@example.com')
+ ->set('password', 'password')
+ ->set('passwordConfirmation', 'password')
+ ->call('register')
+ ->assertRedirect(route('home'));
+
+ $this->assertTrue(User::whereEmail('tallstack@example.com')->exists());
+ $this->assertEquals('tallstack@example.com', Auth::user()->email);
+});
+
+
+it('requires a name', function () {
+ Livewire::test('auth.register')
+ ->set('name', '')
+ ->call('register')
+ ->assertHasErrors(['email' => 'required']);
+});
+
+it('requires an email', function () {
+ Livewire::test('auth.register')
+ ->set('email', '')
+ ->call('register')
+ ->assertHasErrors(['email' => 'required']);
+});
+
+
+it('requires a valid email', function () {
+ Livewire::test('auth.register')
+ ->set('email', 'tallstack')
+ ->call('register')
+ ->assertHasErrors(['email' => 'email']);
+});
+
+
+it('requires an email that has not already been taken', function () {
+ factory(User::class)->create(['email' => 'tallstack@example.com']);
+
+ Livewire::test('auth.register')
+ ->set('email', 'tallstack@example.com')
+ ->call('register')
+ ->assertHasErrors(['email' => 'unique']);
+});
+
+it('shows an email has already been taken message as the user types', function () {
+ factory(User::class)->create(['email' => 'tallstack@example.com']);
+
+ Livewire::test('auth.register')
+ ->set('email', 'smallstack@gmail.com')
+ ->assertHasNoErrors()
+ ->set('email', 'tallstack@example.com')
+ ->call('register')
+ ->assertHasErrors(['email' => 'unique']);
+});
+
+
+it('requires a password', function () {
+ Livewire::test('auth.register')
+ ->set('password', '')
+ ->set('passwordConfirmation', 'password')
+ ->call('register')
+ ->assertHasErrors(['password' => 'required']);
+});
+
+
+it('requires a password that is at least the minimum length', function () {
+ Livewire::test('auth.register')
+ ->set('password', 'secret')
+ ->set('passwordConfirmation', 'secret')
+ ->call('register')
+ ->assertHasErrors(['password' => 'min']);
+});
+
+
+it('requires a password that matches the password configuration', function () {
+ Livewire::test('auth.register')
+ ->set('email', 'tallstack@example.com')
+ ->set('password', 'password')
+ ->set('passwordConfirmation', 'not-password')
+ ->call('register')
+ ->assertHasErrors(['password' => 'same']);
+});
diff --git a/tests/Feature/Auth/VerifyTest.php b/tests/Feature/Auth/VerifyTest.php
index 202ec94..8dbec0e 100644
--- a/tests/Feature/Auth/VerifyTest.php
+++ b/tests/Feature/Auth/VerifyTest.php
@@ -1,65 +1,52 @@
<?php
-namespace Tests\Feature\Auth;
-
use App\User;
-use Tests\TestCase;
-use Livewire\Livewire;
-use Illuminate\Support\Facades\Hash;
-use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\URL;
+use Livewire\Livewire;
-class VerifyTest extends TestCase
-{
- use RefreshDatabase;
+uses(RefreshDatabase::class);
- /** @test */
- public function can_view_verification_page()
- {
- $user = factory(User::class)->create([
- 'email_verified_at' => null,
- ]);
+it('can view verification page', function () {
+ $user = factory(User::class)->create([
+ 'email_verified_at' => null,
+ ]);
- Auth::login($user);
+ Auth::login($user);
- $this->get(route('verification.notice'))
- ->assertSuccessful()
- ->assertSeeLivewire('auth.verify');
- }
+ $this->get(route('verification.notice'))
+ ->assertSuccessful()
+ ->assertSeeLivewire('auth.verify');
+});
- /** @test */
- public function can_resend_verification_email()
- {
- $user = factory(User::class)->create();
+it('can resend the verification email', function () {
+ $user = factory(User::class)->create();
- Livewire::actingAs($user);
+ Livewire::actingAs($user);
- Livewire::test('auth.verify')
- ->call('resend')
- ->assertEmitted('resent');
- }
+ Livewire::test('auth.verify')
+ ->call('resend')
+ ->assertEmitted('resent');
+});
- /** @test */
- public function can_verify()
- {
- $user = factory(User::class)->create([
- 'email_verified_at' => null,
- ]);
+it('can verify an email', function () {
+ $user = factory(User::class)->create([
+ 'email_verified_at' => null,
+ ]);
- Auth::login($user);
+ Auth::login($user);
- $url = URL::temporarySignedRoute('verification.verify', Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)), [
+ $url = URL::temporarySignedRoute('verification.verify',
+ Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)), [
'id' => $user->getKey(),
'hash' => sha1($user->getEmailForVerification()),
]);
- $this->get($url)
- ->assertRedirect(route('home'));
+ $this->get($url)
+ ->assertRedirect(route('home'));
- $this->assertTrue($user->hasVerifiedEmail());
- }
-}
+ $this->assertTrue($user->hasVerifiedEmail());
+});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment