Expected status code 200 but received 302. Failed asserting that false is true. using phpunit test in laravel 5.4

Hi i have this page which is /dno-personal/cebu-properties. I tried to run in using PHPUNIT test in my laravel. Now i created this test file below

<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Http\Response;


class DnoPersonalTest extends TestCase
{
/**
* A basic test example.
*
* @test
*/
public function add_cebu_properties_page()
{


$response = $this->get('/dno-personal/cebu-properties');
$response->assertStatus(200);

}
}

Now in my route file i i did not create a route for dno-personal/cebu-properties yet which i run test into my phpunit it throws an error of

Expected status code 200 but received 404.
Failed asserting that false is true.

C:\xampp\htdocs\dnogroup\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestResponse.php:79
C:\xampp\htdocs\dnogroup\tests\Feature\DnoPersonalTest.php:24

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

which i think is okay cause i have no route yet which throws an error of 404. Now when i add into the route

Route::get('/dno-personal/cebu-properties',
'DnoPersonalController@cebuProperties')
->name('dno-personal.cebuProperties');

without a method into my controller cebuProperties when i run test PHPUNIT it throws

Expected status code 200 but received 302.
Failed asserting that false is true.

C:\xampp\htdocs\dnogroup\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestResponse.php:79
C:\xampp\htdocs\dnogroup\tests\Feature\DnoPersonalTest.php:24

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

it throws an error of 302. Now i want that it throws the method is not yet created instead of 302. now when i add $this->withoutExceptionHandling(); this throws me an error

PHP Fatal error:  Call to undefined method Tests\Feature\DnoPersonalTest::withoutExceptionHandling() in C:\xampp\htdocs\dnogroup\tests\Feature\DnoPersonalTest.php on line 22

In DnoPersonalTest.php line 22:

Call to undefined method Tests\Feature\DnoPersonalTest::withoutExceptionHandling()



Fatal error: Call to undefined method Tests\Feature\DnoPersonalTest::withoutExceptionHandling() in C:\xampp\htdocs\dnogroup\tests\Feature\DnoPersonalTest.php on line 22

it cannot see the $this->withoutExceptionHandling(); can someone help me figured this out? Any help is muchly appreciated. TIA



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3cCZEZQ
via IFTTT

تعليقات

المشاركات الشائعة من هذه المدونة

I am unable to figure out how to create payment collection request, after a form has been submitted in laravel

laravel, mysql transaction not working after failed one time