Skip to content

First example is incorrect #36

@NigelGreenway

Description

@NigelGreenway

When trying the same as the first example you have in your README.md file, calling $this->client->response->getBody()->getContent() returns "" in my test meaning the following does not work:

$this->client->get('/');
$this->assertEquals('Hello World', $this->client->response->getBody());

Your example code:

class VersionTest extends LocalWebTestCase
{
    public function testVersion()
    {
        $this->client->get('/version');
        $this->assertEquals(200, $this->client->response->getStatusCode());
        $this->assertEquals($this->app->config('version'), $this->client->response->getBody());
    }
}

We have our own version (replicated) of WebTestCase as we have our own config and setup process.

To get it working, our test make-up is the following:

    public function testHomePage()
    {
        $body = $this->client->get('/');
        $this->assertEquals(200, $this->client->response->getStatusCode());
        $this->assertContains('Hello world', $body);
        $this->assertContains('<title>Welcome</title>', $body);
    }

The main difference with mine is that I am assigning $body = $this->client->get('/'); as ::get calls ::request but ends with return (string)$this->response->getBody();.

Am I missing something or have the docs not been updated? I can PR on the fix in the docs providing I am not missing something first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions