How to Set Up a Test for the Destroy Method Laravel 5.6 The Next CEO of Stack OverflowFunctional tests depth of assertionsZF3 Unit test authentication onBootstrapLaravel 5.2 PHPUnit JSON Api request body not being setLaravel assert status after redirectLaravel 5.6 - how to create a model factory with a vertical table?Laravel testing: get() method persists query stringLaravel 5.6. How to test JSON/JSONb columnsLaravel 5.6. Mockery. Mock method on propertyLaravel: How to use the same post form for multiple sectionsCan't make assertions because exceptions are crashing my test in Laravel

Only print output after finding pattern

If I blow insulation everywhere in my attic except the door trap, will heat escape through it?

Increase performance creating Mandelbrot set in python

Term for the "extreme-extension" version of a straw man fallacy?

How do I go from 300 unfinished/half written blog posts, to published posts?

Horror movie/show or scene where a horse creature opens its mouth really wide and devours a man in a stables

Why do professional authors make "consistency" mistakes? And how to avoid them?

How can I quit an app using Terminal?

Customer Requests (Sometimes) Drive Me Bonkers!

% symbol leads to superlong (forever?) compilations

Grabbing quick drinks

When Does an Atlas Uniquely Define a Manifold?

Robert Sheckley short story about vacation spots being overwhelmed

Are there languages with no euphemisms?

When airplanes disconnect from a tanker during air to air refueling, why do they bank so sharply to the right?

How to be diplomatic in refusing to write code that breaches the privacy of our users

WOW air has ceased operation, can I get my tickets refunded?

Does it take more energy to get to Venus or to Mars?

What is the point of a new vote on May's deal when the indicative votes suggest she will not win?

Why didn't Khan get resurrected in the Genesis Explosion?

Return the Closest Prime Number

What is the purpose of the Evocation wizard's Potent Cantrip feature?

Shade part of a Venn diagram

What does "Its cash flow is deeply negative" mean?



How to Set Up a Test for the Destroy Method Laravel 5.6



The Next CEO of Stack OverflowFunctional tests depth of assertionsZF3 Unit test authentication onBootstrapLaravel 5.2 PHPUnit JSON Api request body not being setLaravel assert status after redirectLaravel 5.6 - how to create a model factory with a vertical table?Laravel testing: get() method persists query stringLaravel 5.6. How to test JSON/JSONb columnsLaravel 5.6. Mockery. Mock method on propertyLaravel: How to use the same post form for multiple sectionsCan't make assertions because exceptions are crashing my test in Laravel










0















I'm going through the testing on my app, and I've gotten to the point where I need to test the destroy method of my controller. The test as I have it currently is:



public function test_user_can_delete_draft()

$user = factory(User::class)->states('confirmed', 'normaluser')->create();
$userForm = factory(Form::class)->states('in_house_signs')->create(['user_id' => $user->id, 'status' => 'draft',]);
// Test creator can delete form
$response = $this->actingAs($user)->delete(route('forms.destroy', $userForm));
$response->assertSuccessful();



And the method in the controller that I am testing is:



public function destroy($id) 
$form = Form::find($id);
Comment::where('form_id', $id)->delete();
$form->delete();

// Redirect
return redirect()->back()->with('status', 'Form successfully deleted');



When I run phpunit, I get the error:



Response status code [302] is not a successful status code.
Failed asserting that false is true.


What should I do to get the test to run properly?










