mirror of
https://github.com/michaelachrisco/ReadOnlyTraitLaravel.git
synced 2024-12-26 15:47:21 -08:00
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:
parent
3e39985b40
commit
4854827098
3 changed files with 40 additions and 0 deletions
|
@ -45,6 +45,8 @@ $result = $legacyUser->save();
|
||||||
* finishSave
|
* finishSave
|
||||||
* performUpdate
|
* performUpdate
|
||||||
* touch
|
* touch
|
||||||
|
* insert
|
||||||
|
* truncate
|
||||||
|
|
||||||
## TODO:
|
## TODO:
|
||||||
* saveOrFail
|
* saveOrFail
|
||||||
|
|
|
@ -145,6 +145,24 @@ describe("User", function() {
|
||||||
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
|
})->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"));
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -161,4 +161,24 @@ trait ReadOnlyTrait {
|
||||||
$class = get_called_class();
|
$class = get_called_class();
|
||||||
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$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}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue