I have a test suite for phpunit for my symfony application. In that test file, I have some dependencies between different tests, and pass a DOMCrawler object between the dependent so that I don't have to navigate to it each time.
However, in taking the approach that I did, It seems that you cannot submit forms with these passed objects, but you can click on the links on them. Is there a reason for this? Is my design just poor and if so, how should I change it? Any feedback is welcome. I've attached some code below.
<?php
namespace someBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
* blah Controller Test
*
*/
class BlahControllerTest extends WebTestCase
{
private $adminUrl;
/**
* Constructs basic information for a audit report controller test suite
*
*/
public function __construct()
{
$this->adminUrl = '/admin/';
}
/**
* Starts a test suite
*
* @return Crawler
*/
public function testAdd()
{
// Create a new client to browse the application
$client = static::createClient();
// Go to site specific admin url
$crawler = $client->request('GET', $this->adminUrl);
$this->assertTrue(200 === $client->getResponse()->getStatusCode());
// do stuff here
// goes to edit page
$crawler = $client->request('GET', $editPage);
return $crawler;
}
/**
* Tests the edit functionality
*
* @param Crawler $crawler Crawler for the show view
*
* @depends testAdd
*/
public function testEdit($crawler)
{
// Create a new client to browse the application
$client = static::createClient();
//Line below is included if the crawler points to the show view
//$crawler = $client->click($crawler->selectLink('Edit')->link());
// Fill in the form and submit it
$form = $crawler->selectButton('Edit')->form(array(
$foo => $bar,
));
// The following line doesn't work properly if testEdit is passed the
// edit page. However, if it is passed the show page, and the
// edit link above is clicked, then the form will submit fine.
$client->submit($form);
$crawler = $client->followRedirect();
// more code here...
}
}