Dziamid
Dziamid

Reputation: 11571

Symfony: multiple applications in one test

I am writings functional tests for my projects' backend application modules. To test some features, I need to simulate user actions from frontend application. So, I created 2

sfTestFunctional instances:
$frontendBrowser = new frontendTestFunctional();
$backendBrowser = new backendTestFunctional();

These classes basically inherit from sfTestFunctional. Now, as we know, each application in symfony has its own context instance, so we have to switch to it first:

sfContext::switchTo('frontend');
//this works fine
$frontendBrowser->
  get('/home');

sfContext::switchTo('backend');
//the following fails with a misirable error: Cannot redeclare class homeComponents
$backendBrowser->
  get('/home');

So, the problem is that both pages have their own classes with the same name (homeComponents) that obviously cannot be included in one script. Is there anything I can do about it?

P.S the question is not necessarily Symfony related, so I also tag it 'php'

update: Seems like the only solution is to rename all the modules in one application, so that action and components classes have different names. But this is very involved.

Upvotes: 5

Views: 393

Answers (1)

user212218
user212218

Reputation:

You might consider breaking the test up into two distinct tests.

The first one runs the frontend application and then checks to make sure that the state of the database, session, etc. is correct.

The second test will set up the test environment to mimic the results of the frontend application completing successfully and then running the backend application and checking the result.

This will also help down the road in case regressions surface in either application; if you were to keep the tests for both applications consolidated, you would get less information from a test failure. With a separate test for each application, you will be able to find the regression more easily (since you will at least know which application is affected).

Upvotes: 1

Related Questions