0
votes

I'm starting to look into testing so thought id do something simple like see if a page loads correctly.

Here is my test;

<?php

use App\Users\Models\User;

class BlogPostsTest extends TestCase {

    protected $baseUrl = 'http://localhost:8000';

    public function testBlogPostsAreAccessible()
    {
        $this->be( User::findOrFail(1) );
        $response = $this->call( 'GET', '/admin/blog-posts' );
        $this->assertEquals( 200, $response->getStatusCode() );
    }

}

Which returns and error

1) BlogPostsTest::testBlogPostsAreAccessible Error: Call to undefined method Symfony\Component\Debug\Exception\FatalThrowableError::getStatusCode()

/Users/ss/git/modules/admin/admin-blog/app/Exceptions/Handler.php:77 /Users/ss/git/modules/admin/admin-blog/app/Exceptions/Handler.php:58 /Users/ss/git/modules/admin/admin-blog/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:291 /Users/ss/git/modules/admin/admin-blog/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:107 /Users/ss/git/modules/admin/admin-blog/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:515 /Users/ss/git/modules/admin/admin-blog/tests/ExampleTest.php:12

FAILURES! Tests: 1, Assertions: 0, Errors: 1.

The error is coming from $this->call() does anyone know why this is?

regards

1

1 Answers

0
votes

Are you sure your 'admin/blog-posts' returns an actual response object? Can you dd() the output in your test? So:

dd($response);

To see what it is your code is returning?