diff --git a/app/Models/Foundation/Summit/Events/Presentations/Materials/PresentationMaterial.php b/app/Models/Foundation/Summit/Events/Presentations/Materials/PresentationMaterial.php index a67f1bfa0..50dfb8946 100644 --- a/app/Models/Foundation/Summit/Events/Presentations/Materials/PresentationMaterial.php +++ b/app/Models/Foundation/Summit/Events/Presentations/Materials/PresentationMaterial.php @@ -68,7 +68,7 @@ public function getPresentationId(){ try { return $this->presentation->getId(); } - catch (\Exception $ex){ + catch (\Throwable $ex){ return 0; } } @@ -81,7 +81,7 @@ public function getSummitId(): int try { return $this->presentation->getSummitId(); } - catch (\Exception $ex){ + catch (\Throwable $ex){ return 0; } } diff --git a/tests/Unit/Services/PresentationMaterialEventDispatchTest.php b/tests/Unit/Services/PresentationMaterialEventDispatchTest.php index 0f7e790d6..a457e81b7 100644 --- a/tests/Unit/Services/PresentationMaterialEventDispatchTest.php +++ b/tests/Unit/Services/PresentationMaterialEventDispatchTest.php @@ -136,4 +136,17 @@ public function testDeleteMediaUploadDispatchesLifeCycleEventWithoutError(): voi $this->assertCount(1, $jobs, 'Expected 1 ProcessScheduleEntityLifeCycleEvent for PresentationMediaUpload delete'); $this->assertSame(0, $jobs[0]->summit_id, 'summit_id is 0 here because unsetPresentation() runs before PreRemove - accepted degraded case, not a regression'); } + + /** + * Both accessors must survive a material whose owning presentation is not set - the + * state removeMediaUpload() leaves behind before PreRemove fires. A null dereference + * throws \Error, which a catch of \Exception does not cover. + */ + public function testAccessorsReturnZeroWhenPresentationIsNotSet(): void + { + $media_upload = new PresentationMediaUpload(); + + $this->assertSame(0, $media_upload->getPresentationId()); + $this->assertSame(0, $media_upload->getSummitId()); + } }