3

I'm doing some functional testing with PHPUnit in Symfony2 .

I use PHPUnit version 4.4.1 ,tests were created with the controller generation (doctrine:generate:crud)

So , I only tests the CRUD on an User, and it takes me more than 30 seconds (This varies between 30 and 40s ) . Is this comes from the code? Tests themselves ? The fact that I worked on a remote server?

Here is the test class :

 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());
}

 }
Matteo
  • 37,680
  • 11
  • 100
  • 115
Nanis
  • 361
  • 6
  • 18
  • can you investigate in which point spent much time? trivially simply put a die after some point and see what appen. BTW from the logs `app/log/test.log` see something strange? – Matteo Mar 05 '15 at 10:08
  • If I look test.log nothing spent much time than another. I don't know if you want to see it ? – Nanis Mar 05 '15 at 10:24

1 Answers1

0

Just a shot in the dark, as more info is needed, but I had the same issue. If you've got xdebug enabled, you could try disabling it, see disabling xdebug. This is of course only relevant if you're not using it for things like code coverage (which always takes quite a while).

Community
  • 1
  • 1
Frank van Luijn
  • 470
  • 4
  • 16