there4 / slim-test-helpers

Integration testing helpers for the Slim Framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

First example is incorrect

NigelGreenway opened this issue · comments

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.

It will be next week before I can investigate this. I don't particularly like having to fetch into a temporary $body variable. It sounds like something else may be going on.

Hi @craig-davis, no worries. If I can get chance I will clone and see what I can find if that helps, but I too am pretty stretched out with spare time at the moment.

I've made you a contributor. If you're blocked by something, go ahead and be a responsible member of the group :)

@craig-davis thank you, much appreciated.