2323#[Group('DatabaseLive ' )]
2424final class EventsModelTest extends LiveModelTestCase
2525{
26- /**
27- * @var EventModel
28- */
29- protected $ model ;
30-
3126 protected function setUp (): void
3227 {
3328 parent ::setUp ();
3429 $ this ->createModel (EventModel::class);
3530 }
3631
32+ private function model (): EventModel
33+ {
34+ $ this ->assertInstanceOf (EventModel::class, $ this ->model );
35+
36+ return $ this ->model ;
37+ }
38+
3739 public function testInsertEvent (): void
3840 {
3941 $ data = [
@@ -43,9 +45,9 @@ public function testInsertEvent(): void
4345 'deleted ' => 0 ,
4446 ];
4547
46- $ this ->model ->insert ($ data );
47- $ this ->assertTrue ($ this ->model ->hasToken ('beforeInsert ' ));
48- $ this ->assertTrue ($ this ->model ->hasToken ('afterInsert ' ));
48+ $ this ->model () ->insert ($ data );
49+ $ this ->assertTrue ($ this ->model () ->hasToken ('beforeInsert ' ));
50+ $ this ->assertTrue ($ this ->model () ->hasToken ('afterInsert ' ));
4951 }
5052
5153 public function testUpdateEvent (): void
@@ -57,106 +59,106 @@ public function testUpdateEvent(): void
5759 'deleted ' => 0 ,
5860 ];
5961
60- $ id = $ this ->model ->insert ($ data );
62+ $ id = $ this ->model () ->insert ($ data );
6163
62- $ this ->model ->update ($ id , $ data );
63- $ this ->assertTrue ($ this ->model ->hasToken ('beforeUpdate ' ));
64- $ this ->assertTrue ($ this ->model ->hasToken ('afterUpdate ' ));
64+ $ this ->model () ->update ($ id , $ data );
65+ $ this ->assertTrue ($ this ->model () ->hasToken ('beforeUpdate ' ));
66+ $ this ->assertTrue ($ this ->model () ->hasToken ('afterUpdate ' ));
6567 }
6668
6769 public function testDeleteEvent (): void
6870 {
69- $ this ->model ->delete (1 );
70- $ this ->assertTrue ($ this ->model ->hasToken ('beforeDelete ' ));
71- $ this ->assertTrue ($ this ->model ->hasToken ('afterDelete ' ));
71+ $ this ->model () ->delete (1 );
72+ $ this ->assertTrue ($ this ->model () ->hasToken ('beforeDelete ' ));
73+ $ this ->assertTrue ($ this ->model () ->hasToken ('afterDelete ' ));
7274 }
7375
7476 public function testFindEvent (): void
7577 {
76- $ this ->model ->find (1 );
77- $ this ->assertTrue ($ this ->model ->hasToken ('beforeFind ' ));
78- $ this ->assertTrue ($ this ->model ->hasToken ('afterFind ' ));
78+ $ this ->model () ->find (1 );
79+ $ this ->assertTrue ($ this ->model () ->hasToken ('beforeFind ' ));
80+ $ this ->assertTrue ($ this ->model () ->hasToken ('afterFind ' ));
7981 }
8082
8183 public function testBeforeFindReturnsData (): void
8284 {
83- $ this ->model ->beforeFindReturnData = true ;
85+ $ this ->model () ->beforeFindReturnData = true ;
8486
85- $ result = $ this ->model ->find (1 );
86- $ this ->assertTrue ($ this ->model ->hasToken ('beforeFind ' ));
87+ $ result = $ this ->model () ->find (1 );
88+ $ this ->assertTrue ($ this ->model () ->hasToken ('beforeFind ' ));
8789 $ this ->assertSame ('foobar ' , $ result );
8890 }
8991
9092 public function testBeforeFindReturnDataPreventsAfterFind (): void
9193 {
92- $ this ->model ->beforeFindReturnData = true ;
93- $ this ->model ->find (1 );
94- $ this ->assertFalse ($ this ->model ->hasToken ('afterFind ' ));
94+ $ this ->model () ->beforeFindReturnData = true ;
95+ $ this ->model () ->find (1 );
96+ $ this ->assertFalse ($ this ->model () ->hasToken ('afterFind ' ));
9597 }
9698
9799 public function testFindEventSingletons (): void
98100 {
99101 // afterFind
100- $ this ->model ->first ();
101- $ this ->assertTrue ($ this ->model ->eventData ['singleton ' ]);
102+ $ this ->model () ->first ();
103+ $ this ->assertTrue ($ this ->model () ->eventData ['singleton ' ]);
102104
103- $ this ->model ->find (1 );
104- $ this ->assertTrue ($ this ->model ->eventData ['singleton ' ]);
105+ $ this ->model () ->find (1 );
106+ $ this ->assertTrue ($ this ->model () ->eventData ['singleton ' ]);
105107
106- $ this ->model ->find ();
107- $ this ->assertFalse ($ this ->model ->eventData ['singleton ' ]);
108+ $ this ->model () ->find ();
109+ $ this ->assertFalse ($ this ->model () ->eventData ['singleton ' ]);
108110
109- $ this ->model ->findAll ();
110- $ this ->assertFalse ($ this ->model ->eventData ['singleton ' ]);
111+ $ this ->model () ->findAll ();
112+ $ this ->assertFalse ($ this ->model () ->eventData ['singleton ' ]);
111113
112114 // beforeFind
113- $ this ->model ->beforeFindReturnData = true ;
115+ $ this ->model () ->beforeFindReturnData = true ;
114116
115- $ this ->model ->first ();
116- $ this ->assertTrue ($ this ->model ->eventData ['singleton ' ]);
117+ $ this ->model () ->first ();
118+ $ this ->assertTrue ($ this ->model () ->eventData ['singleton ' ]);
117119
118- $ this ->model ->find (1 );
119- $ this ->assertTrue ($ this ->model ->eventData ['singleton ' ]);
120+ $ this ->model () ->find (1 );
121+ $ this ->assertTrue ($ this ->model () ->eventData ['singleton ' ]);
120122
121- $ this ->model ->find ();
122- $ this ->assertFalse ($ this ->model ->eventData ['singleton ' ]);
123+ $ this ->model () ->find ();
124+ $ this ->assertFalse ($ this ->model () ->eventData ['singleton ' ]);
123125
124- $ this ->model ->findAll ();
125- $ this ->assertFalse ($ this ->model ->eventData ['singleton ' ]);
126+ $ this ->model () ->findAll ();
127+ $ this ->assertFalse ($ this ->model () ->eventData ['singleton ' ]);
126128 }
127129
128130 public function testAllowCallbacksFalsePreventsTriggers (): void
129131 {
130- $ this ->model ->allowCallbacks (false )->find (1 );
131- $ this ->assertFalse ($ this ->model ->hasToken ('afterFind ' ));
132+ $ this ->model () ->allowCallbacks (false )->find (1 );
133+ $ this ->assertFalse ($ this ->model () ->hasToken ('afterFind ' ));
132134 }
133135
134136 public function testAllowCallbacksTrueFiresTriggers (): void
135137 {
136- $ this ->setPrivateProperty ($ this ->model , 'allowCallbacks ' , false );
137- $ this ->model ->allowCallbacks (true )->find (1 );
138- $ this ->assertTrue ($ this ->model ->hasToken ('afterFind ' ));
138+ $ this ->setPrivateProperty ($ this ->model () , 'allowCallbacks ' , false );
139+ $ this ->model () ->allowCallbacks (true )->find (1 );
140+ $ this ->assertTrue ($ this ->model () ->hasToken ('afterFind ' ));
139141 }
140142
141143 public function testAllowCallbacksResetsAfterTrigger (): void
142144 {
143- $ this ->model ->allowCallbacks (false )->find (1 );
144- $ this ->model ->delete (1 );
145+ $ this ->model () ->allowCallbacks (false )->find (1 );
146+ $ this ->model () ->delete (1 );
145147
146- $ this ->assertFalse ($ this ->model ->hasToken ('afterFind ' ));
147- $ this ->assertTrue ($ this ->model ->hasToken ('afterDelete ' ));
148+ $ this ->assertFalse ($ this ->model () ->hasToken ('afterFind ' ));
149+ $ this ->assertTrue ($ this ->model () ->hasToken ('afterDelete ' ));
148150 }
149151
150152 public function testAllowCallbacksUsesModelProperty (): void
151153 {
152- $ this ->setPrivateProperty ($ this ->model , 'allowCallbacks ' , false );
153- $ this ->setPrivateProperty ($ this ->model , 'tempAllowCallbacks ' , false ); // Was already set by the constructor
154+ $ this ->setPrivateProperty ($ this ->model () , 'allowCallbacks ' , false );
155+ $ this ->setPrivateProperty ($ this ->model () , 'tempAllowCallbacks ' , false ); // Was already set by the constructor
154156
155- $ this ->model ->find (1 );
156- $ this ->model ->delete (1 );
157+ $ this ->model () ->find (1 );
158+ $ this ->model () ->delete (1 );
157159
158- $ this ->assertFalse ($ this ->model ->hasToken ('afterFind ' ));
159- $ this ->assertFalse ($ this ->model ->hasToken ('afterDelete ' ));
160+ $ this ->assertFalse ($ this ->model () ->hasToken ('afterFind ' ));
161+ $ this ->assertFalse ($ this ->model () ->hasToken ('afterDelete ' ));
160162 }
161163
162164 public function testInvalidEventException (): void
@@ -168,11 +170,11 @@ public function testInvalidEventException(): void
168170 'deleted ' => 0 ,
169171 ];
170172
171- $ this ->setPrivateProperty ($ this ->model , 'beforeInsert ' , ['anotherBeforeInsertMethod ' ]);
173+ $ this ->setPrivateProperty ($ this ->model () , 'beforeInsert ' , ['anotherBeforeInsertMethod ' ]);
172174
173175 $ this ->expectException (DataException::class);
174176 $ this ->expectExceptionMessage ('"anotherBeforeInsertMethod" is not a valid Model Event callback. ' );
175- $ this ->model ->insert ($ data );
177+ $ this ->model () ->insert ($ data );
176178 }
177179
178180 public function testInsertBatchEvent (): void
@@ -192,9 +194,9 @@ public function testInsertBatchEvent(): void
192194 ],
193195 ];
194196
195- $ this ->model ->insertBatch ($ data );
196- $ this ->assertTrue ($ this ->model ->hasToken ('beforeInsertBatch ' ));
197- $ this ->assertTrue ($ this ->model ->hasToken ('afterInsertBatch ' ));
197+ $ this ->model () ->insertBatch ($ data );
198+ $ this ->assertTrue ($ this ->model () ->hasToken ('beforeInsertBatch ' ));
199+ $ this ->assertTrue ($ this ->model () ->hasToken ('afterInsertBatch ' ));
198200 }
199201
200202 public function testUpdateBatchEvent (): void
@@ -210,8 +212,8 @@ public function testUpdateBatchEvent(): void
210212 ],
211213 ];
212214
213- $ this ->model ->updateBatch ($ data , 'name ' );
214- $ this ->assertTrue ($ this ->model ->hasToken ('beforeUpdateBatch ' ));
215- $ this ->assertTrue ($ this ->model ->hasToken ('afterUpdateBatch ' ));
215+ $ this ->model () ->updateBatch ($ data , 'name ' );
216+ $ this ->assertTrue ($ this ->model () ->hasToken ('beforeUpdateBatch ' ));
217+ $ this ->assertTrue ($ this ->model () ->hasToken ('afterUpdateBatch ' ));
216218 }
217219}
0 commit comments