From 48548270989a2dfcb4e825705322df681e976eb7 Mon Sep 17 00:00:00 2001 From: aptdavid Date: Wed, 29 Mar 2017 13:15:48 -0400 Subject: [PATCH] Add Insert emptyTable and Truncate to blocks (#16) * Update ReadOnlyTrait.php * Added truncate, insert * Added Truncate and insert * Update README.md --- README.md | 2 ++ spec/ReadOnlyTraitSpec.php | 18 ++++++++++++++++++ src/ReadOnlyTrait.php | 20 ++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/README.md b/README.md index 0deb594..2b2b334 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ $result = $legacyUser->save(); * finishSave * performUpdate * touch + * insert + * truncate ## TODO: * saveOrFail diff --git a/spec/ReadOnlyTraitSpec.php b/spec/ReadOnlyTraitSpec.php index 3076f92..5a39c67 100644 --- a/spec/ReadOnlyTraitSpec.php +++ b/spec/ReadOnlyTraitSpec.php @@ -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")); + }); + }); }); diff --git a/src/ReadOnlyTrait.php b/src/ReadOnlyTrait.php index b6f2cc2..cebf653 100644 --- a/src/ReadOnlyTrait.php +++ b/src/ReadOnlyTrait.php @@ -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}"); + } }