File tree Expand file tree Collapse file tree 2 files changed +40
-3
lines changed
src/Illuminate/Database/Eloquent Expand file tree Collapse file tree 2 files changed +40
-3
lines changed Original file line number Diff line number Diff line change @@ -64,9 +64,9 @@ public function forceDelete()
64
64
protected function performDeleteOnModel ()
65
65
{
66
66
if ($ this ->forceDeleting ) {
67
- $ this ->exists = false ;
68
-
69
- return $ this -> setKeysForSaveQuery ( $ this -> newModelQuery ())-> forceDelete ( );
67
+ return tap ( $ this ->setKeysForSaveQuery ( $ this -> newModelQuery ())-> forceDelete (), function () {
68
+ $ this -> exists = false ;
69
+ } );
70
70
}
71
71
72
72
return $ this ->runSoftDelete ();
Original file line number Diff line number Diff line change 11
11
use Illuminate \Pagination \CursorPaginator ;
12
12
use Illuminate \Pagination \Paginator ;
13
13
use Illuminate \Support \Carbon ;
14
+ use Mockery ;
14
15
use PHPUnit \Framework \TestCase ;
15
16
16
17
class DatabaseEloquentSoftDeletesIntegrationTest extends TestCase
@@ -189,6 +190,42 @@ public function testForceDeleteActuallyDeletesRecords()
189
190
$ this ->assertEquals (1 , $ users ->first ()->id );
190
191
}
191
192
193
+ public function testForceDeleteUpdateExistsProperty ()
194
+ {
195
+ $ this ->createUsers ();
196
+ $ user = SoftDeletesTestUser::find (2 );
197
+
198
+ $ this ->assertTrue ($ user ->exists );
199
+
200
+ $ user ->forceDelete ();
201
+
202
+ $ this ->assertFalse ($ user ->exists );
203
+ }
204
+
205
+ public function testForceDeleteDoesntUpdateExistsPropertyIfFailed ()
206
+ {
207
+ $ user = new class () extends SoftDeletesTestUser
208
+ {
209
+ public $ exists = true ;
210
+
211
+ public function newModelQuery ()
212
+ {
213
+ return Mockery::spy (parent ::newModelQuery (), function (Mockery \MockInterface $ mock ) {
214
+ $ mock ->shouldReceive ('forceDelete ' )->andThrow (new \Exception ());
215
+ });
216
+ }
217
+ };
218
+
219
+ $ this ->assertTrue ($ user ->exists );
220
+
221
+ try {
222
+ $ user ->forceDelete ();
223
+ } catch (\Exception $ exception ) {
224
+ }
225
+
226
+ $ this ->assertTrue ($ user ->exists );
227
+ }
228
+
192
229
public function testRestoreRestoresRecords ()
193
230
{
194
231
$ this ->createUsers ();
You can’t perform that action at this time.
0 commit comments