Managed to solve it. I wasn't passing in the mocked instance of carbon. So although I was passing in the correct class path it didn't work. I got the idea of checking from here http://stackoverflow.com/questions/27745950/mocked-class-not-accepting-instance-of-carbon
So my simplified code now looks like Test
use Carbon\Carbon;
use Mockery as m;
class MedicationTest extends TestCase
{
public $carbon;
public function setUp()
{
$this->carbon = m::mock(Carbon::class);
$this->carbon->shouldReceive('addDays')->once();
}
public function test_we_get_days_of_prescription_remaining()
{
$med = new \MPC\Models\Medication();
$med->getDaysOfPrescriptionRemaining($this->carbon);
}
}
CUT
namespace MPC\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
class Medication extends Model
{
public $timesTakenPerTimePeriod;
public $howManyTakenPerTime;
public $timePeriodTakenOver;
public $unitsPerPrescription;
public $datePrescriptionLastFilled;
protected $table = 'medication';
protected $fillable = [
'user_id',
'name',
'RXCUI',
'preferredName',
'sizeOfEachUnit',
'unitOfMeasurement',
'howManyTakenPerTime',
'timesTakenPerTimePeriod',
'timePeriodTakenOver',
'unitsPerPrescription',
'datePrescriptionLastFilled',
'reminder',
'remarks'
];
public function getCarbonDate()
{
return new \Carbon\Carbon();
}
public function getDaysOfPrescriptionRemaining(Carbon $carbon)
{
return $carbon->addDays(25);
}
}
It obviously needs tidying up and the original (non-simplified) code putting back in there but that can wait until tomorrow. ps I am aware that I could use a $dates property and get a Carbon date by default but this way the test has more isolation.