From 118218430684cba2d4a998de56fa3620d7762642 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 21 Aug 2023 09:51:56 +1000 Subject: [PATCH] Updates for L10 migration --- app/Http/Kernel.php | 2 +- composer.json | 2 +- composer.lock | 26 +- database/seeders/RandomDataSeeder.php | 1 - phpunit.xml | 3 +- tests/Feature/ReminderTest.php | 2 - tests/MockAccountData.php | 1 - tests/Unit/Migration/ImportTest.php | 448 -------------------------- 8 files changed, 17 insertions(+), 468 deletions(-) diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index f0cf330a16f0..171626827189 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -128,7 +128,7 @@ class Kernel extends HttpKernel * * @var array */ - protected $routeMiddleware = [ + protected $middlewareAliases = [ 'auth' => Authenticate::class, 'auth.basic' => AuthenticateWithBasicAuth::class, 'bindings' => SubstituteBindings::class, diff --git a/composer.json b/composer.json index 8be79d304d86..42082bfb62c7 100644 --- a/composer.json +++ b/composer.json @@ -66,7 +66,7 @@ "laravel/ui": "^4.0", "league/csv": "^9.6", "league/flysystem-aws-s3-v3": "^3.0", - "league/fractal": "^0.17.0", + "league/fractal": "^0.20.0", "league/omnipay": "^3.1", "livewire/livewire": "^2.10", "microsoft/microsoft-graph": "^1.69", diff --git a/composer.lock b/composer.lock index 680c4948ec2b..fea6971d7c21 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c54361d62a99c6382de6477fdc56cd7e", + "content-hash": "c6e70e26e10d4836ad93323a7efd7eb5", "packages": [ { "name": "adrienrn/php-mimetyper", @@ -5532,28 +5532,30 @@ }, { "name": "league/fractal", - "version": "0.17.0", + "version": "0.20.1", "source": { "type": "git", "url": "https://github.com/thephpleague/fractal.git", - "reference": "a0b350824f22fc2fdde2500ce9d6851a3f275b0e" + "reference": "8b9d39b67624db9195c06f9c1ffd0355151eaf62" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/fractal/zipball/a0b350824f22fc2fdde2500ce9d6851a3f275b0e", - "reference": "a0b350824f22fc2fdde2500ce9d6851a3f275b0e", + "url": "https://api.github.com/repos/thephpleague/fractal/zipball/8b9d39b67624db9195c06f9c1ffd0355151eaf62", + "reference": "8b9d39b67624db9195c06f9c1ffd0355151eaf62", "shasum": "" }, "require": { - "php": ">=5.4" + "php": ">=7.4" }, "require-dev": { "doctrine/orm": "^2.5", "illuminate/contracts": "~5.0", - "mockery/mockery": "~0.9", + "mockery/mockery": "^1.3", "pagerfanta/pagerfanta": "~1.0.0", - "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "~1.5", + "phpstan/phpstan": "^1.4", + "phpunit/phpunit": "^9.5", + "squizlabs/php_codesniffer": "~3.4", + "vimeo/psalm": "^4.22", "zendframework/zend-paginator": "~2.3" }, "suggest": { @@ -5564,7 +5566,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "0.13-dev" + "dev-master": "0.20.x-dev" } }, "autoload": { @@ -5594,9 +5596,9 @@ ], "support": { "issues": "https://github.com/thephpleague/fractal/issues", - "source": "https://github.com/thephpleague/fractal/tree/master" + "source": "https://github.com/thephpleague/fractal/tree/0.20.1" }, - "time": "2017-06-12T11:04:56+00:00" + "time": "2022-04-11T12:47:17+00:00" }, { "name": "league/mime-type-detection", diff --git a/database/seeders/RandomDataSeeder.php b/database/seeders/RandomDataSeeder.php index 13a0e89c091d..e508ba0daaee 100644 --- a/database/seeders/RandomDataSeeder.php +++ b/database/seeders/RandomDataSeeder.php @@ -296,7 +296,6 @@ class RandomDataSeeder extends Seeder // $payment->service()->updateInvoicePayment($payment_hash); - // UpdateInvoicePayment::dispatchNow($payment, $payment->company); } }); diff --git a/phpunit.xml b/phpunit.xml index cc7e424e14bd..81d3e64b46f4 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,5 @@ - - + ./tests/Unit diff --git a/tests/Feature/ReminderTest.php b/tests/Feature/ReminderTest.php index c55c302d8c22..2d77e88e8ad9 100644 --- a/tests/Feature/ReminderTest.php +++ b/tests/Feature/ReminderTest.php @@ -268,7 +268,6 @@ class ReminderTest extends TestCase $this->assertEquals(Carbon::parse($this->invoice->next_send_date)->format('Y-m-d'), Carbon::now()->addDays(7)->format('Y-m-d')); - // ReminderJob::dispatchNow(); } public function testReminderHitsScenarioH1() @@ -293,7 +292,6 @@ class ReminderTest extends TestCase $this->assertEquals(Carbon::parse($this->invoice->next_send_date)->format('Y-m-d'), Carbon::now()->addDays(30)->subDays(2)->format('Y-m-d')); - // ReminderJob::dispatchNow(); } /* Cant set a reminder in the past so need to skip reminder 2 and go straigh to reminder 3*/ diff --git a/tests/MockAccountData.php b/tests/MockAccountData.php index 3d780ea1fad3..d270d172edba 100644 --- a/tests/MockAccountData.php +++ b/tests/MockAccountData.php @@ -719,7 +719,6 @@ trait MockAccountData $this->invoice->save(); $this->invoice->ledger()->updateInvoiceBalance($this->invoice->amount); - // UpdateCompanyLedgerWithInvoice::dispatchNow($this->invoice, $this->invoice->amount, $this->invoice->company); $user_id = $this->invoice->user_id; diff --git a/tests/Unit/Migration/ImportTest.php b/tests/Unit/Migration/ImportTest.php index 0cf8c1168565..a482715b3dfe 100644 --- a/tests/Unit/Migration/ImportTest.php +++ b/tests/Unit/Migration/ImportTest.php @@ -11,26 +11,7 @@ namespace Tests\Unit\Migration; -use App\Exceptions\ResourceDependencyMissing; -use App\Exceptions\ResourceNotAvailableForMigration; -use App\Jobs\Util\Import; -use App\Jobs\Util\StartMigration; -use App\Mail\MigrationFailed; -use App\Models\Client; -use App\Models\ClientContact; -use App\Models\ClientGatewayToken; -use App\Models\Company; -use App\Models\CompanyGateway; -use App\Models\Credit; -use App\Models\Document; -use App\Models\Invoice; -use App\Models\Payment; -use App\Models\Product; -use App\Models\Quote; -use App\Models\TaxRate; -use App\Models\User; use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Support\Facades\Mail; use Tests\MockAccountData; use Tests\TestCase; @@ -59,433 +40,4 @@ class ImportTest extends TestCase $this->assertTrue($status); } - // public function testAllImport() - // { - - // $this->invoice->forceDelete(); - // $this->quote->forceDelete(); - - // $this->user->setCompany($this->company); - // auth()->login($this->user, true); - - // Import::dispatchNow($this->migration_array, $this->company, $this->user); - - // $this->assertTrue(true); - // } - -// public function testExceptionOnUnavailableResource() -// { -// $data['panda_bears'] = [ -// 'name' => 'Awesome Panda Bear', -// ]; - -// try { -// Import::dispatchNow($data, $this->company, $this->user); -// } -// catch (ResourceNotAvailableForMigration $e) { -// $this->assertTrue(true); -// } -// } - -// public function testCompanyUpdating() -// { -// $original_company_key = $this->company->company_key; - -// $data['company'] = [ -// 'company_key' => 0, -// ]; - -// Import::dispatchNow($data, $this->company, $this->user); - -// $this->assertNotEquals($original_company_key, $this->company->company_key); -// } - -// public function testInvoicesFailsWithoutClient() -// { -// $data['invoices'] = [ -// 0 => [ -// 'client_id' => 1, -// 'is_amount_discount' => false, -// ] -// ]; - -// try { -// Import::dispatchNow($data, $this->company, $this->user); -// } catch(ResourceDependencyMissing $e) { -// $this->assertTrue(true); -// } -// } - -// public function testInvoicesImporting() -// { -// $this->makeTestData(); - -// $this->invoice->forceDelete(); -// $this->quote->forceDelete(); - -// $original_count = Invoice::count(); - -// Import::dispatchNow($this->migration_array, $this->company, $this->user); - -// $this->assertGreaterThan($original_count, Invoice::count()); -// } - -// public function testQuotesFailsWithoutClient() -// { -// $data['quotes'] = [ -// 0 => [ -// 'client_id' => 1, -// 'is_amount_discount' => false, -// ] -// ]; - -// try { -// Import::dispatchNow($data, $this->company, $this->user); -// } catch(ResourceDependencyMissing $e) { -// $this->assertTrue(true); -// } -// } - -// public function testImportFileExists() -// { -// $this->assertGreaterThan(1, count($this->migration_array)); - -// } - -// public function testClientAttributes() -// { -// $original_number = Client::count(); - -// $random_balance = rand(0, 10); - -// $data['clients'] = [ -// 0 => [ -// 'id' => 1, -// 'name' => 'My awesome unique client', -// 'balance' => $random_balance, -// 'user_id' => 1, -// ] -// ]; - -// Import::dispatchNow($data, $this->company, $this->user); - -// $client = Client::where('name', 'My awesome unique client') -// ->where('balance', $random_balance) -// ->first(); - -// $this->assertNotNull($client); -// $this->assertGreaterThan($original_number, Client::count()); -// $this->assertGreaterThanOrEqual(0, $client->balance); -// } - -// // public function testInvoiceAttributes() -// // { -// // $original_number = Invoice::count(); - -// // $this->invoice->forceDelete(); - -// // $migration_file = base_path() . '/tests/Unit/Migration/migration.json'; - -// // $this->migration_array = json_decode(file_get_contents($migration_file), 1); - -// // Import::dispatchNow($this->migration_array, $this->company, $this->user); - -// // $this->assertGreaterThan($original_number, Invoice::count()); - -// // $invoice_1 = Invoice::whereNumber('0001') -// // // ->where('discount', '0.00') -// // // ->where('date', '2020-03-18') -// // ->first(); - -// // $invoice_2 = Invoice::whereNumber('0018') -// // // ->where('discount', '0.00') -// // // ->where('date', '2019-10-15') -// // ->first(); - -// // $this->assertNotNull($invoice_1); -// // $this->assertNotNull($invoice_2); - -// // $this->assertEquals('13.5000', $invoice_1->amount); -// // $this->assertEquals('67.4100', $invoice_2->amount); - -// // $this->assertEquals('8.4900', $invoice_1->balance); -// // $this->assertEquals('50.4200', $invoice_2->balance); -// // } - -// // public function testQuoteAttributes() -// // { -// // $original_number = Quote::count(); - -// // $this->invoice->forceDelete(); - -// // $migration_file = base_path() . '/tests/Unit/Migration/migration.json'; - -// // $this->migration_array = json_decode(file_get_contents($migration_file), 1); - -// // Import::dispatchNow($this->migration_array, $this->company, $this->user); - -// // $this->assertGreaterThan($original_number, Invoice::count()); - -// // $quote = Quote::whereNumber('0021') -// // ->whereDiscount('0.00') -// // ->first(); - -// // $this->assertNotNull($quote); -// // $this->assertEquals('0.0000', $quote->amount); -// // $this->assertEquals('0.0000', $quote->balance); -// // } - -// public function testPaymentsImport() -// { -// $original_count = Payment::count(); - -// $this->invoice->forceDelete(); -// $this->quote->forceDelete(); -// Import::dispatchNow($this->migration_array, $this->company, $this->user); - -// $this->assertGreaterThan($original_count, Payment::count()); -// } - -// public function testPaymentDependsOnClient() -// { -// $data['payments'] = [ -// 0 => [ -// 'client_id' => 1, -// 'amount' => 1, -// ] -// ]; - -// try { -// Import::dispatchNow($data, $this->company, $this->user); -// } catch(ResourceDependencyMissing $e) { -// $this->assertTrue(true); -// } -// } - -// public function testQuotesImport() -// { -// $original_count = Credit::count(); - -// $this->invoice->forceDelete(); -// $this->quote->forceDelete(); - -// Import::dispatchNow($this->migration_array, $this->company, $this->user); - -// $this->assertGreaterThan($original_count, Credit::count()); -// } - -// public function testMigrationFileExists() -// { -// $migration_archive = base_path() . '/tests/Unit/Migration/migration.zip'; - -// $this->assertTrue(file_exists($migration_archive)); -// } - -// // public function testMigrationFileBeingExtracted() -// // { -// // $migration_archive = base_path() . '/tests/Unit/Migration/migration.zip'; - -// // StartMigration::dispatchNow($migration_archive, $this->user, $this->company); - -// // $extracted_archive = storage_path("migrations/migration"); -// // $migration_file = storage_path("migrations/migration/migration.json"); - -// // $this->assertTrue(file_exists($extracted_archive)); -// // $this->assertTrue(is_dir($extracted_archive)); -// // $this->assertTrue(file_exists($migration_file)); -// // } - -// public function testValidityOfImportedData() -// { -// $this->invoice->forceDelete(); -// $this->quote->forceDelete(); - -// Import::dispatchNow($this->migration_array, $this->company, $this->user); - -// $differences = []; - -// foreach ($this->migration_array['invoices'] as $key => $invoices) { -// $record = Invoice::whereNumber($invoices['number']) -// ->whereAmount($invoices['amount']) -// ->whereBalance($invoices['balance']) -// ->first(); - -// if (!$record) { -// $differences['invoices']['missing'][] = $invoices['id']; -// } -// } - -// foreach ($this->migration_array['users'] as $key => $user) { -// $record = User::whereEmail($user['email'])->first(); - -// if (!$record) { -// $differences['users']['missing'][] = $user['email']; -// } -// } - -// foreach ($this->migration_array['tax_rates'] as $key => $tax_rate) { -// $record = TaxRate::whereName($tax_rate['name']) -// ->where('rate', $tax_rate['rate']) -// ->first(); - -// if (!$record) { -// $differences['tax_rates']['missing'][] = $tax_rate['name']; -// } -// } - -// foreach ($this->migration_array['clients'] as $key => $client) { -// $record = Client::whereName($client['name']) -// ->whereCity($client['city']) -// // ->where('paid_to_date', $client['paid_to_date']) // TODO: Doesn't work. Need debugging. -// ->first(); - -// if (!$record) { -// $differences['clients']['missing'][] = $client['name']; -// } -// } - -// foreach ($this->migration_array['products'] as $key => $product) { -// $record = Product::where('product_key', $product['product_key']) -// ->first(); - -// if (!$record) { -// $differences['products']['missing'][] = $product['notes']; -// } -// } - -// foreach ($this->migration_array['quotes'] as $key => $quote) { -// $record = Quote::whereNumber($quote['number']) -// ->whereIsAmountDiscount($quote['is_amount_discount']) -// ->whereDueDate($quote['due_date']) -// ->first(); - -// if (!$record) { -// $differences['quotes']['missing'][] = $quote['id']; -// } -// } - -// foreach ($this->migration_array['payments'] as $key => $payment) { -// $record = Payment::whereApplied($payment['applied']) -// ->first(); - -// if (!$record) { -// $differences['payments']['missing'][] = $payment['id']; -// } -// } - -// foreach ($this->migration_array['credits'] as $key => $credit) { - -// // The Import::processCredits() does insert the credit record with number: 0053, -// // .. however this part of the code doesn't see it at all. - -// $record = Credit::whereNumber($credit['number']) -// ->first(); - -// if (!$record) { -// $differences['credits']['missing'][] = $credit['id']; -// } -// } - -// /* -// foreach ($this->migration_array['company_gateways'] as $key => $company_gateway) { - -// // The Import::processCredits() does insert the credit record with number: 0053, -// // .. however this part of the code doesn't see it at all. - -// $record = CompanyGateway::where('gateway_key' ,$company_gateway['gateway_key']) -// ->first(); - -// if (!$record) { -// $differences['company_gateways']['missing'][] = $company_gateway['id']; -// } -// } - -// foreach ($this->migration_array['client_gateway_tokens'] as $key => $cgt) { - -// // The Import::processCredits() does insert the credit record with number: 0053, -// // .. however this part of the code doesn't see it at all. - -// $record = ClientGatewayToken::where('token' ,$cgt['token']) -// ->first(); - -// if (!$record) { -// $differences['client_gateway_tokens']['missing'][] = $cgt['id']; -// } -// } -// */ -// //@TODO we can uncomment tests for documents when we have imported expenses. - -// // foreach ($this->migration_array['documents'] as $key => $document) { - -// // if(!is_null($document['invoice_id'])) { - -// // $record = Document::where('hash', $document['hash']) -// // ->first(); - -// // if (!$record) { -// // $differences['documents']['missing'][] = $document['id']; -// // } -// // } -// // } - -// //\Log::error($differences); - -// $this->assertCount(0, $differences); -// } - -// public function testClientContactsImport() -// { -// $this->invoice->forceDelete(); -// $this->quote->forceDelete(); - -// $original = ClientContact::count(); - -// Import::dispatchNow($this->migration_array, $this->company, $this->user); - -// $this->assertGreaterThan($original, ClientContact::count()); -// } - -// public function testClientGatewayTokensImport() -// { -// $this->invoice->forceDelete(); -// $this->quote->forceDelete(); - -// $original = ClientGatewayToken::count(); - -// Import::dispatchNow($this->migration_array, $this->company, $this->user); - -// $this->assertTrue(true, 'ClientGatewayTokens importing not completed yet.'); - -// } - -// public function testDocumentsImport() -// { -// $this->invoice->forceDelete(); -// $this->quote->forceDelete(); - -// $original = Document::count(); - -// Import::dispatchNow($this->migration_array, $this->company, $this->user); - -// $document = Document::first(); - -// $this->assertTrue(true, 'Documents importing not completed yet. Missing expenses.'); -// } - -// public function testExceptionMailSending() -// { -// Mail::fake(); - -// $data['panda_bears'] = [ -// 'name' => 'Awesome Panda Bear', -// ]; - -// try { -// Import::dispatchNow($data, $this->company, $this->user); -// } -// catch (ResourceNotAvailableForMigration $e) { -// Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage())); -// $this->assertTrue(true); -// } -// } }