I'm writing unit tests for a project I'm working on and I'm trying to figure out how to effectively write tests to test this.
I currently have the following methods:
- Object::createNew()
- Object->delete()
My concern is how do I write unit tests to properly test this effectively because I'm having a hard time thinking about how to "tie" these functions together. So for example,
<?php
public function testObjectCreation() {
$object = Object::createNew("my parameters");
// ... asserts
// I don't want to keep the object so I delete it
// but I don't want test that deleting works here too, I want to separate it
$object->delete();
}
// Where would I get an object to test that deleting works?
public function testObjectDeletion() {
// ...stuff
$object->delete();
}
public function testUnrelatedObjectFunctions () {}
So my question is, how could I feed one object to the other function. Would I have to make testObjectCreation() be static and then feed it to testObjectDeletion() with @dataProvider or would I have to store $object in a private/protected variable that would only be used in these two functions? If I make it static, wouldn't I lose access to the assert functions provided by PHPUnit?