slim-test-helpers icon indicating copy to clipboard operation
slim-test-helpers copied to clipboard

First example is incorrect

Open NigelGreenway opened this issue 8 years ago • 4 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.

NigelGreenway avatar Feb 09 '17 16:02 NigelGreenway

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.

craig-davis avatar Feb 09 '17 18:02 craig-davis

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.

NigelGreenway avatar Feb 09 '17 18:02 NigelGreenway

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

craig-davis avatar Feb 09 '17 21:02 craig-davis

@craig-davis thank you, much appreciated.

NigelGreenway avatar Feb 10 '17 11:02 NigelGreenway