Lestah's avatar
Level 11

Laravel Feature Test

Im trying this test but it says failed asserting that false is true this is just a simple test so user can visit the settings page


/**
     *
     * @test
     * @group  feature
     * @group  feature:setting
     * @group  settings.preferences
     * @return void
     */
    public function a_user_can_visit_the_settings_page()
    {
        // Arrangements
        // $this->withoutExceptionHandling();
        $this->actingAs($user = $this->superAdmin);
        $settings = factory(Setting::class, 5)->create();

        // Actions
        $response = $this->get(route('settings.index'));

        // Assertions
        $response->assertSuccessful()
                 ->assertViewHas('settings')
                 ->assertViewIs('setting::admin.index');
    }

0 likes
6 replies
kevinbui's avatar

Does it say any errors when you uncomment $this->withoutExceptionHandling()?

Lestah's avatar
Level 11

yes the same error Response status code [302] is not a succesful status code. failed asserting that false is true i think it has something to do with my $response = $this->get(route('settings.index'));

kevinbui's avatar

Can you post the controller code as well?

There's nothing wrong with status code 302, its a redirect response. You may want to change the assertions to something like this:

$response->assertStatus(302)
                 ->assertViewHas('settings')
                 ->assertViewIs('setting::admin.index');
Lestah's avatar
Level 11

<?php

namespace Setting\Http\Controllers;

use Core\Http\Controllers\AdminController;
use Illuminate\Http\Request;
use Setting\Services\SettingServiceInterface;

class SettingsController extends AdminController
{
    /**
     * Create a new controller instance.
     *
     * @param \Setting\Services\SettingServiceInterface $service
     */
    public function __construct(SettingServiceInterface $service)
    {
        $this->service = $service;
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $settings = $this->service()->all();

        return view('setting::admin.index')->withResources($settings);
    }

Lestah's avatar
Level 11

i tried

$response->assertStatus(302)

it says the response is not a view

Lestah's avatar
Level 11

here's the route


<?php

Route::namespace('Settings')->prefix('settings')->group(function () {
    Route::get('branding', 'ShowBranding')->name('settings.branding');
    Route::get('preferences', 'ShowPreference')->name('settings.preferences');
});

Route::get('settings', 'Settings\RedirectSettings')->name('settings.index');
Route::post('settings', 'SettingsController@store')->name('settings.store');

Please or to participate in this conversation.