Any way to preserve instance variables between phpunit tests?

Viewed 8202

I'm writing functional tests for a SOA system so need to test a backend subsystem from the frontend.

It's a standard CRUD system. I have a test that tests I can create an object, and it returns me the ID of the new object. In subsequent tests I want to edit and then delete this object, but phpunit seems to be re-instantiating the test class each time, so I lose my instance variables.

How can I achieve this? Running functional tests on each server in the architecture isn't an option.

4 Answers

Use setUp() method of TestCase class.

protected function setUp(): void
{
    parent::setUp();
    //init something
}
Related