Is it ok to create a single object instance and storing it in a private or static property?
I mean, most of the examples out there will create one instance per test. In the other hand, this seems like a waste of resources to me.
Here is an example:
use PHPUnit\Framework\TestCase;
class MyClassTest extends TestCase
{
private $obj;
public function testFoo()
{
$this->assertEquals($this->obj->foo(), 'something');
}
public function testBar()
{
$this->assertEquals($this->obj->bar(), 'something else');
}
public function __construct()
{
$this->obj = new MyClass();
}
}
Is this a bad thing or could it cause any unexpected behaviour?
Aucun commentaire:
Enregistrer un commentaire