share|improve this question


























    0















    I'm going through the testing on my app, and I've gotten to the point where I need to test the destroy method of my controller. The test as I have it currently is:



    public function test_user_can_delete_draft()

    $user = factory(User::class)->states('confirmed', 'normaluser')->create();
    $userForm = factory(Form::class)->states('in_house_signs')->create(['user_id' => $user->id, 'status' => 'draft',]);
    // Test creator can delete form
    $response = $this->actingAs($user)->delete(route('forms.destroy', $userForm));
    $response->assertSuccessful();



    And the method in the controller that I am testing is:



    public function destroy($id) 
    $form = Form::find($id);
    Comment::where('form_id', $id)->delete();
    $form->delete();

    // Redirect
    return redirect()->back()->with('status', 'Form successfully deleted');



    When I run phpunit, I get the error:



    Response status code [302] is not a successful status code.
    Failed asserting that false is true.


    What should I do to get the test to run properly?










    share|improve this question
























      0












      0








      0








      I'm going through the testing on my app, and I've gotten to the point where I need to test the destroy method of my controller. The test as I have it currently is:



      public function test_user_can_delete_draft()

      $user = factory(User::class)->states('confirmed', 'normaluser')->create();
      $userForm = factory(Form::class)->states('in_house_signs')->create(['user_id' => $user->id, 'status' => 'draft',]);
      // Test creator can delete form
      $response = $this->actingAs($user)->delete(route('forms.destroy', $userForm));
      $response->assertSuccessful();



      And the method in the controller that I am testing is:



      public function destroy($id) 
      $form = Form::find($id);
      Comment::where('form_id', $id)->delete();
      $form->delete();

      // Redirect
      return redirect()->back()->with('status', 'Form successfully deleted');



      When I run phpunit, I get the error:



      Response status code [302] is not a successful status code.
      Failed asserting that false is true.


      What should I do to get the test to run properly?










      share|improve this question














      I'm going through the testing on my app, and I've gotten to the point where I need to test the destroy method of my controller. The test as I have it currently is:



      public function test_user_can_delete_draft()

      $user = factory(User::class)->states('confirmed', 'normaluser')->create();
      $userForm = factory(Form::class)->states('in_house_signs')->create(['user_id' => $user->id, 'status' => 'draft',]);
      // Test creator can delete form
      $response = $this->actingAs($user)->delete(route('forms.destroy', $userForm));
      $response->assertSuccessful();



      And the method in the controller that I am testing is:



      public function destroy($id) 
      $form = Form::find($id);
      Comment::where('form_id', $id)->delete();
      $form->delete();

      // Redirect
      return redirect()->back()->with('status', 'Form successfully deleted');



      When I run phpunit, I get the error:



      Response status code [302] is not a successful status code.
      Failed asserting that false is true.


      What should I do to get the test to run properly?







      php laravel laravel-5.6 laravel-testing






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 14:29









      Erik WillliamsErik Willliams

      142




      142






















          2 Answers
          2






          active

          oldest

          votes


















          0














          you could try to use assertRedirect https://laravel.com/docs/5.6/http-tests#assert-redirect



          or use the status check:



          $response->assertStatus(302) https://laravel.com/docs/5.6/http-tests#assert-status



          or if you really want to check if the record is being deleted you could check the database in your test if the record is deleted $this->assertEquals(Comment::where('form_id', $userForm->id)->first(),null)






          share|improve this answer























          • I changed my controller from redirect()->back to redirect()->route and changed the test to match and now it passes! Thank you for the tip!

            – Erik Willliams
            Mar 7 at 14:51


















          0














          You are using $response->assertSuccessful(); and redirecting user, I mean if your delete request successes it will return 302 redirect, change assertSuccessful() to assertStatus(302)






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55046189%2fhow-to-set-up-a-test-for-the-destroy-method-laravel-5-6%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            you could try to use assertRedirect https://laravel.com/docs/5.6/http-tests#assert-redirect



            or use the status check:



            $response->assertStatus(302) https://laravel.com/docs/5.6/http-tests#assert-status



            or if you really want to check if the record is being deleted you could check the database in your test if the record is deleted $this->assertEquals(Comment::where('form_id', $userForm->id)->first(),null)






            share|improve this answer























            • I changed my controller from redirect()->back to redirect()->route and changed the test to match and now it passes! Thank you for the tip!

              – Erik Willliams
              Mar 7 at 14:51















            0














            you could try to use assertRedirect https://laravel.com/docs/5.6/http-tests#assert-redirect



            or use the status check:



            $response->assertStatus(302) https://laravel.com/docs/5.6/http-tests#assert-status



            or if you really want to check if the record is being deleted you could check the database in your test if the record is deleted $this->assertEquals(Comment::where('form_id', $userForm->id)->first(),null)






            share|improve this answer























            • I changed my controller from redirect()->back to redirect()->route and changed the test to match and now it passes! Thank you for the tip!

              – Erik Willliams
              Mar 7 at 14:51













            0












            0








            0







            you could try to use assertRedirect https://laravel.com/docs/5.6/http-tests#assert-redirect



            or use the status check:



            $response->assertStatus(302) https://laravel.com/docs/5.6/http-tests#assert-status



            or if you really want to check if the record is being deleted you could check the database in your test if the record is deleted $this->assertEquals(Comment::where('form_id', $userForm->id)->first(),null)






            share|improve this answer













            you could try to use assertRedirect https://laravel.com/docs/5.6/http-tests#assert-redirect



            or use the status check:



            $response->assertStatus(302) https://laravel.com/docs/5.6/http-tests#assert-status



            or if you really want to check if the record is being deleted you could check the database in your test if the record is deleted $this->assertEquals(Comment::where('form_id', $userForm->id)->first(),null)







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 7 at 14:36









            MrChrissssMrChrissss

            14319




            14319












            • I changed my controller from redirect()->back to redirect()->route and changed the test to match and now it passes! Thank you for the tip!

              – Erik Willliams
              Mar 7 at 14:51

















            • I changed my controller from redirect()->back to redirect()->route and changed the test to match and now it passes! Thank you for the tip!

              – Erik Willliams
              Mar 7 at 14:51
















            I changed my controller from redirect()->back to redirect()->route and changed the test to match and now it passes! Thank you for the tip!

            – Erik Willliams
            Mar 7 at 14:51





            I changed my controller from redirect()->back to redirect()->route and changed the test to match and now it passes! Thank you for the tip!

            – Erik Willliams
            Mar 7 at 14:51













            0














            You are using $response->assertSuccessful(); and redirecting user, I mean if your delete request successes it will return 302 redirect, change assertSuccessful() to assertStatus(302)






            share|improve this answer



























              0














              You are using $response->assertSuccessful(); and redirecting user, I mean if your delete request successes it will return 302 redirect, change assertSuccessful() to assertStatus(302)






              share|improve this answer

























                0












                0








                0







                You are using $response->assertSuccessful(); and redirecting user, I mean if your delete request successes it will return 302 redirect, change assertSuccessful() to assertStatus(302)






                share|improve this answer













                You are using $response->assertSuccessful(); and redirecting user, I mean if your delete request successes it will return 302 redirect, change assertSuccessful() to assertStatus(302)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 7 at 14:37









                Nevermind23Nevermind23

                225211




                225211



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55046189%2fhow-to-set-up-a-test-for-the-destroy-method-laravel-5-6%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                    Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                    Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved