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()
6464 protected function performDeleteOnModel ()
6565 {
6666 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+ } );
7070 }
7171
7272 return $ this ->runSoftDelete ();
Original file line number Diff line number Diff line change 1111use Illuminate \Pagination \CursorPaginator ;
1212use Illuminate \Pagination \Paginator ;
1313use Illuminate \Support \Carbon ;
14+ use Mockery ;
1415use PHPUnit \Framework \TestCase ;
1516
1617class DatabaseEloquentSoftDeletesIntegrationTest extends TestCase
@@ -189,6 +190,42 @@ public function testForceDeleteActuallyDeletesRecords()
189190 $ this ->assertEquals (1 , $ users ->first ()->id );
190191 }
191192
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+
192229 public function testRestoreRestoresRecords ()
193230 {
194231 $ this ->createUsers ();
You can’t perform that action at this time.
0 commit comments