PhpUnit测试很长

时间:2015-03-05 10:02:27

标签: symfony phpunit

我正在使用Symfony2中的PHPUnit进行一些功能测试。

我使用PHPUnit版本4.4.1,使用控制器生成创建测试(doctrine:generate:crud)

所以,我只测试一个用户的CRUD,它花了我超过30秒(这在30到40秒之间变化)。这来自代码吗?测试自己?我在远程服务器上工作的事实?

这是测试类:

 class UserControllerTest extends WebTestCase
{
/**
 * Test CRUD functions (Create, read, update, delete)
 */
public function testCompleteScenario()
{
    // Create a new client to browse the application
    $client = static::createClient();

    // Create a new entry in the database
    $crawler = $client->request('GET', '/user/');
    $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /user/");
    $crawler = $client->click($crawler->selectLink('Create a new entry')->link());

    // Fill in the form and submit it
    $form = $crawler->selectButton('Create')->form(array(
        's_dosfabbundle_user[login]'  => 'test.test',
        's_dosfabbundle_user[trigram]'  => 'tet',
        's_dosfabbundle_user[email]'  => 'test@test.com',
        's_dosfabbundle_user[productionUnits]'  => '11',
        's_dosfabbundle_user[roles]'  => '55',
    ));

    $client->submit($form);
    $crawler = $client->followRedirect();

    // Check data in the show view
    $this->assertGreaterThan(0, $crawler->filter('td:contains("test.test")')->count(), 'Missing element td:contains("test.test")');

    // Edit the entity
    $crawler = $client->click($crawler->selectLink('Edit')->link());

    $form = $crawler->selectButton('Update')->form(array(
         's_dosfabbundle_user[login]'  => 'test.testUpdate',
        's_dosfabbundle_user[trigram]'  => 'tetU',
        's_dosfabbundle_user[email]'  => 'test_update@test.com',
        's_dosfabbundle_user[productionUnits]'  => '11',
        's_dosfabbundle_user[roles]'  => '57',
    ));

    $client->submit($form);
    $crawler = $client->followRedirect();

    // Check the element contains an attribute with value equals "Foo"
    $this->assertGreaterThan(0, $crawler->filter('[value="tetU"]')->count(), 'Missing element [value="tetU"]');

    // Delete the entity
    $client->submit($crawler->selectButton('Delete')->form());
    $crawler = $client->followRedirect();

    // Check the entity has been delete on the list
    $this->assertNotRegExp('/tetU/', $client->getResponse()->getContent());
}

 }

1 个答案:

答案 0 :(得分:0)

只是在黑暗中拍摄,因为需要更多信息,但我遇到了同样的问题。如果您已启用xdebug,则可以尝试禁用它,请参阅disabling xdebug。这当然只有在您没有将它用于代码覆盖(这总是需要很长时间)等事情时才有意义。