From acdc8fad94d3abe062d70d9a82756894d6f611f3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 26 Apr 2019 21:18:23 +1000 Subject: [PATCH] Finalize tests for Factories --- app/Factory/CloneInvoiceFactory.php | 2 +- app/Factory/InvoiceFactory.php | 4 +- .../2014_10_13_000000_create_users_table.php | 2 +- tests/Unit/FactoryCreationTest.php | 66 +++++++++++++++++++ 4 files changed, 70 insertions(+), 4 deletions(-) diff --git a/app/Factory/CloneInvoiceFactory.php b/app/Factory/CloneInvoiceFactory.php index cfaf1f19dc99..996f2d8a0a91 100644 --- a/app/Factory/CloneInvoiceFactory.php +++ b/app/Factory/CloneInvoiceFactory.php @@ -10,7 +10,7 @@ class CloneInvoiceFactory { $clone_invoice = $invoice->replicate(); $clone_invoice->status_id = Invoice::STATUS_DRAFT; - $clone_invoice->invoice_number = ''; + $clone_invoice->invoice_number = NULL; $clone_invoice->invoice_date = null; $clone_invoice->due_date = null; $clone_invoice->partial_due_date = null; diff --git a/app/Factory/InvoiceFactory.php b/app/Factory/InvoiceFactory.php index 831bc6977400..a9291de7a192 100644 --- a/app/Factory/InvoiceFactory.php +++ b/app/Factory/InvoiceFactory.php @@ -9,9 +9,9 @@ use Illuminate\Support\Facades\Log; class InvoiceFactory { - public static function create(int $company_id, int $user_id) :\stdClass + public static function create(int $company_id, int $user_id) :Invoice { - $invoice = new \stdClass; + $invoice = new Invoice(); $invoice->status_id = Invoice::STATUS_DRAFT; $invoice->invoice_number = ''; $invoice->discount = 0; diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php index 576826d00a7e..83292ab0b496 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -343,7 +343,7 @@ class CreateUsersTable extends Migration $t->unsignedInteger('company_id')->index(); $t->unsignedInteger('status_id'); - $t->string('invoice_number'); + $t->string('invoice_number')->nullable(); $t->float('discount'); $t->boolean('is_amount_discount'); diff --git a/tests/Unit/FactoryCreationTest.php b/tests/Unit/FactoryCreationTest.php index 4619c93280ee..97a390b6ccf7 100644 --- a/tests/Unit/FactoryCreationTest.php +++ b/tests/Unit/FactoryCreationTest.php @@ -4,6 +4,9 @@ namespace Tests\Unit; use App\Factory\ClientContactFactory; use App\Factory\ClientFactory; +use App\Factory\CloneInvoiceFactory; +use App\Factory\InvoiceFactory; +use App\Factory\ProductFactory; use App\Factory\UserFactory; use App\Models\Client; use App\Utils\Traits\MakesHash; @@ -46,6 +49,69 @@ class FactoryCreationTest extends TestCase ]); } + /** + * @test + * @covers App\Factory\ProductFactory + */ + public function testProductionCreation() + { + $product = ProductFactory::create($this->company->id, $this->user->id); + $product->save(); + + $this->assertNotNull($product); + + $this->assertInternalType("int", $product->id); + } + + /** + * @test + * @covers App\Factory\InvoiceFactory + */ + + public function testInvoiceCreation() + { + $client = ClientFactory::create($this->company->id, $this->user->id); + + $client->save(); + + $invoice = InvoiceFactory::create($this->company->id,$this->user->id);//stub the company and user_id + $invoice->client_id = $client->id; + $invoice->save(); + + $this->assertNotNull($invoice); + + $this->assertInternalType("int", $invoice->id); + } + + /** + * @test + * @covers App|Factory\CloneInvoiceFactory + */ + public function testCloneInvoiceCreation() + { + $client = ClientFactory::create($this->company->id, $this->user->id); + + $client->save(); + + $invoice = InvoiceFactory::create($this->company->id,$this->user->id);//stub the company and user_id + $invoice->client_id = $client->id; + $invoice->save(); + + $this->assertNotNull($invoice); + + $this->assertInternalType("int", $invoice->id); + + + $clone = CloneInvoiceFactory::create($invoice, $this->user->id); + $clone->save(); + + $this->assertNotNull($clone); + + $this->assertInternalType("int", $clone->id); + + + } + /** * @test * @covers App|Factory\ClientFactory