mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Mocking objects for tests
This commit is contained in:
parent
f7c31bd5a1
commit
b7dc753d58
@ -2,26 +2,36 @@
|
||||
|
||||
namespace App\Factory;
|
||||
|
||||
use App\Models\Invoice;
|
||||
|
||||
class InvoiceFactory
|
||||
{
|
||||
public static function create() :\stdClass
|
||||
{
|
||||
$item = new \stdClass;
|
||||
$item->qty = 0;
|
||||
$item->cost = 0;
|
||||
$item->product_key = '';
|
||||
$item->notes = '';
|
||||
$item->discount = 0;
|
||||
$item->is_amount_discount = true;
|
||||
$item->tax_name1 = '';
|
||||
$item->tax_rate1 = 0;
|
||||
$item->tax_name2 = '';
|
||||
$item->tax_rate2 = 0;
|
||||
$item->sort_id = 0;
|
||||
$item->line_total = 0;
|
||||
$item->invoice_item_type_id = 0;
|
||||
$invoice = new \stdClass;
|
||||
$invoice->invoice_status_id = Invoice::STATUS_DRAFT;
|
||||
$invoice->invoice_number = '';
|
||||
$invoice->discount = 0;
|
||||
$invoice->is_amount_discount = true;
|
||||
$invoice->po_number = '';
|
||||
$invoice->invoice_date = null;
|
||||
$invoice->due_date = null;
|
||||
$invoice->is_deleted = false;
|
||||
$invoice->line_items = json_encode([]);
|
||||
$invoice->settings = json_encode([]);
|
||||
$invoice->backup = json_encode([]);
|
||||
$invoice->tax_name1 = '';
|
||||
$invoice->tax_rate1 = 0;
|
||||
$invoice->tax_name2 = '';
|
||||
$invoice->tax_rate2 = 0;
|
||||
$invoice->custom_value1 = '';
|
||||
$invoice->custom_value2 = '';
|
||||
$invoice->custom_value3 = '';
|
||||
$invoice->custom_value4 = '';
|
||||
$invoice->amount = 0;
|
||||
$invoice->balance = 0;
|
||||
$invoice->partial = 0;
|
||||
|
||||
return $item;
|
||||
return $invoice;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -355,7 +355,7 @@ class CreateUsersTable extends Migration
|
||||
$t->boolean('is_deleted')->default(false);
|
||||
|
||||
$t->text('line_items')->nullable();
|
||||
$t->text('options')->nullable();
|
||||
$t->text('settings')->nullable();
|
||||
$t->text('backup')->nullable();
|
||||
|
||||
$t->string('tax_name1');
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Factory\InvoiceFactory;
|
||||
use App\Factory\InvoiceItemFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
@ -11,11 +12,49 @@ use Tests\TestCase;
|
||||
*/
|
||||
class InvoiceTest extends TestCase
|
||||
{
|
||||
|
||||
protected $invoice;
|
||||
|
||||
protected $invoice_calc;
|
||||
|
||||
private $settings;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$this->invoice = InvoiceFactory::create();
|
||||
$this->invoice->line_items = $this->buildLineItems();
|
||||
|
||||
$this->settings = $this->buildSettings();
|
||||
|
||||
$this->invoice_calc = new InvoiceCalc($this->invoice, $this->settings);
|
||||
}
|
||||
|
||||
|
||||
private function buildSettings()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private function buildLineItems()
|
||||
{
|
||||
$line_items = [];
|
||||
|
||||
$item = InvoiceItemFactory::create();
|
||||
$item->qty = 1;
|
||||
$item->cost =10;
|
||||
|
||||
$line_items[] = $item;
|
||||
|
||||
$item = InvoiceItemFactory::create();
|
||||
$item->qty = 1;
|
||||
$item->cost =10;
|
||||
|
||||
$line_items[] = $item;
|
||||
|
||||
return $line_items;
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user