markTestSkipped('Skip test no Yodlee API credentials found'); $this->makeTestData(); $this->withoutMiddleware( ThrottleRequests::class ); } public function testDataMatching1() { $this->invoice->number = "super-funk-1234"; $this->invoice->save(); $bank_transaction = BankTransaction::where('company_id', $this->company->id)->first(); $bank_transaction->description = "super-funk-1234"; $bank_transaction->save(); $this->assertNotNull($this->invoice); $this->assertNotNull($bank_transaction); $invoices = Invoice::where('company_id', $this->company->id)->get(); BankTransaction::where('company_id', $this->company->id) ->where('status_id', BankTransaction::STATUS_UNMATCHED) ->cursor() ->each(function ($bt) use($invoices){ $invoice = $invoices->first(function ($value, $key) use ($bt){ return str_contains($value->number, $bt->description); }); if($invoice) { $bt->invoice_ids = $invoice->hashed_id; $bt->status_id = BankTransaction::STATUS_MATCHED; $bt->save(); } }); $this->assertTrue(BankTransaction::where('invoice_ids', $this->invoice->hashed_id)->exists()); } public function testDataMatching2() { $this->invoice->number = "super-funk-1234"; $this->invoice->save(); $bank_transaction = BankTransaction::where('company_id', $this->company->id)->first(); $bank_transaction->description = "super-funk-123"; $bank_transaction->save(); $this->assertNotNull($this->invoice); $this->assertNotNull($bank_transaction); $invoices = Invoice::where('company_id', $this->company->id)->get(); BankTransaction::where('company_id', $this->company->id) ->where('status_id', BankTransaction::STATUS_UNMATCHED) ->cursor() ->each(function ($bt) use($invoices){ $invoice = $invoices->first(function ($value, $key) use ($bt){ return str_contains($value->number, $bt->description); }); if($invoice) { $bt->invoice_ids = $invoice->hashed_id; $bt->status_id = BankTransaction::STATUS_MATCHED; $bt->save(); } }); $this->assertTrue(BankTransaction::where('invoice_ids', $this->invoice->hashed_id)->exists()); } }