Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

siewlon6093's avatar

Failed asserting that '<!doctype html>\n <html lang="en">\n

 Tests\Feature\ParticipateInForumTest::test_an_authenticated_user_may_participate_in_forum_threads
Failed asserting that '<!doctype html>\n
<html lang="en">\n
<head>\n
    <meta charset="utf-8">\n
    <meta name="viewport" content="width=device-width, initial-scale=1">\n
\n
    <!-- CSRF Token -->\n
    <meta name="csrf-token" content="obqBIMUAxRZcpRSG3rwWV87tY8Khw3VPCscRuuF2">\n
\n
    <title>Laravel</title>\n
\n
    <!-- Scripts -->\n
    <script src="http://localhost/js/app.js" defer></script>\n
\n
    <!-- Fonts -->\n
    <link rel="dns-prefetch" href="//fonts.gstatic.com">\n
    <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">\n
\n
    <!-- Styles -->\n
    <link href="http://localhost/css/app.css" rel="stylesheet">\n
</head>\n
<body>\n
    <div id="app">\n
        <nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">\n
            <div class="container">\n
                <a class="navbar-brand" href="http://localhost">\n
                    Laravel\n
                </a>\n
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">\n
                    <span class="navbar-toggler-icon"></span>\n
                </button>\n
\n
                <div class="collapse navbar-collapse" id="navbarSupportedContent">\n
                    <!-- Left Side Of Navbar -->\n
                    <ul class="navbar-nav mr-auto">\n
\n
                    </ul>\n
\n
                    <!-- Right Side Of Navbar -->\n
                    <ul class="navbar-nav ml-auto">\n
                        <!-- Authentication Links -->\n
                                                    <li class="nav-item dropdown">\n
                                <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>\n
                                    Vivian Rosenbaum <span class="caret"></span>\n
                                </a>\n
\n
                                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">\n
                                    <a class="dropdown-item" href="http://localhost/logout"\n
                                       onclick="event.preventDefault();\n
                                                     document.getElementById('logout-form').submit();">\n
                                        Logout\n
                                    </a>\n
\n
                                    <form id="logout-form" action="http://localhost/logout" method="POST" style="display: none;">\n
                                        <input type="hidden" name="_token" value="obqBIMUAxRZcpRSG3rwWV87tY8Khw3VPCscRuuF2">                                    </form>\n
                                </div>\n
                            </li>\n
                                            </ul>\n
                </div>\n
            </div>\n
        </nav>\n
\n
        <main class="py-4">\n
                <div class="container">\n
        <div class="row justify-content-center">\n
            <div class="col-md-8">\n
\n
                <div class="card">\n
                    <div class="card-header">\n
                        <a href="#">Gussie Treutel\n
                            Ms.\n
                        </a>\n
                        posted:\n
                    </div>\n
\n
                    <div class="card-body">\n
                       Pariatur in error modi sed fugit. Aut molestias qui beatae et vero hic suscipit. Consequuntur dicta eveniet modi quis.\n
                    </div>\n
                </div>\n
            </div>\n
        </div>\n
    </div>\n
\n
       <div class = "container">\n
        <div class="row justify-content-center">\n
            <div class="col-md-8">\n
                            </div>\n
        </div>\n
       </div>\n
        </main>\n
    </div>\n
</body>\n
</html>\n
' contains "Eius cupiditate dolore possimus voluptas numquam qui illum. Quos voluptatem rerum quaerat. Est omnis corrupti maiores. Aperiam architecto provident nemo quis rem omnis.".

C:\xampp\htdocs\blog\vendor\laravel\framework\src\Illuminate\Testing\TestResponse.php:400
C:\xampp\htdocs\blog\tests\Feature\ParticipateInForumTest.php:30
   function test_an_authenticated_user_may_participate_in_forum_threads()
    {
        $this->be($user = factory('App\User')->create());

        $thread = factory('App\Thread')->create();

        $reply = factory('App\Reply')->make();
        $this->post('/threads/' .$thread->id. '/replies', $reply->toArray());

        $this->get($thread->path())->assertSee($reply->body);
    }

can someone help please?

0 likes
3 replies
Octet's avatar

You should check that your reply is submited by checking your POST request with for example :

$this->post('/threads/' .$thread->id. '/replies', $reply->toArray())->assertOk();

It seems that for a reason your reply is actually not added to database

siewlon6093's avatar

Response status code [500] does not match expected 200 status code. Failed asserting that false is true.

Octet's avatar

It means that your test is useful !

There is something wrong with your controller which has route : /threads/{id}/replies

You could replace your test by :

    function test_an_authenticated_user_may_participate_in_forum_threads()
    {
	$this->withExceptionHandling();
        $this->be($user = factory('App\User')->create());

        $thread = factory('App\Thread')->create();

        $reply = factory('App\Reply')->make();
        $this->post('/threads/' .$thread->id. '/replies', $reply->toArray());

        $this->get($thread->path())->assertSee($reply->body);
    }

You'll be able to see any server errors

Please or to participate in this conversation.