diff --git a/src/Illuminate/Bus/Batch.php b/src/Illuminate/Bus/Batch.php index a37e8c20a679..ae369e669ba6 100644 --- a/src/Illuminate/Bus/Batch.php +++ b/src/Illuminate/Bus/Batch.php @@ -420,6 +420,16 @@ public function hasFailureCallbacks(): bool return isset($this->options['failure']) && ! empty($this->options['failure']); } + /** + * Get the "failure" callbacks that have been registered with the batch. + * + * @return array + */ + public function failureCallbacks() + { + return $this->options['failure'] ?? []; + } + /** * Determine if the batch has "finally" callbacks. * diff --git a/tests/Bus/BusBatchTest.php b/tests/Bus/BusBatchTest.php index 670d1073ad92..80b1af658851 100644 --- a/tests/Bus/BusBatchTest.php +++ b/tests/Bus/BusBatchTest.php @@ -597,6 +597,13 @@ public function test_batch_state_can_be_inspected() $batch->options['catch'] = [1]; $this->assertTrue($batch->hasCatchCallbacks()); + $this->assertSame([], $batch->failureCallbacks()); + $batch->options['failure'] = []; + $this->assertFalse($batch->hasFailureCallbacks()); + $batch->options['failure'] = [1]; + $this->assertTrue($batch->hasFailureCallbacks()); + $this->assertSame([1], $batch->failureCallbacks()); + $this->assertFalse($batch->cancelled()); $batch->cancelledAt = Carbon::now(); $this->assertTrue($batch->cancelled());