From d20f5d2d56e038fd8f6867f67c4008ea99df4d0c Mon Sep 17 00:00:00 2001 From: EnesSacid-Buker Date: Thu, 15 Dec 2022 12:21:04 +0300 Subject: [PATCH] Tests are refactored --- tests/Feature/Banking/TransactionsTest.php | 21 +++++++++++---------- tests/Feature/Common/ItemsTest.php | 21 +++++++++++---------- tests/Feature/Purchases/BillsTest.php | 21 +++++++++++---------- tests/Feature/Purchases/VendorsTest.php | 21 +++++++++++---------- tests/Feature/Sales/CustomersTest.php | 21 +++++++++++---------- tests/Feature/Sales/InvoicesTest.php | 21 +++++++++++---------- 6 files changed, 66 insertions(+), 60 deletions(-) diff --git a/tests/Feature/Banking/TransactionsTest.php b/tests/Feature/Banking/TransactionsTest.php index 18b65e2a8..eabe05ef6 100644 --- a/tests/Feature/Banking/TransactionsTest.php +++ b/tests/Feature/Banking/TransactionsTest.php @@ -7,6 +7,7 @@ use App\Jobs\Banking\CreateTransaction; use App\Models\Banking\Transaction; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\File; +use Maatwebsite\Excel\Facades\Excel; use Tests\Feature\FeatureTestCase; class TransactionsTest extends FeatureTestCase @@ -119,16 +120,16 @@ class TransactionsTest extends FeatureTestCase $count = 5; Transaction::factory()->income()->count($count)->create(); - \Excel::fake(); + Excel::fake(); $this->loginAs() ->get(route('transactions.export')) ->assertStatus(200); - \Excel::matchByRegex(); + Excel::matchByRegex(); - \Excel::assertDownloaded( - '/' . \Str::filename(trans_choice('general.transactions', 2)) . '-\d{10}\.xlsx/', + Excel::assertDownloaded( + '/' . str()->filename(trans_choice('general.transactions', 2), '-') . '-\d{10}\.xlsx/', function (Export $export) use ($count) { // Assert that the correct export is downloaded. return $export->collection()->count() === $count; @@ -143,7 +144,7 @@ class TransactionsTest extends FeatureTestCase $transactions = Transaction::factory()->income()->count($create_count)->create(); - \Excel::fake(); + Excel::fake(); $this->loginAs() ->post( @@ -152,10 +153,10 @@ class TransactionsTest extends FeatureTestCase ) ->assertStatus(200); - \Excel::matchByRegex(); + Excel::matchByRegex(); - \Excel::assertDownloaded( - '/' . \Str::filename(trans_choice('general.transactions', 2)) . '-\d{10}\.xlsx/', + Excel::assertDownloaded( + '/' . str()->filename(trans_choice('general.transactions', 2), '-') . '-\d{10}\.xlsx/', function (Export $export) use ($select_count) { return $export->collection()->count() === $select_count; } @@ -164,7 +165,7 @@ class TransactionsTest extends FeatureTestCase public function testItShouldImportTransactions() { - \Excel::fake(); + Excel::fake(); $this->loginAs() ->post( @@ -178,7 +179,7 @@ class TransactionsTest extends FeatureTestCase ) ->assertStatus(200); - \Excel::assertImported('transactions.xlsx'); + Excel::assertImported('transactions.xlsx'); $this->assertFlashLevel('success'); } diff --git a/tests/Feature/Common/ItemsTest.php b/tests/Feature/Common/ItemsTest.php index e83900502..d1038b589 100644 --- a/tests/Feature/Common/ItemsTest.php +++ b/tests/Feature/Common/ItemsTest.php @@ -7,6 +7,7 @@ use App\Jobs\Common\CreateItem; use App\Models\Common\Item; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\File; +use Maatwebsite\Excel\Facades\Excel; use Tests\Feature\FeatureTestCase; class ItemsTest extends FeatureTestCase @@ -90,16 +91,16 @@ class ItemsTest extends FeatureTestCase $count = 5; Item::factory()->count($count)->create(); - \Excel::fake(); + Excel::fake(); $this->loginAs() ->get(route('items.export')) ->assertStatus(200); - \Excel::matchByRegex(); + Excel::matchByRegex(); - \Excel::assertDownloaded( - '/' . \Str::filename(trans_choice('general.items', 2)) . '-\d{10}\.xlsx/', + Excel::assertDownloaded( + '/' . str()->filename(trans_choice('general.items', 2), '-') . '-\d{10}\.xlsx/', function (Export $export) use ($count) { // Assert that the correct export is downloaded. return $export->sheets()[0]->collection()->count() === $count; @@ -114,7 +115,7 @@ class ItemsTest extends FeatureTestCase $items = Item::factory()->count($create_count)->create(); - \Excel::fake(); + Excel::fake(); $this->loginAs() ->post( @@ -123,10 +124,10 @@ class ItemsTest extends FeatureTestCase ) ->assertStatus(200); - \Excel::matchByRegex(); + Excel::matchByRegex(); - \Excel::assertDownloaded( - '/' . \Str::filename(trans_choice('general.items', 2)) . '-\d{10}\.xlsx/', + Excel::assertDownloaded( + '/' . str()->filename(trans_choice('general.items', 2), '-') . '-\d{10}\.xlsx/', function (Export $export) use ($select_count) { // Assert that the correct export is downloaded. return $export->sheets()[0]->collection()->count() === $select_count; @@ -136,7 +137,7 @@ class ItemsTest extends FeatureTestCase public function testItShouldImportItems() { - \Excel::fake(); + Excel::fake(); $this->loginAs() ->post( @@ -150,7 +151,7 @@ class ItemsTest extends FeatureTestCase ) ->assertStatus(200); - \Excel::assertImported('items.xlsx'); + Excel::assertImported('items.xlsx'); $this->assertFlashLevel('success'); } diff --git a/tests/Feature/Purchases/BillsTest.php b/tests/Feature/Purchases/BillsTest.php index ed5d35c7a..050b20d25 100644 --- a/tests/Feature/Purchases/BillsTest.php +++ b/tests/Feature/Purchases/BillsTest.php @@ -9,6 +9,7 @@ use Illuminate\Http\UploadedFile; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Storage; +use Maatwebsite\Excel\Facades\Excel; use Tests\Feature\FeatureTestCase; class BillsTest extends FeatureTestCase @@ -170,16 +171,16 @@ class BillsTest extends FeatureTestCase $count = 5; Document::factory()->bill()->count($count)->create(); - \Excel::fake(); + Excel::fake(); $this->loginAs() ->get(route('bills.export')) ->assertStatus(200); - \Excel::matchByRegex(); + Excel::matchByRegex(); - \Excel::assertDownloaded( - '/' . \Str::filename(trans_choice('general.bills', 2)) . '-\d{10}\.xlsx/', + Excel::assertDownloaded( + '/' . str()->filename(trans_choice('general.bills', 2), '-') . '-\d{10}\.xlsx/', function (Export $export) use ($count) { // Assert that the correct export is downloaded. return $export->sheets()[0]->collection()->count() === $count; @@ -194,7 +195,7 @@ class BillsTest extends FeatureTestCase $bills = Document::factory()->bill()->count($create_count)->create(); - \Excel::fake(); + Excel::fake(); $this->loginAs() ->post( @@ -203,10 +204,10 @@ class BillsTest extends FeatureTestCase ) ->assertStatus(200); - \Excel::matchByRegex(); + Excel::matchByRegex(); - \Excel::assertDownloaded( - '/' . \Str::filename(trans_choice('general.bills', 2)) . '-\d{10}\.xlsx/', + Excel::assertDownloaded( + '/' . str()->filename(trans_choice('general.bills', 2), '-') . '-\d{10}\.xlsx/', function (Export $export) use ($select_count) { return $export->sheets()[0]->collection()->count() === $select_count; } @@ -215,7 +216,7 @@ class BillsTest extends FeatureTestCase public function testItShouldImportBills() { - \Excel::fake(); + Excel::fake(); $this->loginAs() ->post( @@ -229,7 +230,7 @@ class BillsTest extends FeatureTestCase ) ->assertStatus(200); - \Excel::assertImported('bills.xlsx'); + Excel::assertImported('bills.xlsx'); $this->assertFlashLevel('success'); } diff --git a/tests/Feature/Purchases/VendorsTest.php b/tests/Feature/Purchases/VendorsTest.php index 2a14a4e37..19f2acb58 100644 --- a/tests/Feature/Purchases/VendorsTest.php +++ b/tests/Feature/Purchases/VendorsTest.php @@ -7,6 +7,7 @@ use App\Jobs\Common\CreateContact; use App\Models\Common\Contact; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\File; +use Maatwebsite\Excel\Facades\Excel; use Tests\Feature\FeatureTestCase; class VendorsTest extends FeatureTestCase @@ -116,16 +117,16 @@ class VendorsTest extends FeatureTestCase Contact::factory()->vendor()->count(5)->create(); $count = Contact::vendor()->count(); - \Excel::fake(); + Excel::fake(); $this->loginAs() ->get(route('vendors.export')) ->assertStatus(200); - \Excel::matchByRegex(); + Excel::matchByRegex(); - \Excel::assertDownloaded( - '/' . \Str::filename(trans_choice('general.vendors', 2)) . '-\d{10}\.xlsx/', + Excel::assertDownloaded( + '/' . str()->filename(trans_choice('general.vendors', 2), '-') . '-\d{10}\.xlsx/', function (Export $export) use ($count) { // Assert that the correct export is downloaded. return $export->collection()->count() === $count; @@ -140,7 +141,7 @@ class VendorsTest extends FeatureTestCase $vendors = Contact::factory()->vendor()->count($create_count)->create(); - \Excel::fake(); + Excel::fake(); $this->loginAs() ->post( @@ -149,10 +150,10 @@ class VendorsTest extends FeatureTestCase ) ->assertStatus(200); - \Excel::matchByRegex(); + Excel::matchByRegex(); - \Excel::assertDownloaded( - '/' . \Str::filename(trans_choice('general.vendors', 2)) . '-\d{10}\.xlsx/', + Excel::assertDownloaded( + '/' . str()->filename(trans_choice('general.vendors', 2), '-') . '-\d{10}\.xlsx/', function (Export $export) use ($select_count) { return $export->collection()->count() === $select_count; } @@ -161,7 +162,7 @@ class VendorsTest extends FeatureTestCase public function testItShouldImportVendors() { - \Excel::fake(); + Excel::fake(); $this->loginAs() ->post( @@ -175,7 +176,7 @@ class VendorsTest extends FeatureTestCase ) ->assertStatus(200); - \Excel::assertImported('vendors.xlsx'); + Excel::assertImported('vendors.xlsx'); $this->assertFlashLevel('success'); } diff --git a/tests/Feature/Sales/CustomersTest.php b/tests/Feature/Sales/CustomersTest.php index ac2b19f3b..965d07039 100644 --- a/tests/Feature/Sales/CustomersTest.php +++ b/tests/Feature/Sales/CustomersTest.php @@ -8,6 +8,7 @@ use App\Models\Auth\User; use App\Models\Common\Contact; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\File; +use Maatwebsite\Excel\Facades\Excel; use Tests\Feature\FeatureTestCase; class CustomersTest extends FeatureTestCase @@ -137,16 +138,16 @@ class CustomersTest extends FeatureTestCase Contact::factory()->customer()->count(5)->create(); $count = Contact::customer()->count(); - \Excel::fake(); + Excel::fake(); $this->loginAs() ->get(route('customers.export')) ->assertStatus(200); - \Excel::matchByRegex(); + Excel::matchByRegex(); - \Excel::assertDownloaded( - '/' . \Str::filename(trans_choice('general.customers', 2)) . '-\d{10}\.xlsx/', + Excel::assertDownloaded( + '/' . str()->filename(trans_choice('general.customers', 2), '-') . '-\d{10}\.xlsx/', function (Export $export) use ($count) { // Assert that the correct export is downloaded. return $export->collection()->count() === $count; @@ -161,7 +162,7 @@ class CustomersTest extends FeatureTestCase $customers = Contact::factory()->customer()->count($create_count)->create(); - \Excel::fake(); + Excel::fake(); $this->loginAs() ->post( @@ -170,10 +171,10 @@ class CustomersTest extends FeatureTestCase ) ->assertStatus(200); - \Excel::matchByRegex(); + Excel::matchByRegex(); - \Excel::assertDownloaded( - '/' . \Str::filename(trans_choice('general.customers', 2)) . '-\d{10}\.xlsx/', + Excel::assertDownloaded( + '/' . str()->filename(trans_choice('general.customers', 2), '-') . '-\d{10}\.xlsx/', function (Export $export) use ($select_count) { return $export->collection()->count() === $select_count; } @@ -182,7 +183,7 @@ class CustomersTest extends FeatureTestCase public function testItShouldImportCustomers() { - \Excel::fake(); + Excel::fake(); $this->loginAs() ->post( @@ -196,7 +197,7 @@ class CustomersTest extends FeatureTestCase ) ->assertStatus(200); - \Excel::assertImported('customers.xlsx'); + Excel::assertImported('customers.xlsx'); $this->assertFlashLevel('success'); } diff --git a/tests/Feature/Sales/InvoicesTest.php b/tests/Feature/Sales/InvoicesTest.php index 0e1558391..095824a72 100644 --- a/tests/Feature/Sales/InvoicesTest.php +++ b/tests/Feature/Sales/InvoicesTest.php @@ -9,6 +9,7 @@ use Illuminate\Http\UploadedFile; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Storage; +use Maatwebsite\Excel\Facades\Excel; use Tests\Feature\FeatureTestCase; class InvoicesTest extends FeatureTestCase @@ -181,16 +182,16 @@ class InvoicesTest extends FeatureTestCase $count = 5; Document::factory()->invoice()->count($count)->create(); - \Excel::fake(); + Excel::fake(); $this->loginAs() ->get(route('invoices.export')) ->assertStatus(200); - \Excel::matchByRegex(); + Excel::matchByRegex(); - \Excel::assertDownloaded( - '/' . \Str::filename(trans_choice('general.invoices', 2)) . '-\d{10}\.xlsx/', + Excel::assertDownloaded( + '/' . str()->filename(trans_choice('general.invoices', 2), '-') . '-\d{10}\.xlsx/', function (Export $export) use ($count) { // Assert that the correct export is downloaded. return $export->sheets()[0]->collection()->count() === $count; @@ -205,7 +206,7 @@ class InvoicesTest extends FeatureTestCase $invoices = Document::factory()->invoice()->count($create_count)->create(); - \Excel::fake(); + Excel::fake(); $this->loginAs() ->post( @@ -214,10 +215,10 @@ class InvoicesTest extends FeatureTestCase ) ->assertStatus(200); - \Excel::matchByRegex(); + Excel::matchByRegex(); - \Excel::assertDownloaded( - '/' . \Str::filename(trans_choice('general.invoices', 2)) . '-\d{10}\.xlsx/', + Excel::assertDownloaded( + '/' . str()->filename(trans_choice('general.invoices', 2), '-') . '-\d{10}\.xlsx/', function (Export $export) use ($select_count) { return $export->sheets()[0]->collection()->count() === $select_count; } @@ -226,7 +227,7 @@ class InvoicesTest extends FeatureTestCase public function testItShouldImportInvoices() { - \Excel::fake(); + Excel::fake(); $this->loginAs() ->post( @@ -240,7 +241,7 @@ class InvoicesTest extends FeatureTestCase ) ->assertStatus(200); - \Excel::assertImported('invoices.xlsx'); + Excel::assertImported('invoices.xlsx'); $this->assertFlashLevel('success'); }