我有一个测试套件PHPUnit的我的symfony应用程序。 在该测试文件,我有不同的测试之间的一些依赖,并通过依赖之间的DOMCrawler对象,这样我就不用每次都来找到它。
然而,在考虑,我没有办法,看来你不能提交与这些传递的对象形式,但你可以点击他们的链接。 是否有一个原因? 是我设计的只是可怜的,如果是这样,我应该如何改变呢? 欢迎任何的反馈。 我下面附加了一些代码。
<?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...
}
}