Что ж, простая, но грязная вещь - это подделать сбой сохранения через событие saving
:
Вот примечание от обработчика события:
public function save(array $options = [])
{
$query = $this->newModelQuery();
// If the "saving" event returns false we'll bail out of the save and return
// false, indicating that the save failed. This provides a chance for any
// listeners to cancel save operations if validations fail or whatever.
if ($this->fireModelEvent('saving') === false) {
return false;
}
....
Поэтому что-то вродедолжно работать следующее:
class TestModelSaving {
public function testSaveFailureLogs() {
// Create the fake model here
// If the event handler for saving returns false then `save()` will return false
Customer::saving(function () { return false; });
// Call your unit under test here
// Cleanup: Usually unnecessary, but some test configurations might need it
Customer::flushEventListeners();
}
}
Для проверки того, что что-то зарегистрировано, вы можете смоделировать фасад регистратора с помощью Log::shouldReceive(....)
(параметры для функции насмешки с тем же именем совпадают)