Skip to main content
Post Closed as "Not suitable for this site" by Malachi, Quill, chillworld, 200_success
added 10 characters in body; edited tags; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

Basic Sign Up Methodsign-up method, Testabletestable and With Trywith try/Catchcatch

I am learning how to implement testing and trytry/catchcatch statements into my code. I have a laravelLaravel application with the following method. I am looking for advice on where I should add in trytry/catchcatch statements and what phpunit unit-test(s) I would create to ensure this is functioning properly. Tips on comment blocks are also appreciated.

Basic Sign Up Method, Testable and With Try/Catch

I am learning how to implement testing and try/catch statements into my code. I have a laravel application with the following method. I am looking for advice on where I should add in try/catch statements and what phpunit unit-test(s) I would create to ensure this is functioning properly. Tips on comment blocks also appreciated.

Basic sign-up method, testable and with try/catch

I am learning how to implement testing and try/catch statements into my code. I have a Laravel application with the following method. I am looking for advice on where I should add in try/catch statements and what phpunit unit-test(s) I would create to ensure this is functioning properly. Tips on comment blocks are also appreciated.

Source Link
Jon
  • 109
  • 1

Basic Sign Up Method, Testable and With Try/Catch

I am learning how to implement testing and try/catch statements into my code. I have a laravel application with the following method. I am looking for advice on where I should add in try/catch statements and what phpunit unit-test(s) I would create to ensure this is functioning properly. Tips on comment blocks also appreciated.

// User sign up
public function postSignup() 
{
    $validator = Validator::make(Input::all(), User::$rules);

    $confirmation_code = MyHelper::encrypt_decrypt('encrypt',Input::get('email'));
    
    if($validator->passes()) {
        $user = new User;
        $user->email = Input::get('email');
        $user->password = Hash::make(Input::get('password'));
        $user->emailVerifiedToken = $confirmation_code;
        $user->firstName = null;
        $user->lastName = null;
        $user->shipAddressId = null;
        $user->billAddressId = null;
        $user->phone = null;
        $user->save();
        
        $userdata = array(
            'token' => $confirmation_code
        );

        //Send the user an email requesting verification
        $toEmail = $user->email;
        $toName = $user->email;
        $subject = "Email Verification - example.com";

        Mail::queue('emails.account.account-creation', $userdata, function($message) use ($toEmail,$toName,$subject)
        {
            $message->to($toEmail,$toName)->subject($subject);
        });
        
        if(Auth::attempt(array('email' => Input::get('email'), 'password' => Input::get('password')), false))
        {
            return Redirect::to('/home/')
            ->with('login_message', 'Thank you for creating a new account, please sign in');
        }
    }
    
    return Redirect::to('/account/sign-up')
            ->with('signup_message',  'Something went wrong')
            ->withErrors($validator)
            ->withInput();
}