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.
One way to pass stuff between tests is to use the @depends
annotation
public function testCreate() { //... return $id; } /** * @depends testCreate */ public function testDelete($id) { // use $id }
if you do it like that the "delete" test will be skipped if the creation doesn't work.
So you will only get one error if the service doesn't work at all instead of many failing tests.
If you don't want to do that or that doesn't match your case for whatever reason static class variables can also be an option, but you should be really sure that you know you absolutely need them :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With