S
S
Sergey Beloventsev2020-09-08 10:39:04
Laravel
Sergey Beloventsev, 2020-09-08 10:39:04

Why are laravel tests not passing?

doing feature tests

public function create()
    {
        $response= $this->actingAs($this->admin)->post('/admin/users',[
            'name'=>'Test Name',
            'email'=>'[email protected]'
        ]);
        $user=User::where('email','[email protected]')->first();
        $response->assertStatus(302)
        ->assertRedirect('/admin/users/'.$user->id);
    }

here is a route
Route::group(
    [
        'prefix' => 'admin',
        'as' => 'admin.',
        'namespace' => 'Admin',
        'middleware' => ['auth', 'can:admin-panel'],
    ],
    function () {
        ...
        Route::resource('users', 'UsersController');
        ...
    }

here is the controller
public function store(CreateRequest $request)
    {
        $user = User::new($request);
        return redirect()->route('admin.users.show', $user);
    }

but when testing I get failures
1) Tests\Feature\Admin\UserTest::create
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'http://localhost/admin/users/9e364fb9-6079-473b-b449-9fe9bd4992cb'
+'http://localhost'
/www/app/vendor/laravel/framework/src/Illuminate/Testing/TestResponse.php:260
/www/app/vendor/laravel/framework/src/Illuminate/Testing/TestResponse.php:205
/www/app/tests/Feature/Admin/UserTest.php:64

and even the server is raised through docker
, please explain why there are errors with the redirect?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Shamanov, 2020-09-08
@Sergalas

because your id's don't match

K
Korya, 2020-09-24
@Korya

public function store(CreateRequest $request)
    {
        $user = User::new($request);
        $user->save();
        return redirect()->route('admin.users.show', $user);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question