jeudi 23 juillet 2015

Depending on previous tests - Symfony

In summary - I want testIndex() to run first and handle logging into the app. There's no point logging in again in my view, so I'd like testEdit() to just continue on from the first test without having to log in again.

I have tried @depends on testEdit() and returned $crawler, and passed it into testEdit() - but it tried to log in again. I don't know how to get around this. For now, I'm just logging in twice (once in each test) but I'd really like to avoid doing that and just log in once.

Any ideas are appreciated. Thanks.

Parent class:

public function logIn($client, $crawler, $administrator = true)
{
    $administrator = ($administrator) ? UserData::newAdminUser() : UserData::newRegularUser();
    $form = $crawler->selectButton('Login')->form();

    $form['_username'] = $administrator['username'];
    $form['_password'] = $administrator['password'];

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

    return $crawler;
}

Test fixture:

public function testIndex()
{
    $client = parent::createTestClient();

    $crawler = $client->request('GET', self::USER_INDEX_PATH);
    $crawler = parent::logIn($client, $crawler);

    ...
}

public function testEdit()
{
    $client = parent::createTestClient();

    $crawler = $client->request('GET', self::USER_EDIT_PATH);
    $crawler = parent::logIn($client, $crawler);

    ...
}

Aucun commentaire:

Enregistrer un commentaire