diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 052a477c2d..951767d0ec 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -52,6 +52,7 @@ class Handler extends ExceptionHandler MaxAttemptsExceededException::class, CommandNotFoundException::class, ValidationException::class, + ModelNotFoundException::class, ]; /** diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 162923cee0..ed02b1e366 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -339,6 +339,10 @@ class InvoiceService public function removeUnpaidGatewayFees() { + //return early if type three does not exist. + if(!collect($this->invoice->line_items)->contains('type_id', 3)) + return $this; + $this->invoice->line_items = collect($this->invoice->line_items) ->reject(function ($item) { return $item->type_id == '3'; diff --git a/tests/Unit/CollectionMergingTest.php b/tests/Unit/CollectionMergingTest.php index 067a8d3275..f223011a12 100644 --- a/tests/Unit/CollectionMergingTest.php +++ b/tests/Unit/CollectionMergingTest.php @@ -10,6 +10,7 @@ */ namespace Tests\Unit; +use App\Factory\InvoiceItemFactory; use App\Utils\Traits\UserSessionAttributes; use Illuminate\Support\Facades\Session; use Tests\TestCase; @@ -19,13 +20,10 @@ use Tests\TestCase; */ class CollectionMergingTest extends TestCase { - use UserSessionAttributes; public function setUp() :void { parent::setUp(); - - Session::start(); } public function testUniqueValues() @@ -62,4 +60,21 @@ class CollectionMergingTest extends TestCase $intersect = $collection->intersectByKeys($collection->flatten(1)->unique()); $this->assertEquals(11, $intersect->count()); } + + public function testExistenceInCollection() + { + + $items = InvoiceItemFactory::generate(5); + + $this->assertFalse(collect($items)->contains('type_id', "3")); + $this->assertFalse(collect($items)->contains('type_id', 3)); + + $item = InvoiceItemFactory::create(); + $item->type_id = "3"; + $items[] = $item; + + $this->assertTrue(collect($items)->contains('type_id', "3")); + $this->assertTrue(collect($items)->contains('type_id', 3)); + + } }