|
1 | 1 | <?php |
2 | 2 | require_once('src/ReadOnlyTrait.php'); |
3 | | -// use MichaelAChrisco\ReadOnlyTrait; |
4 | | -use Illuminate\Database\Eloquent\Model; |
| 3 | +use MichaelAChrisco\ReadOnly\ReadOnlyException, |
| 4 | + MichaelAChrisco\ReadOnly\ReadOnlyTrait, |
| 5 | + Illuminate\Database\Eloquent\Model; |
| 6 | +// use Illuminate\Database\Eloquent\Builder; |
| 7 | + |
5 | 8 | class User extends Illuminate\Database\Eloquent\Model { |
6 | | - use MichaelAChrisco\ReadOnly\ReadOnlyTrait; |
| 9 | + use ReadOnlyTrait; |
7 | 10 | } |
8 | 11 |
|
9 | 12 | describe("User", function() { |
10 | 13 | describe("::create()", function(){ |
11 | | - it("is expected to return false", function() { |
12 | | - $user = new User; |
13 | | - expect($user->create([]))->toBe(false); |
14 | | - unset($user); |
| 14 | + it("is expected to throw ReadOnlyException", function() { |
| 15 | + expect( |
| 16 | + function(){ |
| 17 | + $user = new User; |
| 18 | + $user->create([]); |
| 19 | + })->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User")); |
15 | 20 | }); |
16 | 21 | }); |
17 | 22 | describe("::forceCreate()", function(){ |
18 | | - it("is expected to return false", function() { |
| 23 | + it("is expected to throw ReadOnlyException", function() { |
| 24 | + $closure = function(){ |
19 | 25 | $user = new User; |
20 | | - expect($user->forceCreate([]))->toBe(false); |
21 | | - unset($user); |
| 26 | + $user->forceCreate([]); |
| 27 | + }; |
| 28 | + expect($closure)->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User")); |
22 | 29 | }); |
23 | 30 | }); |
24 | 31 | describe("::save()", function(){ |
25 | | - |
26 | | - it("is expected to return false", function() { |
27 | | - $user = new User; |
28 | | - expect($user->save([]))->toBe(false); |
29 | | - unset($user); |
| 32 | + it("is expected to throw ReadOnlyException", function() { |
| 33 | + expect( |
| 34 | + function(){ |
| 35 | + $user = new User; |
| 36 | + $user->save([]); |
| 37 | + })->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User")); |
30 | 38 | }); |
31 | 39 | }); |
32 | 40 | describe("::update()", function(){ |
33 | | - it("is expected to return false", function() { |
34 | | - $user = new User; |
35 | | - expect($user->update([]))->toBe(false); |
36 | | - unset($user); |
| 41 | + it("is expected to throw ReadOnlyException", function() { |
| 42 | + expect( |
| 43 | + function(){ |
| 44 | + $user = new User; |
| 45 | + $user->update([]); |
| 46 | + })->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User")); |
37 | 47 | }); |
38 | 48 | }); |
39 | 49 | describe("::firstOrCreate()", function(){ |
40 | | - it("is expected to return false", function() { |
41 | | - $user = new User; |
42 | | - expect($user->firstOrCreate([]))->toBe(false); |
43 | | - unset($user); |
| 50 | + it("is expected to throw ReadOnlyException", function() { |
| 51 | + expect( |
| 52 | + function(){ |
| 53 | + $user = new User; |
| 54 | + $user->firstOrCreate([]); |
| 55 | + })->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User")); |
44 | 56 | }); |
45 | 57 | }); |
46 | 58 | describe("::firstOrNew()", function(){ |
47 | | - it("is expected to return false", function() { |
48 | | - $user = new User; |
49 | | - expect($user->firstOrNew([]))->toBe(false); |
50 | | - unset($user); |
| 59 | + it("is expected to throw ReadOnlyException", function() { |
| 60 | + expect( |
| 61 | + function(){ |
| 62 | + $user = new User; |
| 63 | + $user->firstOrNew([]); |
| 64 | + })->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User")); |
51 | 65 | }); |
52 | 66 | }); |
53 | 67 | describe("::delete()", function(){ |
54 | | - it("is expected to return false", function() { |
55 | | - $user = new User; |
56 | | - expect($user->delete())->toBe(false); |
57 | | - unset($user); |
| 68 | + it("is expected to throw ReadOnlyException", function() { |
| 69 | + expect( |
| 70 | + function(){ |
| 71 | + $user = new User; |
| 72 | + $user->delete(); |
| 73 | + })->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User")); |
58 | 74 | }); |
59 | 75 | }); |
60 | 76 | describe("::destroy()", function(){ |
61 | | - it("is expected to return false", function() { |
62 | | - $user = new User; |
63 | | - expect($user->destroy(1))->toBe(false); |
64 | | - unset($user); |
| 77 | + it("is expected to throw ReadOnlyException", function() { |
| 78 | + expect( |
| 79 | + function(){ |
| 80 | + $user = new User; |
| 81 | + $user->destroy(1); |
| 82 | + })->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User")); |
65 | 83 | }); |
66 | 84 | }); |
67 | 85 | describe("::restore()", function(){ |
68 | | - it("is expected to return false", function() { |
69 | | - $user = new User; |
70 | | - expect($user->restore())->toBe(false); |
71 | | - unset($user); |
| 86 | + it("is expected to throw ReadOnlyException", function() { |
| 87 | + expect( |
| 88 | + function(){ |
| 89 | + $user = new User; |
| 90 | + $user->restore(); |
| 91 | + })->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User")); |
72 | 92 | }); |
73 | 93 | }); |
74 | 94 | describe("::forceDelete()", function(){ |
75 | | - it("is expected to return false", function() { |
76 | | - $user = new User; |
77 | | - expect($user->forceDelete())->toBe(false); |
78 | | - unset($user); |
| 95 | + it("is expected to throw ReadOnlyException", function() { |
| 96 | + expect( |
| 97 | + function(){ |
| 98 | + $user = new User; |
| 99 | + $user->forceDelete(); |
| 100 | + })->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User")); |
| 101 | + }); |
79 | 102 | }); |
80 | | - }); |
81 | 103 | describe("::performDeleteOnModel()", function(){ |
82 | | - it("is expected to return false", function() { |
83 | | - $user = new User; |
84 | | - expect($user->performDeleteOnModel())->toBe(false); |
85 | | - unset($user); |
86 | | - }); |
| 104 | + it("is expected to throw ReadOnlyException", function() { |
| 105 | + expect( |
| 106 | + function(){ |
| 107 | + $user = new User; |
| 108 | + $user->performDeleteOnModel(); |
| 109 | + })->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User")); |
| 110 | + }); |
87 | 111 | }); |
88 | 112 | describe("::push()", function(){ |
89 | | - it("is expected to return false", function() { |
90 | | - $user = new User; |
91 | | - expect($user->push())->toBe(false); |
92 | | - unset($user); |
93 | | - }); |
| 113 | + it("is expected to throw ReadOnlyException", function() { |
| 114 | + expect( |
| 115 | + function(){ |
| 116 | + $user = new User; |
| 117 | + $user->push(); |
| 118 | + })->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User")); |
| 119 | + }); |
94 | 120 | }); |
95 | 121 | describe("::finishSave()", function(){ |
96 | | - it("is expected to return false", function() { |
97 | | - $user = new User; |
98 | | - expect($user->finishSave([]))->toBe(false); |
99 | | - unset($user); |
100 | | - }); |
| 122 | + it("is expected to throw ReadOnlyException", function() { |
| 123 | + expect( |
| 124 | + function(){ |
| 125 | + $user = new User; |
| 126 | + $user->finishSave([]); |
| 127 | + })->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User")); |
| 128 | + }); |
101 | 129 | }); |
102 | 130 | describe("::performUpdate()", function(){ |
103 | | - it("is expected to return false", function() { |
| 131 | + it("is expected to throw ReadOnlyException", function() { |
104 | 132 | $user = new User; |
105 | 133 | //TODO: Mock up |
106 | | - // $query = new Illuminate\Database\Eloquent\Builder(''); |
107 | | - // expect($user->performUpdate($query))->toBe(false); |
| 134 | + // $user = new User; |
| 135 | + // $user->performUpdate(new Builder, []); |
108 | 136 | unset($user); |
109 | 137 | }); |
110 | 138 | }); |
111 | 139 | describe("::touch()", function(){ |
112 | | - it("is expected to return false", function() { |
113 | | - $user = new User; |
114 | | - expect($user->touch())->toBe(false); |
115 | | - unset($user); |
116 | | - }); |
| 140 | + it("is expected to throw Error", function() { |
| 141 | + expect( |
| 142 | + function(){ |
| 143 | + $user = new User; |
| 144 | + $user->touch(); |
| 145 | + })->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User")); |
| 146 | + }); |
117 | 147 | }); |
118 | 148 | }); |
119 | 149 |
|
|
0 commit comments