Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to assert view data from Tests

The current response returned from Phalcon\Http\Client\Response is contains body, header, statusCode etc but how can we test the data passed into the view file?

One solution can be asserting the html but that doesn't work with paginated views.

Any suggestions?

you can use an event to do this

Is there a way to send it back with the response directly?

This is my test:

public function homepage_renders_propoerly()
  $provider = Request::getProvider();

  $response = $provider->get('/');

  $this->assertEquals(200, $response->header->statusCode);

Just reached half of the solution:

If I use the application handle method instead of the provider(got this from the phalcon incubator code) then the di is getting updated and the view params can be fetched

$response = $this->application->handle('/');

$this->assertContains('test variable', $this->di->getView()->getParamsToView());

However I'm not able to create a request as post, put or patch. Any solutions for that? Is this approach correct?


I'm able to make it a post request by overriding the $_SERVER variables.

so the solution is:

$response = $this->application->handle('/');

$this->assertContains('test variable', $this->di->getView()->getParamsToView());