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

treadnought's avatar

Testing error on Laravel Forum

I'm trying to set up Edit Post functionality in the tutorial project https://laracasts.com/series/build-a-forum-with-laravel I am working on a clone of branch episode_51; nothing changed at all except I've added extra Post resource routes edit and update, as well as a new test file EditPost.php.

Here's my web.php route:

Route::middleware([
    'auth',
    config('jetstream.auth_session'),
    'verified',
])->group(function () {
    Route::get('/dashboard', function () {
        return Inertia::render('Dashboard');
    })->name('dashboard');

    Route::resource('posts', PostController::class)->only(['create', 'store', 'edit', 'update', 'destroy']);
    Route::resource('posts.comments', CommentController::class)->shallow()->only(['store', 'update', 'destroy']);

    Route::post('/likes/{type}/{id}', [LikeController::class, 'store'])->name('likes.store');
    Route::delete('/likes/{type}/{id}', [LikeController::class, 'destroy'])->name('likes.destroy');
});

And here's my EditPost.php test:

<?php
use App\Models\Post;
use function Pest\Laravel\get;

it('requires authentication', function () {
    get(route('posts.edit', [Post::factory()->create()]))->assertRedirect(route('login'));
});

Why am I getting this error:

   FAIL  Tests\Feature\Controllers\PostController\EditTest
  ⨯ it requires authentication                                                                              2.67s  
  ───────────────────────────────────────────────────────────────────────────────────────────────────────────────  
   FAILED  Tests\Feature\Controllers\PostController\EditTest > it requires authenticati…  CommunicationException   
  cURL error 7: Failed to connect to 127.0.0.1 port 7700 after 2020 ms: Couldn't connect to server (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://127.0.0.1:7700/indexes/posts/documents?primaryKey=id

  at vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:210
    206▕         }
    207▕
    208▕         // Create a connection exception if it was a specific error code.
    209▕         $error = isset($connectionErrors[$easy->errno])
  ➜ 210▕             ? new ConnectException($message, $easy->request, null, $ctx)
    211▕             : new RequestException($message, $easy->request, $easy->response, null, $ctx);
    212▕
    213▕         return P\Create::rejectionFor($error);
    214▕     }

  1   vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:210
  2   vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:158


  Tests:    1 failed (0 assertions)
  Duration: 2.80s
0 likes
6 replies
Nakov's avatar

Does any test works and just this one does not? Because I see you have issues with your test setup. It tries to connect to a service on port 7700 which is not running.

So how are you running your project? php artisan serve? If so, then you will have to have it running in another terminal window I guess. And then run your tests.

treadnought's avatar

@Nakov I'm using a clone of the course source code. All the other tests work fine. I'm using Herd, and running npm run dev to serve the project.

Nakov's avatar

@treadnought I cloned the project now, and tried the tests. And as I said above, you will have to have npm run dev running in one terminal window, and run the tests in another window in order to work.

treadnought's avatar

@Nakov Unfortunately fhat leads to the same error (just in the edit test that I set up, all the others pass). Would it be possible for you to try my code (or tell me what I've done wrong of course :))

Nakov's avatar
Nakov
Best Answer
Level 73

@treadnought I copied your code from above. I just did run npm run build and then pest and the test succeeded. If I change it to status 200 it fails as expected:

https://snipboard.io/5eD9nm.jpg

With the redirect https://snipboard.io/slZS3Q.jpg

Please or to participate in this conversation.