Improve how tests function under parallel testing

This commit is contained in:
David Bomba 2023-01-18 17:35:43 +11:00
parent 0d767f7d98
commit d708d054f2
4 changed files with 23 additions and 32 deletions

View File

@ -40,6 +40,9 @@ class InvitationTest extends TestCase
protected function setUp() :void
{
parent::setUp();
$this->faker = \Faker\Factory::create();
}
public function testInvoiceCreationAfterInvoiceMarkedSent()
@ -52,10 +55,13 @@ class InvitationTest extends TestCase
$account->default_company_id = $company->id;
$account->save();
$user = User::where('email', 'user@example.com')->first();
$fake_email = $this->faker->email();
$user = User::where('email', $fake_email)->first();
if (! $user) {
$user = User::factory()->create([
'email' => $fake_email,
'account_id' => $account->id,
'confirmation_code' => $this->createDbHash(config('database.default')),
]);

View File

@ -54,29 +54,8 @@ class CompanyLedgerTest extends TestCase
$this->artisan('db:seed --force');
/* Warm up the cache !*/
$cached_tables = config('ninja.cached_tables');
foreach ($cached_tables as $name => $class) {
// check that the table exists in case the migration is pending
if (! Schema::hasTable((new $class())->getTable())) {
continue;
}
if ($name == 'payment_terms') {
$orderBy = 'num_days';
} elseif ($name == 'fonts') {
$orderBy = 'sort_order';
} elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) {
$orderBy = 'name';
} else {
$orderBy = 'id';
}
$tableData = $class::orderBy($orderBy)->get();
if ($tableData->count()) {
Cache::forever($name, $tableData);
}
}
$this->faker = \Faker\Factory::create();
$fake_email = $this->faker->email();
$this->account = Account::factory()->create();
$this->company = Company::factory()->create([
@ -93,7 +72,7 @@ class CompanyLedgerTest extends TestCase
$settings->state = 'State';
$settings->postal_code = 'Postal Code';
$settings->phone = '555-343-2323';
$settings->email = 'user@example.com';
$settings->email = $fake_email;
$settings->country_id = '840';
$settings->vat_number = 'vat number';
$settings->id_number = 'id number';
@ -106,10 +85,12 @@ class CompanyLedgerTest extends TestCase
$this->account->default_company_id = $this->company->id;
$this->account->save();
$user = User::whereEmail('user@example.com')->first();
$user = User::whereEmail($fake_email)->first();
if (! $user) {
$user = User::factory()->create([
'email' => $fake_email,
'account_id' => $this->account->id,
'password' => Hash::make('ALongAndBriliantPassword'),
'confirmation_code' => $this->createDbHash(config('database.default')),

View File

@ -213,6 +213,9 @@ trait MockAccountData
}
}
$this->faker = \Faker\Factory::create();
$fake_email = $this->faker->email();
$this->account = Account::factory()->create([
'hosted_client_count' => 1000,
'hosted_company_count' => 1000,
@ -233,7 +236,6 @@ trait MockAccountData
$settings = CompanySettings::defaults();
$settings->company_logo = 'https://pdf.invoicing.co/favicon-v2.png';
// $settings->company_logo = asset('images/new_logo.png');
$settings->website = 'www.invoiceninja.com';
$settings->address1 = 'Address 1';
$settings->address2 = 'Address 2';
@ -241,7 +243,7 @@ trait MockAccountData
$settings->state = 'State';
$settings->postal_code = 'Postal Code';
$settings->phone = '555-343-2323';
$settings->email = 'user@example.com';
$settings->email = $fake_email;
$settings->country_id = '840';
$settings->vat_number = 'vat number';
$settings->id_number = 'id number';
@ -256,13 +258,13 @@ trait MockAccountData
$this->account->default_company_id = $this->company->id;
$this->account->save();
$user = User::whereEmail('user@example.com')->first();
$user = User::whereEmail($fake_email)->first();
if (! $user) {
$user = User::factory()->create([
'account_id' => $this->account->id,
'confirmation_code' => $this->createDbHash(config('database.default')),
'email' => 'user@example.com',
'email' => $fake_email,
]);
}

View File

@ -62,13 +62,15 @@ class GeneratesConvertedQuoteCounterTest extends TestCase
$this->account->num_users = 3;
$this->account->save();
$user = User::whereEmail('user@example.com')->first();
$fake_email = $this->faker->email();
$user = User::whereEmail($fake_email)->first();
if (! $user) {
$user = User::factory()->create([
'account_id' => $this->account->id,
'confirmation_code' => $this->createDbHash(config('database.default')),
'email' => 'user@example.com',
'email' => $fake_email,
]);
}