In my job I have a small disagreement on whether we should utilize helper functions for making datasets especially in laravel
framework. A sample for the test is:
namespace Tests\MyAppTests;
use PHPUnit\Framework\TestCase;
use Carbon\Carbon;
class MyTest extends TestCase
{
private function makeATwoHourSpan(Carbon $now, &$start, &$end)
{
$start = new Carbon($now);
$start->modify("-1 hour");
$end = new Carbon($now);
$end->modify("+1 hour");
}
public function testSomething()
{
$now=Carbon::now();
$start=null;
$end=null;
this->makeATwoHourSpan($now, $start, $end);
//Rest Of Test Here
}
public function testSomethingElse()
{
$now=Carbon::now();
$start=null;
$end=null;
this->makeATwoHourSpan($now, $start, $end);
//Rest Of Test Here
}
}
The argument that my supervisor says is that using the makeATwoHourSpan
method even though makes the code DRY it does not aid the readability of the test. Also he mentioned that a test should be autonomous and a easy to run as standalone without any helper function except the tools provided from the framework.
So my question is: Should I avoid utilizing "helper" functions especially when I make test data when I make tests, or having a function for data creation makes is the way to go?