Add Insert emptyTable and Truncate to blocks (#16)

* Update ReadOnlyTrait.php
* Added truncate, insert
* Added Truncate and insert
* Update README.md
This commit is contained in:
aptdavid 2017-03-29 13:15:48 -04:00 committed by Michael Chrisco
parent 3e39985b40
commit 4854827098
3 changed files with 40 additions and 0 deletions

View file

@ -45,6 +45,8 @@ $result = $legacyUser->save();
* finishSave
* performUpdate
* touch
* insert
* truncate
## TODO:
* saveOrFail

View file

@ -145,6 +145,24 @@ describe("User", function() {
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
});
});
describe("::truncate()", function(){
it("is expected to throw Error", function() {
expect(
function(){
$user = new User;
$user->truncate();
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
});
});
describe("::insert()", function(){
it("is expected to throw Error", function() {
expect(
function(){
$user = new User;
$user->insert();
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
});
});
});

View file

@ -161,4 +161,24 @@ trait ReadOnlyTrait {
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
}
/**
* throws ReadOnlyException on insert
* @method insert
*
*/
public function insert(){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
}
/**
* throws ReadOnlyException on truncate
* @method truncate
*
*/
public function truncate(){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
}
}