From b03ded8a57c2bc798c786a7119a1a7b70fccdd00 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Mon, 16 Dec 2019 13:19:09 +0300 Subject: [PATCH] factory in tests --- database/factories/Transaction.php | 4 ---- tests/Feature/Expenses/PaymentsTest.php | 28 ++++--------------------- tests/Feature/Incomes/RevenuesTest.php | 28 ++++--------------------- 3 files changed, 8 insertions(+), 52 deletions(-) diff --git a/database/factories/Transaction.php b/database/factories/Transaction.php index f2ef53cc8..04abbed45 100644 --- a/database/factories/Transaction.php +++ b/database/factories/Transaction.php @@ -3,7 +3,6 @@ use App\Models\Auth\User; use App\Models\Banking\Transaction; use Faker\Generator as Faker; -use Illuminate\Http\UploadedFile; $user = User::first(); $company = $user->companies()->first(); @@ -11,8 +10,6 @@ $company = $user->companies()->first(); $factory->define(Transaction::class, function (Faker $faker) use ($company) { setting()->setExtraColumns(['company_id' => $company->id]); - $attachment = UploadedFile::fake()->create('image.jpg'); - return [ 'company_id' => $company->id, 'type' => 'income', @@ -25,7 +22,6 @@ $factory->define(Transaction::class, function (Faker $faker) use ($company) { 'category_id' => $company->categories()->type('income')->pluck('id')->first(), 'reference' => $faker->text(5), 'payment_method' => setting('default.payment_method'), - //'attachment' => $attachment, ]; }); diff --git a/tests/Feature/Expenses/PaymentsTest.php b/tests/Feature/Expenses/PaymentsTest.php index 2c8fec124..479a47033 100644 --- a/tests/Feature/Expenses/PaymentsTest.php +++ b/tests/Feature/Expenses/PaymentsTest.php @@ -3,7 +3,7 @@ namespace Tests\Feature\Expenses; use App\Jobs\Banking\CreateTransaction; -use Illuminate\Http\UploadedFile; +use App\Models\Banking\Transaction; use Tests\Feature\FeatureTestCase; class PaymentsTest extends FeatureTestCase @@ -27,7 +27,7 @@ class PaymentsTest extends FeatureTestCase public function testItShouldCreatePayment() { $this->loginAs() - ->post(route('payments.store'), $this->getPaymentRequest()) + ->post(route('payments.store'), factory(Transaction::class)->states('expense')->raw()) ->assertStatus(200); $this->assertFlashLevel('success'); @@ -35,7 +35,7 @@ class PaymentsTest extends FeatureTestCase public function testItShouldUpdatePayment() { - $request = $this->getPaymentRequest(); + $request = factory(Transaction::class)->states('expense')->raw(); $payment = $this->dispatch(new CreateTransaction($request)); @@ -50,7 +50,7 @@ class PaymentsTest extends FeatureTestCase public function testItShouldDeletePayment() { - $payment = $this->dispatch(new CreateTransaction($this->getPaymentRequest())); + $payment = $this->dispatch(new CreateTransaction(factory(Transaction::class)->states('expense')->raw())); $this->loginAs() ->delete(route('payments.destroy', $payment->id)) @@ -58,24 +58,4 @@ class PaymentsTest extends FeatureTestCase $this->assertFlashLevel('success'); } - - private function getPaymentRequest() - { - $attachment = UploadedFile::fake()->create('image.jpg'); - - return [ - 'company_id' => $this->company->id, - 'type' => 'expense', - 'account_id' => setting('default.account'), - 'paid_at' => $this->faker->date(), - 'amount' => $this->faker->randomFloat(2, 2), - 'currency_code' => setting('default.currency'), - 'currency_rate' => '1', - 'description' => $this->faker->text(5), - 'category_id' => $this->company->categories()->type('expense')->first()->id, - 'payment_method' => setting('default.payment_method'), - 'reference' => $this->faker->text(5), - 'attachment' => $attachment, - ]; - } } diff --git a/tests/Feature/Incomes/RevenuesTest.php b/tests/Feature/Incomes/RevenuesTest.php index b39fb2fc0..3fe9104ee 100644 --- a/tests/Feature/Incomes/RevenuesTest.php +++ b/tests/Feature/Incomes/RevenuesTest.php @@ -3,7 +3,7 @@ namespace Tests\Feature\Incomes; use App\Jobs\Banking\CreateTransaction; -use Illuminate\Http\UploadedFile; +use App\Models\Banking\Transaction; use Tests\Feature\FeatureTestCase; class RevenuesTest extends FeatureTestCase @@ -27,7 +27,7 @@ class RevenuesTest extends FeatureTestCase public function testItShouldCreateRevenue() { $this->loginAs() - ->post(route('revenues.store'), $this->getRevenueRequest()) + ->post(route('revenues.store'), factory(Transaction::class)->raw()) ->assertStatus(200); $this->assertFlashLevel('success'); @@ -35,7 +35,7 @@ class RevenuesTest extends FeatureTestCase public function testItShouldUpdateRevenue() { - $request = $this->getRevenueRequest(); + $request = factory(Transaction::class)->raw(); $revenue = $this->dispatch(new CreateTransaction($request)); @@ -50,7 +50,7 @@ class RevenuesTest extends FeatureTestCase public function testItShouldDeleteRevenue() { - $revenue = $this->dispatch(new CreateTransaction($this->getRevenueRequest())); + $revenue = $this->dispatch(new CreateTransaction(factory(Transaction::class)->raw())); $this->loginAs() ->delete(route('revenues.destroy', $revenue->id)) @@ -58,24 +58,4 @@ class RevenuesTest extends FeatureTestCase $this->assertFlashLevel('success'); } - - private function getRevenueRequest() - { - $attachment = UploadedFile::fake()->create('image.jpg'); - - return [ - 'company_id' => $this->company->id, - 'type' => 'income', - 'account_id' => setting('default.account'), - 'paid_at' => $this->faker->date(), - 'amount' => $this->faker->randomFloat(2, 2), - 'currency_code' => setting('default.currency'), - 'currency_rate' => '1', - 'description' => $this->faker->text(5), - 'category_id' => $this->company->categories()->type('income')->first()->id, - 'reference' => $this->faker->text(5), - 'payment_method' => setting('default.payment_method'), - 'attachment' => $attachment, - ]; - } }