I've been using Laravel and Symfony for a while and I'm very happy with the testing with DomCrawler. Now at work I'm using CakePHP 3, and I'm not comfortable with the integration testing system, it's like this:
$this->get('/miweb/add-page/rates/2');
$this->assertResponseOk();
$this->assertResponseContains( 'precio' );
$this->post('/miweb/add-page/rates/2', $data);
$this->assertResponseContains( '30€' );
$this->assertResponseContains( '90€' );
I've been looking for a way to integrate DomCrawler in the testing system, so that I could use $crawler->filter('body > p');
, $form->submit()
and all the functionality, but I've accomplished nothing. Has anyone done this? Is it possible?
What I've done so far is this:
<?php
class BaseIntegrationTestCase extends IntegrationTestCase
{
public function get( $url )
{
$result = parent::get($url);
$crawler = new Crawler();
$crawler->addContent($this->_response);
return $crawler;
}
public function post($url, $data = [])
{
$result = parent::post($url, $data);
$crawler = new Crawler();
$crawler->addContent($this->_response);
return $crawler;
}
}
And then extend my Class in the tests, but it doesn't work...