Reputation: 11887
I would like to know whether the setting null
to variables in the tearDown
methods within PHPUnit_Framework_TestCase
and children is a mere formality or serves some actual purpose.
Example:
protected function tearDown(){
$this->someUsedVariable=null;
}
P.S.: I mean, don't used variables get destroyed anyway by the end of the script?
Upvotes: 2
Views: 516
Reputation: 6536
the variables get destroyed after the end of the script. tearDown can be helpful to delete the data produced during the test for examples, data in the database or generated files.
Upvotes: 3
Reputation: 34234
Of course they are destroyed at the end of the script. Once you started your test suite your script does not end directly, because you'll probably have hundrets or thousands of test cases being executed and all those test cases together will sooner or later use up all memory / fill up the max. number of connections to a database (etc.) if not properly teared down.
By setting variables to null you allow the garbage collector, once activated, to free up the used memory.
Upvotes: 4