I'm adding test coverage to an API built in Symfony. I have an ApiControllerTest
that is extending Symfony's WebTestCase
, and performs tests on the different controller actions of the API controller. Please note these are functional tests so they are calling controller routes and and saving to the database.
I want the tests to run in a specific order. For example, there are API methods to save a project, match that project to another, add a requirement to that project, delete that project, etc. I understand that unit tests should not depend on each other, but it seems functional tests can. Instead of having set up and tear down methods that manually add / delete a project before and after every test, it would be much more efficient to save a project in the first test, then have subsequent tests update, delete, etc. for that project.
I have looked at Run PHPUnit Tests in Certain Order and tried using the @depends
annotation, but this does not work (I'm not trying to pass the result of one test to another). Also, I've seen that you can specify the order for separate classes to run, but it seems like these tests are all related and belong in a single class, as they are testing a single controller (I typically have one test class per controller class, service class, etc. that I'm testing)
Is there a way using PHPUnit or Symfony's WebTestCase
to specify the order that tests within a specific class should run? Or I'm a way off base on the design pattern here and need to use a different approach?