2019-05-14 06:05:05 +02:00
|
|
|
<?php
|
2020-09-14 13:11:46 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-09-14 13:11:46 +02:00
|
|
|
*
|
2022-06-21 11:57:17 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-09-14 13:11:46 +02:00
|
|
|
*/
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2019-05-14 06:05:05 +02:00
|
|
|
namespace Tests\Integration;
|
|
|
|
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2019-05-16 08:00:27 +02:00
|
|
|
class MarkInvoicePaidTest extends TestCase
|
2019-05-14 06:05:05 +02:00
|
|
|
{
|
|
|
|
use MockAccountData;
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
2022-06-21 12:00:57 +02:00
|
|
|
protected function setUp() :void
|
2019-05-14 06:05:05 +02:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->makeTestData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testClientExists()
|
|
|
|
{
|
|
|
|
$this->assertNotNull($this->client);
|
|
|
|
}
|
|
|
|
|
2019-05-16 08:00:27 +02:00
|
|
|
public function testMarkInvoicePaidInvoice()
|
2019-05-14 06:05:05 +02:00
|
|
|
{
|
2020-02-03 11:33:07 +01:00
|
|
|
$invoice = Invoice::find($this->invoice->id);
|
|
|
|
$invoice_balance = $invoice->balance;
|
|
|
|
$client = $invoice->client;
|
|
|
|
$client_balance = $client->balance;
|
|
|
|
|
2020-02-04 08:51:44 +01:00
|
|
|
$this->invoice->service()->markPaid();
|
2019-05-14 06:05:05 +02:00
|
|
|
|
|
|
|
$invoice = Invoice::find($this->invoice->id);
|
2020-02-03 11:33:07 +01:00
|
|
|
$client = $invoice->client;
|
2019-10-22 04:07:00 +02:00
|
|
|
|
2019-05-14 06:05:05 +02:00
|
|
|
$this->assertEquals(0.00, $invoice->balance);
|
|
|
|
|
|
|
|
$this->assertEquals(1, count($invoice->payments));
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
foreach ($invoice->payments as $payment) {
|
|
|
|
$this->assertEquals(round($this->invoice->amount, 2), $payment->amount);
|
2019-05-14 06:05:05 +02:00
|
|
|
}
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
//events are not firing which makes this impossible to control.
|
2019-05-14 06:05:05 +02:00
|
|
|
|
|
|
|
$this->assertEquals(0.00, $invoice->balance);
|
2020-02-03 11:33:07 +01:00
|
|
|
$this->assertEquals(($client_balance - $invoice_balance), $client->balance);
|
2019-05-14 06:05:05 +02:00
|
|
|
}
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|