From 751344f11a7c57df7c843f94751c9d688bd15d6d Mon Sep 17 00:00:00 2001 From: denisdulici Date: Tue, 7 Jan 2020 01:28:05 +0300 Subject: [PATCH 1/3] improved factories and tests --- database/factories/Account.php | 12 +++++++ database/factories/Contact.php | 45 ++++++++++++++++++------ database/factories/Item.php | 12 +++++++ database/factories/Transaction.php | 15 +++++--- database/factories/User.php | 12 +++++++ tests/Feature/Auth/UsersTest.php | 19 ++++++---- tests/Feature/Banking/AccountsTest.php | 13 ++++--- tests/Feature/Banking/TransfersTest.php | 6 ++-- tests/Feature/Common/ItemsTest.php | 13 ++++--- tests/Feature/Purchases/PaymentsTest.php | 11 ++++-- tests/Feature/Purchases/VendorsTest.php | 26 +++++--------- tests/Feature/Sales/CustomersTest.php | 38 ++++++++------------ tests/Feature/Sales/RevenuesTest.php | 11 ++++-- 13 files changed, 152 insertions(+), 81 deletions(-) diff --git a/database/factories/Account.php b/database/factories/Account.php index 26c78c409..d7fd642bd 100644 --- a/database/factories/Account.php +++ b/database/factories/Account.php @@ -24,3 +24,15 @@ $factory->define(Account::class, function (Faker $faker) use ($company) { 'enabled' => $faker->boolean ? 1 : 0, ]; }); + +$factory->state(Account::class, 'enabled', function (Faker $faker) { + return [ + 'enabled' => 1, + ]; +}); + +$factory->state(Account::class, 'disabled', function (Faker $faker) { + return [ + 'enabled' => 0, + ]; +}); diff --git a/database/factories/Contact.php b/database/factories/Contact.php index 5a2e659c5..5abd20c22 100644 --- a/database/factories/Contact.php +++ b/database/factories/Contact.php @@ -1,4 +1,5 @@ companies()->first(); $factory->define(Contact::class, function (Faker $faker) use ($company) { - setting()->setExtraColumns([ - 'company_id' => $company->id - ]); + setting()->setExtraColumns(['company_id' => $company->id]); return [ 'company_id' => $company->id, 'type' => $faker->boolean ? 'customer' : 'vendor', - 'name' => $faker->text(15), - 'email' => '', + 'name' => $faker->name, + 'email' => $faker->unique()->safeEmail, 'user_id' => null, - 'tax_number' => null, - 'phone' => null, - 'address' => null, - 'website' => null, + 'tax_number' => $faker->randomNumber(9), + 'phone' => $faker->phoneNumber, + 'address' => $faker->address, + 'website' => 'https://akaunting.com', 'currency_code' => setting('default.currency'), - 'reference' => null, - 'enabled' => $faker->boolean ? 1 : 0 + 'reference' => $faker->text(5), + 'enabled' => $faker->boolean ? 1 : 0, + ]; +}); + +$factory->state(Contact::class, 'customer', function (Faker $faker) { + return [ + 'type' => 'customer', + ]; +}); + +$factory->state(Contact::class, 'vendor', function (Faker $faker) { + return [ + 'type' => 'vendor', + ]; +}); + +$factory->state(Contact::class, 'enabled', function (Faker $faker) { + return [ + 'enabled' => 1, + ]; +}); + +$factory->state(Contact::class, 'disabled', function (Faker $faker) { + return [ + 'enabled' => 0, ]; }); diff --git a/database/factories/Item.php b/database/factories/Item.php index 467adf0d4..18f418fc3 100644 --- a/database/factories/Item.php +++ b/database/factories/Item.php @@ -21,3 +21,15 @@ $factory->define(Item::class, function (Faker $faker) use ($company) { 'enabled' => $faker->boolean ? 1 : 0, ]; }); + +$factory->state(Item::class, 'enabled', function (Faker $faker) { + return [ + 'enabled' => 1, + ]; +}); + +$factory->state(Item::class, 'disabled', function (Faker $faker) { + return [ + 'enabled' => 0, + ]; +}); diff --git a/database/factories/Transaction.php b/database/factories/Transaction.php index 04abbed45..a9dd48f4c 100644 --- a/database/factories/Transaction.php +++ b/database/factories/Transaction.php @@ -10,22 +10,29 @@ $company = $user->companies()->first(); $factory->define(Transaction::class, function (Faker $faker) use ($company) { setting()->setExtraColumns(['company_id' => $company->id]); + $type = $faker->boolean ? 'income' : 'expense'; + return [ 'company_id' => $company->id, - 'type' => 'income', + 'type' => $type, 'account_id' => setting('default.account'), - 'paid_at' => $faker->date(), + 'paid_at' => $faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d'), 'amount' => $faker->randomFloat(2, 2, 1000), 'currency_code' => setting('default.currency'), 'currency_rate' => '1', 'description' => $faker->text(5), - 'category_id' => $company->categories()->type('income')->pluck('id')->first(), + 'category_id' => $company->categories()->type($type)->pluck('id')->first(), 'reference' => $faker->text(5), 'payment_method' => setting('default.payment_method'), ]; }); -$factory->state(Transaction::class, 'income', []); +$factory->state(Transaction::class, 'income', function (Faker $faker) use ($company) { + return [ + 'type' => 'income', + 'category_id' => $company->categories()->type('income')->pluck('id')->first(), + ]; +}); $factory->state(Transaction::class, 'expense', function (Faker $faker) use ($company) { return [ diff --git a/database/factories/User.php b/database/factories/User.php index 1eece2a23..ed8499d6a 100644 --- a/database/factories/User.php +++ b/database/factories/User.php @@ -19,3 +19,15 @@ $factory->define(User::class, function (Faker $faker) { 'enabled' => $this->faker->boolean ? 1 : 0, ]; }); + +$factory->state(User::class, 'enabled', function (Faker $faker) { + return [ + 'enabled' => 1, + ]; +}); + +$factory->state(User::class, 'disabled', function (Faker $faker) { + return [ + 'enabled' => 0, + ]; +}); diff --git a/tests/Feature/Auth/UsersTest.php b/tests/Feature/Auth/UsersTest.php index 99b69bbea..eb3c14a73 100644 --- a/tests/Feature/Auth/UsersTest.php +++ b/tests/Feature/Auth/UsersTest.php @@ -27,7 +27,7 @@ class UsersTest extends FeatureTestCase public function testItShouldCreateUser() { $this->loginAs() - ->post(route('users.store'), factory(User::class)->raw()) + ->post(route('users.store'), $this->getRequest()) ->assertStatus(200); $this->assertFlashLevel('success'); @@ -35,7 +35,7 @@ class UsersTest extends FeatureTestCase public function testItShouldSeeUserUpdatePage() { - $user = $this->dispatch(new CreateUser(factory(User::class)->raw())); + $user = $this->dispatch(new CreateUser($this->getRequest())); $this->loginAs() ->get(route('users.edit', ['user' => $user->id])) @@ -45,7 +45,7 @@ class UsersTest extends FeatureTestCase public function testItShouldUpdateUser() { - $request = factory(User::class)->raw(); + $request = $this->getRequest(); $user = $this->dispatch(new CreateUser($request)); @@ -60,7 +60,7 @@ class UsersTest extends FeatureTestCase public function testItShouldDeleteUser() { - $user = $this->dispatch(new CreateUser(factory(User::class)->raw())); + $user = $this->dispatch(new CreateUser($this->getRequest())); $this->loginAs() ->delete(route('users.destroy', $user->id)) @@ -78,7 +78,7 @@ class UsersTest extends FeatureTestCase public function testItShouldLoginUser() { - $user = $this->dispatch(new CreateUser(factory(User::class)->raw())); + $user = $this->dispatch(new CreateUser($this->getRequest())); $this->post(route('login'), ['email' => $user->email, 'password' => $user->password]) ->assertStatus(200); @@ -88,7 +88,7 @@ class UsersTest extends FeatureTestCase public function testItShouldNotLoginUser() { - $user = $this->dispatch(new CreateUser(factory(User::class)->raw())); + $user = $this->dispatch(new CreateUser($this->getRequest())); $this->post(route('login'), ['email' => $user->email, 'password' => $this->faker->password()]) ->assertStatus(200); @@ -98,7 +98,7 @@ class UsersTest extends FeatureTestCase public function testItShouldLogoutUser() { - $user = $this->dispatch(new CreateUser(factory(User::class)->raw())); + $user = $this->dispatch(new CreateUser($this->getRequest())); $this->loginAs() ->get(route('logout', $user->id)) @@ -107,4 +107,9 @@ class UsersTest extends FeatureTestCase $this->assertGuest(); } + + public function getRequest() + { + return factory(User::class)->states('enabled')->raw(); + } } diff --git a/tests/Feature/Banking/AccountsTest.php b/tests/Feature/Banking/AccountsTest.php index 2325a0858..7146a6e59 100644 --- a/tests/Feature/Banking/AccountsTest.php +++ b/tests/Feature/Banking/AccountsTest.php @@ -27,7 +27,7 @@ class AccountsTest extends FeatureTestCase public function testItShouldCreateAccount() { $this->loginAs() - ->post(route('accounts.index'), factory(Account::class)->raw()) + ->post(route('accounts.index'), $this->getRequest()) ->assertStatus(200); $this->assertFlashLevel('success'); @@ -35,7 +35,7 @@ class AccountsTest extends FeatureTestCase public function testItShouldSeeAccountUpdatePage() { - $account = $this->dispatch(new CreateAccount(factory(Account::class)->raw())); + $account = $this->dispatch(new CreateAccount($this->getRequest())); $this->loginAs() ->get(route('accounts.edit', ['account' => $account->id])) @@ -45,7 +45,7 @@ class AccountsTest extends FeatureTestCase public function testItShouldUpdateAccount() { - $request = factory(Account::class)->raw(); + $request = $this->getRequest(); $account = $this->dispatch(new CreateAccount($request)); @@ -60,7 +60,7 @@ class AccountsTest extends FeatureTestCase public function testItShouldDeleteAccount() { - $account = $this->dispatch(new CreateAccount(factory(Account::class)->raw())); + $account = $this->dispatch(new CreateAccount($this->getRequest())); $this->loginAs() ->delete(route('accounts.destroy', ['account' => $account])) @@ -68,4 +68,9 @@ class AccountsTest extends FeatureTestCase $this->assertFlashLevel('success'); } + + public function getRequest() + { + return factory(Account::class)->states('enabled')->raw(); + } } diff --git a/tests/Feature/Banking/TransfersTest.php b/tests/Feature/Banking/TransfersTest.php index ecbd9d016..a01551415 100644 --- a/tests/Feature/Banking/TransfersTest.php +++ b/tests/Feature/Banking/TransfersTest.php @@ -69,11 +69,11 @@ class TransfersTest extends FeatureTestCase $this->assertFlashLevel('success'); } - private function getRequest() + public function getRequest() { - $income_transaction = factory(Transaction::class)->create(); + $income_transaction = factory(Transaction::class)->states('income')->create(); - $expense_transaction = factory(Transaction::class)->state('expense')->create(); + $expense_transaction = factory(Transaction::class)->states('expense')->create(); return [ 'company_id' => $this->company->id, diff --git a/tests/Feature/Common/ItemsTest.php b/tests/Feature/Common/ItemsTest.php index a1b6309eb..69ec4e6cc 100644 --- a/tests/Feature/Common/ItemsTest.php +++ b/tests/Feature/Common/ItemsTest.php @@ -27,7 +27,7 @@ class ItemsTest extends FeatureTestCase public function testItShouldCreateItem() { $this->loginAs() - ->post(route('items.store'), factory(Item::class)->raw()) + ->post(route('items.store'), $this->getRequest()) ->assertStatus(200); $this->assertFlashLevel('success'); @@ -35,7 +35,7 @@ class ItemsTest extends FeatureTestCase public function testItShouldSeeItemUpdatePage() { - $item = $this->dispatch(new CreateItem(factory(Item::class)->raw())); + $item = $this->dispatch(new CreateItem($this->getRequest())); $this->loginAs() ->get(route('items.edit', ['item' => $item->id])) @@ -45,7 +45,7 @@ class ItemsTest extends FeatureTestCase public function testItShouldUpdateItem() { - $request = factory(Item::class)->raw(); + $request = $this->getRequest(); $item = $this->dispatch(new CreateItem($request)); @@ -60,7 +60,7 @@ class ItemsTest extends FeatureTestCase public function testItShouldDeleteItem() { - $item = $this->dispatch(new CreateItem(factory(Item::class)->raw())); + $item = $this->dispatch(new CreateItem($this->getRequest())); $this->loginAs() ->delete(route('items.destroy', ['item' => $item])) @@ -68,4 +68,9 @@ class ItemsTest extends FeatureTestCase $this->assertFlashLevel('success'); } + + public function getRequest() + { + return factory(Item::class)->states('enabled')->raw(); + } } diff --git a/tests/Feature/Purchases/PaymentsTest.php b/tests/Feature/Purchases/PaymentsTest.php index ea5d1d931..e7da26a83 100644 --- a/tests/Feature/Purchases/PaymentsTest.php +++ b/tests/Feature/Purchases/PaymentsTest.php @@ -27,7 +27,7 @@ class PaymentsTest extends FeatureTestCase public function testItShouldCreatePayment() { $this->loginAs() - ->post(route('payments.store'), factory(Transaction::class)->states('expense')->raw()) + ->post(route('payments.store'), $this->getRequest()) ->assertStatus(200); $this->assertFlashLevel('success'); @@ -35,7 +35,7 @@ class PaymentsTest extends FeatureTestCase public function testItShouldUpdatePayment() { - $request = factory(Transaction::class)->states('expense')->raw(); + $request = $this->getRequest(); $payment = $this->dispatch(new CreateTransaction($request)); @@ -50,7 +50,7 @@ class PaymentsTest extends FeatureTestCase public function testItShouldDeletePayment() { - $payment = $this->dispatch(new CreateTransaction(factory(Transaction::class)->states('expense')->raw())); + $payment = $this->dispatch(new CreateTransaction($this->getRequest())); $this->loginAs() ->delete(route('payments.destroy', $payment->id)) @@ -58,4 +58,9 @@ class PaymentsTest extends FeatureTestCase $this->assertFlashLevel('success'); } + + public function getRequest() + { + return factory(Transaction::class)->states('expense')->raw(); + } } diff --git a/tests/Feature/Purchases/VendorsTest.php b/tests/Feature/Purchases/VendorsTest.php index df750651e..c76cb4eef 100644 --- a/tests/Feature/Purchases/VendorsTest.php +++ b/tests/Feature/Purchases/VendorsTest.php @@ -3,6 +3,7 @@ namespace Tests\Feature\Purchases; use App\Jobs\Common\CreateContact; +use App\Models\Common\Contact; use Tests\Feature\FeatureTestCase; class VendorsTest extends FeatureTestCase @@ -26,7 +27,7 @@ class VendorsTest extends FeatureTestCase public function testItShouldCreateVendor() { $this->loginAs() - ->post(route('vendors.store'), $this->getVendorRequest()) + ->post(route('vendors.store'), $this->getRequest()) ->assertStatus(200); $this->assertFlashLevel('success'); @@ -34,7 +35,7 @@ class VendorsTest extends FeatureTestCase public function testItShouldSeeVendorDetailPage() { - $vendor = $this->dispatch(new CreateContact($this->getVendorRequest())); + $vendor = $this->dispatch(new CreateContact($this->getRequest())); $this->loginAs() ->get(route('vendors.show', ['vendor' => $vendor->id])) @@ -44,7 +45,7 @@ class VendorsTest extends FeatureTestCase public function testItShouldSeeVendorUpdatePage() { - $vendor = $this->dispatch(new CreateContact($this->getVendorRequest())); + $vendor = $this->dispatch(new CreateContact($this->getRequest())); $this->loginAs() ->get(route('vendors.edit', ['vendor' => $vendor->id])) @@ -55,7 +56,7 @@ class VendorsTest extends FeatureTestCase public function testItShouldUpdateVendor() { - $request = $this->getVendorRequest(); + $request = $this->getRequest(); $vendor = $this->dispatch(new CreateContact($request)); @@ -70,7 +71,7 @@ class VendorsTest extends FeatureTestCase public function testItShouldDeleteVendor() { - $vendor = $this->dispatch(new CreateContact($this->getVendorRequest())); + $vendor = $this->dispatch(new CreateContact($this->getRequest())); $this->loginAs() ->delete(route('vendors.destroy', $vendor->id)) @@ -79,19 +80,8 @@ class VendorsTest extends FeatureTestCase $this->assertFlashLevel('success'); } - private function getVendorRequest() + public function getRequest() { - return [ - 'company_id' => $this->company->id, - 'type' => 'vendor', - 'name' => $this->faker->name, - 'email' => $this->faker->email, - 'tax_number' => $this->faker->randomNumber(9), - 'phone' => $this->faker->phoneNumber, - 'address' => $this->faker->address, - 'website' => 'www.akaunting.com', - 'currency_code' => $this->company->currencies()->enabled()->first()->code, - 'enabled' => $this->faker->boolean ? 1 : 0 - ]; + return factory(Contact::class)->states('vendor', 'enabled')->raw(); } } diff --git a/tests/Feature/Sales/CustomersTest.php b/tests/Feature/Sales/CustomersTest.php index 588de9486..879b5ec27 100644 --- a/tests/Feature/Sales/CustomersTest.php +++ b/tests/Feature/Sales/CustomersTest.php @@ -4,6 +4,7 @@ namespace Tests\Feature\Sales; use App\Jobs\Common\CreateContact; use App\Models\Auth\User; +use App\Models\Common\Contact; use Tests\Feature\FeatureTestCase; class CustomersTest extends FeatureTestCase @@ -27,7 +28,7 @@ class CustomersTest extends FeatureTestCase public function testItShouldCreateOnlyCustomerWithoutUser() { $this->loginAs() - ->post(route('customers.store'), $this->getCustomerRequest()) + ->post(route('customers.store'), $this->getRequest()) ->assertStatus(200); $this->assertFlashLevel('success'); @@ -35,7 +36,7 @@ class CustomersTest extends FeatureTestCase public function testItShouldCreateCustomerWithUser() { - $customer = $this->getCustomerRequestWithUser(); + $customer = $this->getRequestWithUser(); $this->loginAs() ->post(route('customers.store'), $customer) @@ -51,7 +52,7 @@ class CustomersTest extends FeatureTestCase public function testItShouldSeeCustomerDetailPage() { - $customer = $this->dispatch(new CreateContact($this->getCustomerRequest())); + $customer = $this->dispatch(new CreateContact($this->getRequest())); $this->loginAs() ->get(route('customers.show', ['customer' => $customer->id])) @@ -61,7 +62,7 @@ class CustomersTest extends FeatureTestCase public function testItShouldSeeCustomerUpdatePage() { - $customer = $this->dispatch(new CreateContact($this->getCustomerRequest())); + $customer = $this->dispatch(new CreateContact($this->getRequest())); $this->loginAs() ->get(route('customers.edit', ['customer' => $customer->id])) @@ -72,7 +73,7 @@ class CustomersTest extends FeatureTestCase public function testItShouldUpdateCustomer() { - $request = $this->getCustomerRequest(); + $request = $this->getRequest(); $customer = $this->dispatch(new CreateContact($request)); @@ -87,7 +88,7 @@ class CustomersTest extends FeatureTestCase public function testItShouldDeleteCustomer() { - $customer = $this->dispatch(new CreateContact($this->getCustomerRequest())); + $customer = $this->dispatch(new CreateContact($this->getRequest())); $this->loginAs() ->delete(route('customers.destroy', $customer->id)) @@ -103,31 +104,20 @@ class CustomersTest extends FeatureTestCase //TODO : This will write after done invoice and revenues tests. } - private function getCustomerRequest() - { - return [ - 'company_id' => $this->company->id, - 'type' => 'customer', - 'name' => $this->faker->name, - 'email' => $this->faker->email, - 'tax_number' => $this->faker->randomNumber(9), - 'phone' => $this->faker->phoneNumber, - 'address' => $this->faker->address, - 'website' => 'www.akaunting.com', - 'currency_code' => $this->company->currencies()->enabled()->first()->code, - 'enabled' => $this->faker->boolean ? 1 : 0 - ]; - } + public function getRequest() + { + return factory(Contact::class)->states('customer', 'enabled')->raw(); + } - private function getCustomerRequestWithUser() + public function getRequestWithUser() { $password = $this->faker->password; - return $this->getCustomerRequest() + [ + return $this->getRequest() + [ 'create_user' => 1, 'locale' => 'en-GB', 'password' => $password, - 'password_confirmation' => $password + 'password_confirmation' => $password, ]; } } diff --git a/tests/Feature/Sales/RevenuesTest.php b/tests/Feature/Sales/RevenuesTest.php index 5f0230ebf..b04b00432 100644 --- a/tests/Feature/Sales/RevenuesTest.php +++ b/tests/Feature/Sales/RevenuesTest.php @@ -27,7 +27,7 @@ class RevenuesTest extends FeatureTestCase public function testItShouldCreateRevenue() { $this->loginAs() - ->post(route('revenues.store'), factory(Transaction::class)->raw()) + ->post(route('revenues.store'), $this->getRequest()) ->assertStatus(200); $this->assertFlashLevel('success'); @@ -35,7 +35,7 @@ class RevenuesTest extends FeatureTestCase public function testItShouldUpdateRevenue() { - $request = factory(Transaction::class)->raw(); + $request = $this->getRequest(); $revenue = $this->dispatch(new CreateTransaction($request)); @@ -50,7 +50,7 @@ class RevenuesTest extends FeatureTestCase public function testItShouldDeleteRevenue() { - $revenue = $this->dispatch(new CreateTransaction(factory(Transaction::class)->raw())); + $revenue = $this->dispatch(new CreateTransaction($this->getRequest())); $this->loginAs() ->delete(route('revenues.destroy', $revenue->id)) @@ -58,4 +58,9 @@ class RevenuesTest extends FeatureTestCase $this->assertFlashLevel('success'); } + + public function getRequest() + { + return factory(Transaction::class)->states('income')->raw(); + } } From 2d2014b1895c26503e5aa74db9aec4ca66a5b09c Mon Sep 17 00:00:00 2001 From: denisdulici Date: Tue, 7 Jan 2020 01:30:42 +0300 Subject: [PATCH 2/3] fixed spaces --- database/factories/Account.php | 8 ++++---- database/factories/Item.php | 8 ++++---- database/factories/User.php | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/database/factories/Account.php b/database/factories/Account.php index d7fd642bd..b8cecf3f5 100644 --- a/database/factories/Account.php +++ b/database/factories/Account.php @@ -26,13 +26,13 @@ $factory->define(Account::class, function (Faker $faker) use ($company) { }); $factory->state(Account::class, 'enabled', function (Faker $faker) { - return [ + return [ 'enabled' => 1, - ]; + ]; }); $factory->state(Account::class, 'disabled', function (Faker $faker) { - return [ + return [ 'enabled' => 0, - ]; + ]; }); diff --git a/database/factories/Item.php b/database/factories/Item.php index 18f418fc3..961da412c 100644 --- a/database/factories/Item.php +++ b/database/factories/Item.php @@ -23,13 +23,13 @@ $factory->define(Item::class, function (Faker $faker) use ($company) { }); $factory->state(Item::class, 'enabled', function (Faker $faker) { - return [ + return [ 'enabled' => 1, - ]; + ]; }); $factory->state(Item::class, 'disabled', function (Faker $faker) { - return [ + return [ 'enabled' => 0, - ]; + ]; }); diff --git a/database/factories/User.php b/database/factories/User.php index ed8499d6a..e84e42687 100644 --- a/database/factories/User.php +++ b/database/factories/User.php @@ -22,12 +22,12 @@ $factory->define(User::class, function (Faker $faker) { $factory->state(User::class, 'enabled', function (Faker $faker) { return [ - 'enabled' => 1, + 'enabled' => 1, ]; }); $factory->state(User::class, 'disabled', function (Faker $faker) { return [ - 'enabled' => 0, + 'enabled' => 0, ]; }); From 44fd928fa16b4322481e87de7a0ea470d6c53cff Mon Sep 17 00:00:00 2001 From: denisdulici Date: Tue, 7 Jan 2020 01:32:52 +0300 Subject: [PATCH 3/3] more spaces --- database/factories/Account.php | 38 +++++++++++++++++----------------- database/factories/Item.php | 34 +++++++++++++++--------------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/database/factories/Account.php b/database/factories/Account.php index b8cecf3f5..296725fc9 100644 --- a/database/factories/Account.php +++ b/database/factories/Account.php @@ -9,30 +9,30 @@ $user = User::first(); $company = $user->companies()->first(); $factory->define(Account::class, function (Faker $faker) use ($company) { - setting()->setExtraColumns(['company_id' => $company->id]); + setting()->setExtraColumns(['company_id' => $company->id]); - return [ - 'company_id' => $company->id, - 'name' => $faker->text(5), - 'number' => (string) $faker->randomNumber(2), - 'currency_code' => setting('default.currency'), - //'currency_code' => Currency::enabled()->get()->random(1)->pluck('code')->first(), - 'opening_balance' => '0', - 'bank_name' => $faker->text(5), - 'bank_phone' => null, - 'bank_address' => null, - 'enabled' => $faker->boolean ? 1 : 0, - ]; + return [ + 'company_id' => $company->id, + 'name' => $faker->text(5), + 'number' => (string) $faker->randomNumber(2), + 'currency_code' => setting('default.currency'), + //'currency_code' => Currency::enabled()->get()->random(1)->pluck('code')->first(), + 'opening_balance' => '0', + 'bank_name' => $faker->text(5), + 'bank_phone' => null, + 'bank_address' => null, + 'enabled' => $faker->boolean ? 1 : 0, + ]; }); $factory->state(Account::class, 'enabled', function (Faker $faker) { - return [ - 'enabled' => 1, - ]; + return [ + 'enabled' => 1, + ]; }); $factory->state(Account::class, 'disabled', function (Faker $faker) { - return [ - 'enabled' => 0, - ]; + return [ + 'enabled' => 0, + ]; }); diff --git a/database/factories/Item.php b/database/factories/Item.php index 961da412c..6fdace2f9 100644 --- a/database/factories/Item.php +++ b/database/factories/Item.php @@ -8,28 +8,28 @@ $user = User::first(); $company = $user->companies()->first(); $factory->define(Item::class, function (Faker $faker) use ($company) { - setting()->setExtraColumns(['company_id' => $company->id]); + setting()->setExtraColumns(['company_id' => $company->id]); - return [ - 'company_id' => $company->id, - 'name' => $faker->text(15), - 'description' => $faker->text(100), - 'purchase_price' => $faker->randomFloat(2, 10, 20), - 'sale_price' => $faker->randomFloat(2, 10, 20), - 'category_id' => $company->categories()->type('item')->pluck('id')->first(), - 'tax_id' => null, - 'enabled' => $faker->boolean ? 1 : 0, - ]; + return [ + 'company_id' => $company->id, + 'name' => $faker->text(15), + 'description' => $faker->text(100), + 'purchase_price' => $faker->randomFloat(2, 10, 20), + 'sale_price' => $faker->randomFloat(2, 10, 20), + 'category_id' => $company->categories()->type('item')->pluck('id')->first(), + 'tax_id' => null, + 'enabled' => $faker->boolean ? 1 : 0, + ]; }); $factory->state(Item::class, 'enabled', function (Faker $faker) { - return [ - 'enabled' => 1, - ]; + return [ + 'enabled' => 1, + ]; }); $factory->state(Item::class, 'disabled', function (Faker $faker) { - return [ - 'enabled' => 0, - ]; + return [ + 'enabled' => 0, + ]; });