What does the 500 error say?
If it doesn't say anything useful. try adding $this->withoutExceptionHandling(); at the top of your test.
In my test, I'm expecting a 200 status, not 500. I can go to the page in question just fine in my localhost. So it seems to be a test problem, not a problem with the website. I just want to use one of my existing admins in the database and use that for the test, not using fakers or any of that.
I have a very similar question from back in my post history, but it doesn't seem to be the same solution.
Anyway, the test method in question:
namespace Tests\Feature\admin;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
use App\Admin;
use App\User;
use App\SuperAdmin;
use App\Dish;
class AddSelectionPageTest extends TestCase
{
use DatabaseTransactions;
use WithoutMiddleware;
/** @test **/
public function add_new_selection_page_loads_correctly()
{
$this->refreshApplication();
$admin = Admin::find(1);
$response = $this->actingAs($admin, 'admin')
->get('admin/my-dishes/1/selections/add') // Works just fine if I shorten this to 'admin/my-dishes'
->assertStatus(200);
}
I also have different tests in different files that look very similar, and they work fine. For instance-
use DatabaseTransactions;
use WithoutMiddleware;
/** @test **/
public function admin_can_access_page()
{
$this->refreshApplication();
$admin = Admin::find(1);
$response = $this->actingAs($admin, 'admin')
->get('admin/my-restaurants/create')
->assertStatus(200)
->assertSee('Apply to add a new res');
}
@alexlegard Then try adding the withoutExceptionHandling call, it turns off Laravels exception handling and gives better errors. You have a code error somewhere in your controller, model or view.
Please or to participate in this conversation.