I've got a function that generates a matrix of date pairs. specifically, it takes two dates and adds the 31 day ranges to an array, so roughly, it would look like: [[date, date+31], [date, date+31], ...]
I'm using a recursive function to do it:
public function getBatchDates(Carbon $start, Carbon $end, array $arr) {
$setEnd = Carbon::createFromTimestamp($start->getTimestamp())->addDays(31);
if($setEnd->greaterThanOrEqualTo($end)) {
$setEnd = $end;
array_push($arr, array($start, $setEnd));
return;
}
array_push($arr, array($start, $setEnd));
$this->getBatchDates($setEnd, $end, $arr);
}
Now, when I debug the test that calls this function, it seems to work correctly:
However, the test, which is roughly as follows:
$array = array();
getBatchDates(new Carbon("first day of December 2015"),Carbon::now(), $array);
$this->assertNotNull($array);
$this->assertGreaterThan(0, sizeof($array));
It fails, because the $array
is 0-length. Is there something I'm missing, the debugger makes it look like things are working.