From 6dbcec23105380c93fedab1059d7b841d2758311 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 7 Feb 2023 16:16:39 -0800 Subject: [PATCH 01/27] Exclude Dusk tests from phpunit test suite --- phpunit.xml | 1 + tests/Unit/ConsumableTest.php | 19 ------------------- 2 files changed, 1 insertion(+), 19 deletions(-) delete mode 100644 tests/Unit/ConsumableTest.php diff --git a/phpunit.xml b/phpunit.xml index bf3fd2dc3..9706518ab 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,6 +8,7 @@ ./tests/ + ./tests/Browser diff --git a/tests/Unit/ConsumableTest.php b/tests/Unit/ConsumableTest.php deleted file mode 100644 index cbe89b13b..000000000 --- a/tests/Unit/ConsumableTest.php +++ /dev/null @@ -1,19 +0,0 @@ - Date: Tue, 7 Feb 2023 16:17:05 -0800 Subject: [PATCH 02/27] Use factories for relationships in asset factory --- database/factories/AssetFactory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php index 24021921b..858febe82 100644 --- a/database/factories/AssetFactory.php +++ b/database/factories/AssetFactory.php @@ -38,7 +38,7 @@ class AssetFactory extends Factory { return [ 'name' => null, - 'rtd_location_id' => Location::all()->random()->id, + 'rtd_location_id' => Location::factory(), 'serial' => $this->faker->uuid, 'status_id' => 1, 'user_id' => 1, @@ -47,7 +47,7 @@ class AssetFactory extends Factory 'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()), 'purchase_cost' => $this->faker->randomFloat(2, '299.99', '2999.99'), 'order_number' => $this->faker->numberBetween(1000000, 50000000), - 'supplier_id' => Supplier::all()->random()->id, + 'supplier_id' => Supplier::factory(), 'requestable' => $this->faker->boolean(), 'assigned_to' => null, 'assigned_type' => null, From 6b8c0f9e8838e6ad4c5e834a90e6d26d824c92de Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 7 Feb 2023 16:17:16 -0800 Subject: [PATCH 03/27] Make BaseTest abstract --- tests/Unit/BaseTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/BaseTest.php b/tests/Unit/BaseTest.php index 83f118108..136978be2 100644 --- a/tests/Unit/BaseTest.php +++ b/tests/Unit/BaseTest.php @@ -10,7 +10,7 @@ use Tests\TestCase; use Auth; use Artisan; -class BaseTest extends TestCase +abstract class BaseTest extends TestCase { use DatabaseTransactions; From 505ca48da283eaab368bca067cca839ddef25cda Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 7 Feb 2023 16:17:36 -0800 Subject: [PATCH 04/27] Remove test method without assertions --- tests/Unit/CustomFieldTest.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/Unit/CustomFieldTest.php b/tests/Unit/CustomFieldTest.php index 7df281fe1..f991fda20 100644 --- a/tests/Unit/CustomFieldTest.php +++ b/tests/Unit/CustomFieldTest.php @@ -15,11 +15,6 @@ class CustomFieldTest extends BaseTest { protected $tester; - public function testConstructor() - { - $customfield = new CustomField(); - } - public function testFormat() { $customfield = CustomField::factory()->make(['format' => 'IP']); From 787f619a6b51859ed808a1edb2dd331a2d2a92bc Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 7 Feb 2023 16:28:40 -0800 Subject: [PATCH 05/27] Standardize test method syntax --- tests/Unit/AssetMaintenanceTest.php | 20 ++++------------ tests/Unit/AssetTest.php | 5 ---- tests/Unit/SnipeModelTest.php | 37 ++++++----------------------- 3 files changed, 11 insertions(+), 51 deletions(-) diff --git a/tests/Unit/AssetMaintenanceTest.php b/tests/Unit/AssetMaintenanceTest.php index ccae46ed7..ad1667988 100644 --- a/tests/Unit/AssetMaintenanceTest.php +++ b/tests/Unit/AssetMaintenanceTest.php @@ -12,10 +12,7 @@ class AssetMaintenanceTest extends BaseTest */ protected $tester; - /** - * @test - */ - public function it_zeros_out_warranty_if_blank() + public function testZerosOutWarrantyIfBlank() { $c = new AssetMaintenance; $c->is_warranty = ''; @@ -24,10 +21,7 @@ class AssetMaintenanceTest extends BaseTest $this->assertTrue($c->is_warranty == 4); } - /** - * @test - */ - public function it_sets_costs_appropriately() + public function testSetsCostsAppropriately() { $c = new AssetMaintenance(); $c->cost = '0.00'; @@ -38,10 +32,7 @@ class AssetMaintenanceTest extends BaseTest $this->assertTrue($c->cost === 9.5); } - /** - * @test - */ - public function it_nulls_out_notes_if_blank() + public function testNullsOutNotesIfBlank() { $c = new AssetMaintenance; $c->notes = ''; @@ -50,10 +41,7 @@ class AssetMaintenanceTest extends BaseTest $this->assertTrue($c->notes === 'This is a long note'); } - /** - * @test - */ - public function it_nulls_out_completion_date_if_blank_or_invalid() + public function testNullsOutCompletionDateIfBlankOrInvalid() { $c = new AssetMaintenance; $c->completion_date = ''; diff --git a/tests/Unit/AssetTest.php b/tests/Unit/AssetTest.php index 0cc27d80d..e3fa5b449 100644 --- a/tests/Unit/AssetTest.php +++ b/tests/Unit/AssetTest.php @@ -41,10 +41,6 @@ class AssetTest extends BaseTest // $this->assertEquals($expected, $next); // } - - /** - * @test - */ public function testWarrantyExpiresAttribute() { @@ -66,5 +62,4 @@ class AssetTest extends BaseTest $this->assertEquals(Carbon::createFromDate(2019, 1, 1)->format('Y-m-d'), $asset->warranty_expires->format('Y-m-d')); } - } diff --git a/tests/Unit/SnipeModelTest.php b/tests/Unit/SnipeModelTest.php index 8884ecf6d..f9dcfe0cb 100644 --- a/tests/Unit/SnipeModelTest.php +++ b/tests/Unit/SnipeModelTest.php @@ -11,12 +11,7 @@ class SnipeModelTest extends BaseTest */ protected $tester; - // tests - - /** - * @test - */ - public function it_sets_purchase_dates_appropriately() + public function testSetsPurchaseDatesAppropriately() { $c = new SnipeModel; $c->purchase_date = ''; @@ -25,10 +20,7 @@ class SnipeModelTest extends BaseTest $this->assertTrue($c->purchase_date === '2016-03-25 12:35:50'); } - /** - * @test - */ - public function it_sets_purchase_costs_appropriately() + public function testSetsPurchaseCostsAppropriately() { $c = new SnipeModel; $c->purchase_cost = '0.00'; @@ -39,10 +31,7 @@ class SnipeModelTest extends BaseTest $this->assertTrue($c->purchase_cost === 9.5); } - /** - * @test - */ - public function it_nulls_blank_location_ids_but_not_others() + public function testNullsBlankLocationIdsButNotOthers() { $c = new SnipeModel; $c->location_id = ''; @@ -51,10 +40,7 @@ class SnipeModelTest extends BaseTest $this->assertTrue($c->location_id == 5); } - /** - * @test - */ - public function it_nulls_blank_categories_but_not_others() + public function testNullsBlankCategoriesButNotOthers() { $c = new SnipeModel; $c->category_id = ''; @@ -63,10 +49,7 @@ class SnipeModelTest extends BaseTest $this->assertTrue($c->category_id == 1); } - /** - * @test - */ - public function it_nulls_blank_suppliers_but_not_others() + public function testNullsBlankSuppliersButNotOthers() { $c = new SnipeModel; $c->supplier_id = ''; @@ -75,10 +58,7 @@ class SnipeModelTest extends BaseTest $this->assertTrue($c->supplier_id == 4); } - /** - * @test - */ - public function it_nulls_blank_depreciations_but_not_others() + public function testNullsBlankDepreciationsButNotOthers() { $c = new SnipeModel; $c->depreciation_id = ''; @@ -87,10 +67,7 @@ class SnipeModelTest extends BaseTest $this->assertTrue($c->depreciation_id == 4); } - /** - * @test - */ - public function it_nulls_blank_manufacturers_but_not_others() + public function testNullsBlankManufacturersButNotOthers() { $c = new SnipeModel; $c->manufacturer_id = ''; From 4f9ebf6cde33451e918d1b818c70d227ff4a1b59 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 7 Feb 2023 16:40:27 -0800 Subject: [PATCH 06/27] Fix array key --- tests/Unit/AccessoryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/AccessoryTest.php b/tests/Unit/AccessoryTest.php index dafcce663..57b91b8f0 100644 --- a/tests/Unit/AccessoryTest.php +++ b/tests/Unit/AccessoryTest.php @@ -62,7 +62,7 @@ class AccessoryTest extends BaseTest $accessory = Accessory::factory()->appleBtKeyboard()->create( [ 'category_id' => Category::factory()->create(), - 'category_id' => Manufacturer::factory()->apple()->create() + 'manufacturer_id' => Manufacturer::factory()->apple()->create() ]); $this->assertInstanceOf(Manufacturer::class, $accessory->manufacturer); } From 228c59e6eda189043b9a0bb18a96eba6b0595990 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 13 Feb 2023 18:55:50 -0800 Subject: [PATCH 07/27] Bring phpunit.xml closer to default --- phpunit.xml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 9706518ab..2372e19c3 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,18 +6,22 @@ - - ./tests/ - ./tests/Browser + + ./tests/Unit + + + ./tests/Feature + + + - - + From 8b183490ba9d0e08d37ed38b5afa585cbaaf879f Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 13 Feb 2023 18:56:22 -0800 Subject: [PATCH 08/27] Use "testing" environment for tests --- phpunit.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 2372e19c3..f20556608 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -14,7 +14,7 @@ - + From 4197e613b2ee9392b0850129932ade4cb72ba8bb Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 28 Feb 2023 14:50:48 -0800 Subject: [PATCH 09/27] Fix License Factory --- database/factories/LicenseFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/factories/LicenseFactory.php b/database/factories/LicenseFactory.php index 2aa681c0d..399b46858 100644 --- a/database/factories/LicenseFactory.php +++ b/database/factories/LicenseFactory.php @@ -46,7 +46,7 @@ class LicenseFactory extends Factory 'serial' => $this->faker->uuid, 'notes' => 'Created by DB seeder', 'seats' => $this->faker->numberBetween(1, 10), - 'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()), + 'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'), 'order_number' => $this->faker->numberBetween(1000000, 50000000), 'expiration_date' => $this->faker->dateTimeBetween('now', '+3 years', date_default_timezone_get())->format('Y-m-d H:i:s'), 'reassignable' => $this->faker->boolean(), From 75fc624ec65da9690adb6eed6d1256e16fef1454 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 2 Mar 2023 13:12:25 -0800 Subject: [PATCH 10/27] Globally disable SecurityHeaders in tests --- tests/TestCase.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/TestCase.php b/tests/TestCase.php index 508234130..4a19344eb 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,6 +2,7 @@ namespace Tests; +use App\Http\Middleware\SecurityHeaders; use App\Models\Setting; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; @@ -9,10 +10,16 @@ abstract class TestCase extends BaseTestCase { use CreatesApplication; + private array $globallyDisabledMiddleware = [ + SecurityHeaders::class, + ]; + protected function setUp(): void { parent::setUp(); $this->beforeApplicationDestroyed(fn() => Setting::$_cache = null); + + $this->withoutMiddleware($this->globallyDisabledMiddleware); } } From 45d7e9b1342d2a91e4ac40b59db4e9ab19ba2586 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 2 Mar 2023 13:13:30 -0800 Subject: [PATCH 11/27] Switch to using LazilyRefreshDatabase in unit test suite --- tests/Unit/BaseTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Unit/BaseTest.php b/tests/Unit/BaseTest.php index 136978be2..ae27956d2 100644 --- a/tests/Unit/BaseTest.php +++ b/tests/Unit/BaseTest.php @@ -5,6 +5,7 @@ use App\Models\User; use App\Models\Setting; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseTransactions; +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Foundation\Testing\WithoutMiddleware; use Tests\TestCase; use Auth; @@ -12,7 +13,7 @@ use Artisan; abstract class BaseTest extends TestCase { - use DatabaseTransactions; + use LazilyRefreshDatabase; protected function _before() { From ad9eef63935840a58245e773849522053dbbf521 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 2 Mar 2023 13:41:52 -0800 Subject: [PATCH 12/27] Update deprecated faker calls in Asset and Supplier factories --- database/factories/AssetFactory.php | 2 +- database/factories/SupplierFactory.php | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php index b2c02f6da..6b77b8b07 100644 --- a/database/factories/AssetFactory.php +++ b/database/factories/AssetFactory.php @@ -39,7 +39,7 @@ class AssetFactory extends Factory return [ 'name' => null, 'rtd_location_id' => Location::factory(), - 'serial' => $this->faker->uuid, + 'serial' => $this->faker->uuid(), 'status_id' => 1, 'user_id' => 1, 'asset_tag' => $this->faker->unixTime('now'), diff --git a/database/factories/SupplierFactory.php b/database/factories/SupplierFactory.php index 344dfe7d5..47ec2ceee 100644 --- a/database/factories/SupplierFactory.php +++ b/database/factories/SupplierFactory.php @@ -39,18 +39,18 @@ class SupplierFactory extends Factory public function definition() { return [ - 'name' => $this->faker->company, - 'address' => $this->faker->streetAddress, - 'address2' => $this->faker->secondaryAddress, - 'city' => $this->faker->city, - 'state' => $this->faker->stateAbbr, - 'zip' => $this->faker->postCode, - 'country' => $this->faker->countryCode, - 'contact' => $this->faker->name, - 'phone' => $this->faker->phoneNumber, - 'fax' => $this->faker->phoneNumber, - 'email' => $this->faker->safeEmail, - 'url' => $this->faker->url, + 'name' => $this->faker->company(), + 'address' => $this->faker->streetAddress(), + 'address2' => $this->faker->secondaryAddress(), + 'city' => $this->faker->city(), + 'state' => $this->faker->stateAbbr(), + 'zip' => $this->faker->postCode(), + 'country' => $this->faker->countryCode(), + 'contact' => $this->faker->name(), + 'phone' => $this->faker->phoneNumber(), + 'fax' => $this->faker->phoneNumber(), + 'email' => $this->faker->safeEmail(), + 'url' => $this->faker->url(), 'notes' => $this->faker->text(191), // Supplier notes can be a max of 255 characters. ]; } From e8da6d8bacd88d58adc3a4c0bbd500e808d5a0bf Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 2 Mar 2023 13:47:58 -0800 Subject: [PATCH 13/27] Set purchase date in correct format --- tests/Unit/NotificationTest.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/Unit/NotificationTest.php b/tests/Unit/NotificationTest.php index 509aee684..b44284a5a 100644 --- a/tests/Unit/NotificationTest.php +++ b/tests/Unit/NotificationTest.php @@ -20,7 +20,6 @@ class NotificationTest extends BaseTest public function testAUserIsEmailedIfTheyCheckoutAnAssetWithEULA() { - $user = User::factory()->create(); $asset = Asset::factory() ->create( @@ -30,12 +29,11 @@ class NotificationTest extends BaseTest [ 'category_id' => Category::factory()->assetLaptopCategory()->id ] - )->id, + )->id, 'warranty_months' => 24, - 'purchase_date' => Carbon::createFromDate(2017, 1, 1)->hour(0)->minute(0)->second(0) + 'purchase_date' => Carbon::createFromDate(2017, 1, 1)->hour(0)->minute(0)->second(0)->format('Y-m-d') ]); - //dd($asset); Notification::fake(); $asset->checkOut($user, $asset->id); Notification::assertSentTo($user, CheckoutAssetNotification::class); From bc541442840e424ab345a65c7575c9234621fe43 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 6 Mar 2023 12:40:47 -0800 Subject: [PATCH 14/27] Fix test by passing proper user --- tests/Unit/NotificationTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Unit/NotificationTest.php b/tests/Unit/NotificationTest.php index b44284a5a..4b85fa4c4 100644 --- a/tests/Unit/NotificationTest.php +++ b/tests/Unit/NotificationTest.php @@ -20,6 +20,7 @@ class NotificationTest extends BaseTest public function testAUserIsEmailedIfTheyCheckoutAnAssetWithEULA() { + $admin = User::factory()->superuser()->create(); $user = User::factory()->create(); $asset = Asset::factory() ->create( @@ -35,7 +36,7 @@ class NotificationTest extends BaseTest ]); Notification::fake(); - $asset->checkOut($user, $asset->id); + $asset->checkOut($user, $admin->id); Notification::assertSentTo($user, CheckoutAssetNotification::class); } } From a24d734ee9459eb7df0c08158c48b384dd6282b0 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 6 Mar 2023 17:24:09 -0800 Subject: [PATCH 15/27] Alphabetize keys in phpunit.xml --- phpunit.xml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index f20556608..c3d611f4b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,16 @@ - + app/ @@ -17,11 +28,10 @@ - - - + + From 9aad981895142c3423e2e19f063336c1b3255128 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 6 Mar 2023 17:25:03 -0800 Subject: [PATCH 16/27] Update phpunit schema location and remove unneeded environment variable --- phpunit.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index c3d611f4b..4ee53b57b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -9,7 +9,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" + xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" > @@ -30,7 +30,6 @@ - From ba9250167062f42fd73b7412b75791ba6dfde314 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 6 Mar 2023 17:34:43 -0800 Subject: [PATCH 17/27] Add .env.testing.example file --- .env.testing.example | 19 +++++++++++++++++++ .gitignore | 1 + phpunit.xml | 1 + 3 files changed, 21 insertions(+) create mode 100644 .env.testing.example diff --git a/.env.testing.example b/.env.testing.example new file mode 100644 index 000000000..2a6a446bf --- /dev/null +++ b/.env.testing.example @@ -0,0 +1,19 @@ +# -------------------------------------------- +# REQUIRED: BASIC APP SETTINGS +# -------------------------------------------- +APP_ENV=testing +APP_DEBUG=true +APP_KEY=base64:glJpcM7BYwWiBggp3SQ/+NlRkqsBQMaGEOjemXqJzOU= +APP_URL=http://localhost:8000 +APP_TIMEZONE='UTC' +APP_LOCALE=en + +# -------------------------------------------- +# REQUIRED: DATABASE SETTINGS +# -------------------------------------------- +# DB_CONNECTION is set to "mysql" in phpunit.xml +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=null +DB_USERNAME=null +DB_PASSWORD=null diff --git a/.gitignore b/.gitignore index e49e69c9a..04b0d7e6b 100755 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .env .env.dusk.* !.env.dusk.example +!.env.testing phpstan.neon .idea /bin/ diff --git a/phpunit.xml b/phpunit.xml index 4ee53b57b..b0ce0a6f2 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -28,6 +28,7 @@ + From 245f0aff72dc34cb69b3a7250cfb49ad73263cfa Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 6 Mar 2023 17:35:49 -0800 Subject: [PATCH 18/27] Ignore the correct env file --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 04b0d7e6b..f0e9bfcec 100755 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ .env .env.dusk.* !.env.dusk.example -!.env.testing +.env.testing phpstan.neon .idea /bin/ From ddcb8d8dd97675b2958960c12ec39b5b09818923 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 6 Mar 2023 17:37:08 -0800 Subject: [PATCH 19/27] Remove commited .env.testing file --- .env.testing | 75 ---------------------------------------------------- 1 file changed, 75 deletions(-) delete mode 100644 .env.testing diff --git a/.env.testing b/.env.testing deleted file mode 100644 index a60fc4e09..000000000 --- a/.env.testing +++ /dev/null @@ -1,75 +0,0 @@ -# -------------------------------------------- -# REQUIRED: BASIC APP SETTINGS -# -------------------------------------------- -APP_ENV=testing -APP_DEBUG=true -APP_KEY=base64:glJpcM7BYwWiBggp3SQ/+NlRkqsBQMaGEOjemXqJzOU= -APP_URL=http://localhost:8000 -APP_TIMEZONE='US/Pacific' -APP_LOCALE=en -FILESYSTEM_DISK=local - -# -------------------------------------------- -# REQUIRED: DATABASE SETTINGS -# -------------------------------------------- -DB_CONNECTION=sqlite_testing -DB_HOST=localhost -DB_PORT=3306 -DB_DATABASE=testing.sqlite -DB_USERNAME=null -DB_PASSWORD=null - -# -------------------------------------------- -# REQUIRED: OUTGOING MAIL SERVER SETTINGS -# -------------------------------------------- -MAIL_DRIVER=log -MAIL_HOST=email-smtp.us-west-2.amazonaws.com -MAIL_PORT=587 -MAIL_USERNAME=YOURUSERNAME -MAIL_PASSWORD=YOURPASSWORD -MAIL_ENCRYPTION=null -MAIL_FROM_ADDR=you@example.com -MAIL_FROM_NAME=Snipe-IT - -# -------------------------------------------- -# REQUIRED: IMAGE LIBRARY -# This should be gd or imagick -# -------------------------------------------- -IMAGE_LIB=gd - - -# -------------------------------------------- -# OPTIONAL: AWS SETTINGS -# -------------------------------------------- -AWS_SECRET_ACCESS_KEY=null -AWS_ACCESS_KEY_ID=null -AWS_DEFAULT_REGION=null -AWS_BUCKET=null -AWS_BUCKET_ROOT=null -AWS_URL=null - - -# -------------------------------------------- -# OPTIONAL: CACHE SETTINGS -# -------------------------------------------- -CACHE_DRIVER=file -SESSION_DRIVER=file -QUEUE_DRIVER=sync - - -# -------------------------------------------- -# OPTIONAL: SESSION SETTINGS -# -------------------------------------------- -SESSION_LIFETIME=12000 -EXPIRE_ON_CLOSE=false -ENCRYPT=false -COOKIE_NAME=snipeittest_session -COOKIE_DOMAIN=null -SECURE_COOKIES=false - - -# -------------------------------------------- -# OPTIONAL: APP LOG FORMAT -# -------------------------------------------- -LOG_CHANNEL=single -LOG_LEVEL=debug From a3c8c3757a84edf1899c23e403715024ad0fb28d Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 6 Mar 2023 17:50:44 -0800 Subject: [PATCH 20/27] Remove unused method --- tests/Unit/BaseTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/Unit/BaseTest.php b/tests/Unit/BaseTest.php index ae27956d2..2fe6fa76e 100644 --- a/tests/Unit/BaseTest.php +++ b/tests/Unit/BaseTest.php @@ -15,12 +15,6 @@ abstract class BaseTest extends TestCase { use LazilyRefreshDatabase; - protected function _before() - { - Artisan::call('migrate'); - Setting::factory()->create(); - } - protected function signIn($user = null) { if (! $user) { From 8fad377114ff7eaa7b490ec1356f3a62eeee7415 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 7 Mar 2023 10:28:33 -0800 Subject: [PATCH 21/27] Remove helper methods by inlining where needed --- tests/Unit/AccessoryTest.php | 2 - tests/Unit/BaseTest.php | 85 --------------------------------- tests/Unit/DepreciationTest.php | 1 - tests/Unit/LocationTest.php | 4 +- 4 files changed, 1 insertion(+), 91 deletions(-) diff --git a/tests/Unit/AccessoryTest.php b/tests/Unit/AccessoryTest.php index 57b91b8f0..a9ed782ae 100644 --- a/tests/Unit/AccessoryTest.php +++ b/tests/Unit/AccessoryTest.php @@ -57,8 +57,6 @@ class AccessoryTest extends BaseTest public function testAnAccessoryHasAManufacturer() { - $this->createValidManufacturer('apple'); - $this->createValidCategory('accessory-keyboard-category'); $accessory = Accessory::factory()->appleBtKeyboard()->create( [ 'category_id' => Category::factory()->create(), diff --git a/tests/Unit/BaseTest.php b/tests/Unit/BaseTest.php index 2fe6fa76e..977e8b02e 100644 --- a/tests/Unit/BaseTest.php +++ b/tests/Unit/BaseTest.php @@ -14,89 +14,4 @@ use Artisan; abstract class BaseTest extends TestCase { use LazilyRefreshDatabase; - - protected function signIn($user = null) - { - if (! $user) { - $user = User::factory()->superuser()->create([ - 'location_id' => $this->createValidLocation()->id, - ]); - } - Auth::login($user); - return $user; - } - - protected function createValidAssetModel() - { - return \App\Models\AssetModel::factory()->create([ - 'category_id' => $this->createValidCategory(), - 'manufacturer_id' => $this->createValidManufacturer(), - 'depreciation_id' => $this->createValidDepreciation(), - ]); - } - - protected function createValidCategory() - { - return \App\Models\Category::factory()->make(); - } - - protected function createValidCompany() - { - return \App\Models\Company::factory()->create(); - } - - protected function createValidDepartment($state = 'engineering', $overrides = []) - { - return \App\Models\Department::factory()->create(array_merge([ - 'location_id' => $this->createValidLocation()->id, - ], $overrides)); - } - - protected function createValidDepreciation() - { - return \App\Models\Depreciation::factory()->create(); - } - - protected function createValidLocation($overrides = []) - { - return \App\Models\Location::factory()->create($overrides); - } - - protected function createValidManufacturer() - { - return \App\Models\Manufacturer::factory()->create(); - } - - protected function createValidSupplier($overrides = []) - { - return \App\Models\Supplier::factory()->create($overrides); - } - - protected function createValidStatuslabel($state = 'rtd', $overrides = []) - { - return \App\Models\Statuslabel::factory()->state()->create($overrides); - } - - protected function createValidUser($overrides = []) - { - return \App\Models\User::factory()->create( - array_merge([ - 'location_id'=>$this->createValidLocation()->id, - ], $overrides) - ); - } - - protected function createValidAsset($overrides = []) - { - $locId = $this->createValidLocation()->id; - $this->createValidAssetModel(); - - return \App\Models\Asset::factory()->laptopMbp()->create( - array_merge([ - 'rtd_location_id' => $locId, - 'location_id' => $locId, - 'supplier_id' => $this->createValidSupplier()->id, - ], $overrides) - ); - } } diff --git a/tests/Unit/DepreciationTest.php b/tests/Unit/DepreciationTest.php index abe11d7f8..d8885dcf9 100644 --- a/tests/Unit/DepreciationTest.php +++ b/tests/Unit/DepreciationTest.php @@ -18,7 +18,6 @@ class DepreciationTest extends BaseTest public function testADepreciationHasModels() { - $this->createValidAssetModel(); $depreciation = Depreciation::factory()->create(); AssetModel::factory() diff --git a/tests/Unit/LocationTest.php b/tests/Unit/LocationTest.php index eda9c6a89..962d441b2 100644 --- a/tests/Unit/LocationTest.php +++ b/tests/Unit/LocationTest.php @@ -14,12 +14,10 @@ class LocationTest extends BaseTest public function testPassesIfNotSelfParent() { - $this->createValidLocation(['id' => 10]); - $a = Location::factory()->make([ 'name' => 'Test Location', 'id' => 1, - 'parent_id' => 10, + 'parent_id' => Location::factory()->create(['id' => 10])->id, ]); $this->assertTrue($a->isValid()); From 8c13a4c5c9da01575668691f43f494e8f732db9b Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 7 Mar 2023 16:43:18 -0800 Subject: [PATCH 22/27] Use LazilyRefreshDatabase instead of RefreshDatabase --- tests/Feature/Api/Users/UsersForSelectListTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Feature/Api/Users/UsersForSelectListTest.php b/tests/Feature/Api/Users/UsersForSelectListTest.php index 558f36264..0aca637eb 100644 --- a/tests/Feature/Api/Users/UsersForSelectListTest.php +++ b/tests/Feature/Api/Users/UsersForSelectListTest.php @@ -5,14 +5,14 @@ namespace Tests\Feature\Api\Users; use App\Models\Company; use App\Models\Setting; use App\Models\User; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Testing\Fluent\AssertableJson; use Laravel\Passport\Passport; use Tests\TestCase; class UsersForSelectListTest extends TestCase { - use RefreshDatabase; + use LazilyRefreshDatabase; public function testUsersAreReturned() { From 43ff7261b2c5fb821785bfb641a9afd3c869fb96 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 7 Mar 2023 16:57:55 -0800 Subject: [PATCH 23/27] Remove redundant base test case --- .../Api/Users/UsersForSelectListTest.php | 3 --- tests/TestCase.php | 2 ++ tests/Unit/AccessoryTest.php | 4 ++-- tests/Unit/AssetMaintenanceTest.php | 4 ++-- tests/Unit/AssetModelTest.php | 4 ++-- tests/Unit/AssetTest.php | 4 ++-- tests/Unit/BaseTest.php | 17 ----------------- tests/Unit/CategoryTest.php | 4 ++-- tests/Unit/CompanyTest.php | 4 ++-- tests/Unit/ComponentTest.php | 4 ++-- tests/Unit/CustomFieldTest.php | 4 ++-- tests/Unit/DepreciationTest.php | 4 ++-- tests/Unit/ImporterTest.php | 4 ++-- tests/Unit/LocationTest.php | 4 ++-- tests/Unit/NotificationTest.php | 4 ++-- tests/Unit/PermissionsTest.php | 4 ++-- tests/Unit/SnipeModelTest.php | 4 ++-- tests/Unit/StatuslabelTest.php | 4 ++-- tests/Unit/UserTest.php | 4 ++-- 19 files changed, 34 insertions(+), 52 deletions(-) delete mode 100644 tests/Unit/BaseTest.php diff --git a/tests/Feature/Api/Users/UsersForSelectListTest.php b/tests/Feature/Api/Users/UsersForSelectListTest.php index 0aca637eb..b4ede4b11 100644 --- a/tests/Feature/Api/Users/UsersForSelectListTest.php +++ b/tests/Feature/Api/Users/UsersForSelectListTest.php @@ -5,15 +5,12 @@ namespace Tests\Feature\Api\Users; use App\Models\Company; use App\Models\Setting; use App\Models\User; -use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Testing\Fluent\AssertableJson; use Laravel\Passport\Passport; use Tests\TestCase; class UsersForSelectListTest extends TestCase { - use LazilyRefreshDatabase; - public function testUsersAreReturned() { Setting::factory()->create(); diff --git a/tests/TestCase.php b/tests/TestCase.php index 4a19344eb..efa533b8c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,11 +4,13 @@ namespace Tests; use App\Http\Middleware\SecurityHeaders; use App\Models\Setting; +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase { use CreatesApplication; + use LazilyRefreshDatabase; private array $globallyDisabledMiddleware = [ SecurityHeaders::class, diff --git a/tests/Unit/AccessoryTest.php b/tests/Unit/AccessoryTest.php index a9ed782ae..25bd849b6 100644 --- a/tests/Unit/AccessoryTest.php +++ b/tests/Unit/AccessoryTest.php @@ -9,9 +9,9 @@ use App\Models\Company; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\WithoutMiddleware; -use Tests\Unit\BaseTest; +use Tests\TestCase; -class AccessoryTest extends BaseTest +class AccessoryTest extends TestCase { /** * @var \UnitTester diff --git a/tests/Unit/AssetMaintenanceTest.php b/tests/Unit/AssetMaintenanceTest.php index ad1667988..d403b7ff9 100644 --- a/tests/Unit/AssetMaintenanceTest.php +++ b/tests/Unit/AssetMaintenanceTest.php @@ -2,10 +2,10 @@ namespace Tests\Unit; use App\Models\AssetMaintenance; -use Tests\Unit\BaseTest; use Carbon\Carbon; +use Tests\TestCase; -class AssetMaintenanceTest extends BaseTest +class AssetMaintenanceTest extends TestCase { /** * @var \UnitTester diff --git a/tests/Unit/AssetModelTest.php b/tests/Unit/AssetModelTest.php index d7c18dc9a..d1582c906 100644 --- a/tests/Unit/AssetModelTest.php +++ b/tests/Unit/AssetModelTest.php @@ -7,9 +7,9 @@ use App\Models\AssetModel; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\WithoutMiddleware; -use Tests\Unit\BaseTest; +use Tests\TestCase; -class AssetModelTest extends BaseTest +class AssetModelTest extends TestCase { /** * @var \UnitTester diff --git a/tests/Unit/AssetTest.php b/tests/Unit/AssetTest.php index e3fa5b449..d49137be7 100644 --- a/tests/Unit/AssetTest.php +++ b/tests/Unit/AssetTest.php @@ -11,12 +11,12 @@ use App\Models\Category; use Carbon\Carbon; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\WithoutMiddleware; -use Tests\Unit\BaseTest; use App\Models\Component; use App\Models\ActionLog; +use Tests\TestCase; -class AssetTest extends BaseTest +class AssetTest extends TestCase { /** * @var \UnitTester diff --git a/tests/Unit/BaseTest.php b/tests/Unit/BaseTest.php deleted file mode 100644 index 977e8b02e..000000000 --- a/tests/Unit/BaseTest.php +++ /dev/null @@ -1,17 +0,0 @@ - Date: Tue, 7 Mar 2023 17:04:46 -0800 Subject: [PATCH 24/27] Remove old $tester variable and usused imports --- tests/Unit/AccessoryTest.php | 10 ---------- tests/Unit/AssetMaintenanceTest.php | 5 ----- tests/Unit/AssetModelTest.php | 10 ---------- tests/Unit/AssetTest.php | 14 -------------- tests/Unit/CategoryTest.php | 9 --------- tests/Unit/CompanyTest.php | 12 ------------ tests/Unit/ComponentTest.php | 10 ---------- tests/Unit/CustomFieldTest.php | 5 ----- tests/Unit/DepreciationTest.php | 7 ------- tests/Unit/ImporterTest.php | 8 -------- tests/Unit/LocationTest.php | 6 ------ tests/Unit/NotificationTest.php | 6 ------ tests/Unit/PermissionsTest.php | 3 --- tests/Unit/SnipeModelTest.php | 5 ----- tests/Unit/StatuslabelTest.php | 8 -------- tests/Unit/UserTest.php | 8 -------- 16 files changed, 126 deletions(-) diff --git a/tests/Unit/AccessoryTest.php b/tests/Unit/AccessoryTest.php index 25bd849b6..ec931fad6 100644 --- a/tests/Unit/AccessoryTest.php +++ b/tests/Unit/AccessoryTest.php @@ -6,20 +6,10 @@ use App\Models\Manufacturer; use App\Models\Location; use App\Models\Category; use App\Models\Company; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; use Tests\TestCase; class AccessoryTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - - - public function testAnAccessoryBelongsToACompany() { $accessory = Accessory::factory() diff --git a/tests/Unit/AssetMaintenanceTest.php b/tests/Unit/AssetMaintenanceTest.php index d403b7ff9..31b68c0cf 100644 --- a/tests/Unit/AssetMaintenanceTest.php +++ b/tests/Unit/AssetMaintenanceTest.php @@ -7,11 +7,6 @@ use Tests\TestCase; class AssetMaintenanceTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - public function testZerosOutWarrantyIfBlank() { $c = new AssetMaintenance; diff --git a/tests/Unit/AssetModelTest.php b/tests/Unit/AssetModelTest.php index d1582c906..7050ea307 100644 --- a/tests/Unit/AssetModelTest.php +++ b/tests/Unit/AssetModelTest.php @@ -4,18 +4,10 @@ namespace Tests\Unit; use App\Models\Asset; use App\Models\Category; use App\Models\AssetModel; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; use Tests\TestCase; class AssetModelTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - public function testAnAssetModelZerosOutBlankEols() { $am = new AssetModel; @@ -42,6 +34,4 @@ class AssetModelTest extends TestCase ); $this->assertEquals(1, $model->assets()->count()); } - - } diff --git a/tests/Unit/AssetTest.php b/tests/Unit/AssetTest.php index d49137be7..f0a9b11f1 100644 --- a/tests/Unit/AssetTest.php +++ b/tests/Unit/AssetTest.php @@ -1,28 +1,14 @@ create(); diff --git a/tests/Unit/ComponentTest.php b/tests/Unit/ComponentTest.php index 48a4a998e..df8f64771 100644 --- a/tests/Unit/ComponentTest.php +++ b/tests/Unit/ComponentTest.php @@ -5,20 +5,10 @@ use App\Models\Category; use App\Models\Company; use App\Models\Component; use App\Models\Location; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; use Tests\TestCase; class ComponentTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - - - public function testAComponentBelongsToACompany() { $component = Component::factory() diff --git a/tests/Unit/CustomFieldTest.php b/tests/Unit/CustomFieldTest.php index 16313efb3..dbf96c55f 100644 --- a/tests/Unit/CustomFieldTest.php +++ b/tests/Unit/CustomFieldTest.php @@ -2,9 +2,6 @@ namespace Tests\Unit; use App\Models\CustomField; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; use Tests\TestCase; /* @@ -13,8 +10,6 @@ use Tests\TestCase; */ class CustomFieldTest extends TestCase { - protected $tester; - public function testFormat() { $customfield = CustomField::factory()->make(['format' => 'IP']); diff --git a/tests/Unit/DepreciationTest.php b/tests/Unit/DepreciationTest.php index 84b10d7fb..900ae7367 100644 --- a/tests/Unit/DepreciationTest.php +++ b/tests/Unit/DepreciationTest.php @@ -9,13 +9,6 @@ use Tests\TestCase; class DepreciationTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - - - public function testADepreciationHasModels() { $depreciation = Depreciation::factory()->create(); diff --git a/tests/Unit/ImporterTest.php b/tests/Unit/ImporterTest.php index 94d537cce..b3d5da8b3 100644 --- a/tests/Unit/ImporterTest.php +++ b/tests/Unit/ImporterTest.php @@ -13,19 +13,11 @@ use App\Models\Category; use App\Models\CustomField; use App\Models\Location; use App\Models\User; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Support\Facades\Notification; use Tests\TestCase; class ImporterTest extends TestCase { - /** - * @var \UnitTester - */ -// protected $tester; - // public function testDefaultImportAssetWithCustomFields() // { // $this->signIn(); diff --git a/tests/Unit/LocationTest.php b/tests/Unit/LocationTest.php index a72920190..3fded9e56 100644 --- a/tests/Unit/LocationTest.php +++ b/tests/Unit/LocationTest.php @@ -4,14 +4,8 @@ namespace Tests\Unit; use App\Models\Location; use Tests\TestCase; - class LocationTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - public function testPassesIfNotSelfParent() { $a = Location::factory()->make([ diff --git a/tests/Unit/NotificationTest.php b/tests/Unit/NotificationTest.php index 4cc093025..33687ef63 100644 --- a/tests/Unit/NotificationTest.php +++ b/tests/Unit/NotificationTest.php @@ -10,14 +10,8 @@ use App\Notifications\CheckoutAssetNotification; use Illuminate\Support\Facades\Notification; use Tests\TestCase; - class NotificationTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - public function testAUserIsEmailedIfTheyCheckoutAnAssetWithEULA() { $admin = User::factory()->superuser()->create(); diff --git a/tests/Unit/PermissionsTest.php b/tests/Unit/PermissionsTest.php index dcdbd1bb4..e788585dd 100644 --- a/tests/Unit/PermissionsTest.php +++ b/tests/Unit/PermissionsTest.php @@ -7,9 +7,6 @@ use App\Models\Component; use App\Models\Consumable; use App\Models\License; use App\Models\User; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; use Tests\TestCase; class PermissionsTest extends TestCase diff --git a/tests/Unit/SnipeModelTest.php b/tests/Unit/SnipeModelTest.php index 145550221..2bc81da61 100644 --- a/tests/Unit/SnipeModelTest.php +++ b/tests/Unit/SnipeModelTest.php @@ -6,11 +6,6 @@ use Tests\TestCase; class SnipeModelTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - public function testSetsPurchaseDatesAppropriately() { $c = new SnipeModel; diff --git a/tests/Unit/StatuslabelTest.php b/tests/Unit/StatuslabelTest.php index 2dfd0143c..fe5f3cacc 100644 --- a/tests/Unit/StatuslabelTest.php +++ b/tests/Unit/StatuslabelTest.php @@ -2,18 +2,10 @@ namespace Tests\Unit; use App\Models\Statuslabel; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; use Tests\TestCase; class StatuslabelTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - public function testRTDStatuslabelAdd() { $statuslabel = Statuslabel::factory()->rtd()->create(); diff --git a/tests/Unit/UserTest.php b/tests/Unit/UserTest.php index c5eebd6b0..e089fc402 100644 --- a/tests/Unit/UserTest.php +++ b/tests/Unit/UserTest.php @@ -2,18 +2,10 @@ namespace Tests\Unit; use App\Models\User; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; use Tests\TestCase; class UserTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - public function testFirstNameSplit() { $fullname = "Natalia Allanovna Romanova-O'Shostakova"; From 697824007a6fe13867084c5b117b8ad29a43e6fd Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 8 Mar 2023 11:58:29 -0800 Subject: [PATCH 25/27] Move DB_CONNECTION back to .env.testing.example --- .env.testing.example | 2 +- phpunit.xml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.env.testing.example b/.env.testing.example index 2a6a446bf..3391d6272 100644 --- a/.env.testing.example +++ b/.env.testing.example @@ -11,7 +11,7 @@ APP_LOCALE=en # -------------------------------------------- # REQUIRED: DATABASE SETTINGS # -------------------------------------------- -# DB_CONNECTION is set to "mysql" in phpunit.xml +DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=null diff --git a/phpunit.xml b/phpunit.xml index b0ce0a6f2..4ee53b57b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -28,7 +28,6 @@ - From 5fb18af2456fe4841e05ea2a4b470fd886ab5da3 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 8 Mar 2023 11:58:36 -0800 Subject: [PATCH 26/27] Update testing documentation --- TESTING.md | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/TESTING.md b/TESTING.md index 8a430d498..74d2ebd99 100644 --- a/TESTING.md +++ b/TESTING.md @@ -1,25 +1,17 @@ -# Using the Test Suite +# Running the Test Suite -This document is targeted at developers looking to make modifications to -this application's code base and want to run the existing test suite. +This document is targeted at developers looking to make modifications to this application's code base and want to run the existing test suite. +Before starting, follow the [instructions](README.md#installation) for installing the application locally and ensure you can load it in a browser properly. -## Setup +## Unit and Feature Tests -Follow the instructions for installing the application locally, -making sure to have also run the [database migrations](link to db migrations). +Before attempting to run the test suite copy the example environment file for tests and update the values to match your environment: +`cp .env.testing.example .env.testing` +> Since the data in the database is flushed after each test it is recommended you create a separate mysql database for specifically for tests -## Unit Tests - -The application will use values in the `.env.testing` file located -in the root directory to override the -default settings and/or other values that exist in your `.env` files. - -Make sure to modify the section in `.env.testing` that has the -database settings. In the example below, it is connecting to the -[MariaDB](link-to-maria-db) server that is used if you install the -application using [Docker](https://docker.com). +Here is an example of what your `.env.testing` file might look like: ```dotenv # -------------------------------------------- @@ -27,19 +19,18 @@ application using [Docker](https://docker.com). # -------------------------------------------- DB_CONNECTION=mysql DB_HOST=127.0.0.1 -DB_DATABASE=snipeit +DB_DATABASE=snipeit_testing DB_USERNAME=root DB_PASSWORD=changeme1234 ``` -To run the entire unit test suite, use the following command from your terminal: +Now you are ready to run the entire test suite from your terminal: -`php artisan test --env=testing` +`php artisan test` -To run individual test files, you can pass the path to the test that -you want to run. +To run individual test files, you can pass the path to the test that you want to run: -`php artisan test --env=testing tests/Unit/AccessoryTest.php` +`php artisan test tests/Unit/AccessoryTest.php` ## Browser Tests @@ -52,11 +43,9 @@ Before attempting to run Dusk tests copy the example environment file for Dusk a **Important**: Dusk tests cannot be run using an in-memory SQLite database. Additionally, the Dusk test suite uses the `DatabaseMigrations` trait which will leave the database in a fresh state after running. Therefore, it is recommended that you create a test database and point `DB_DATABASE` in `.env.dusk.local` to it. -### Test Setup +### Running Browser Tests -Your application needs to be configured and up and running in order for the browser -tests to actually run. When running the tests locally, you can start the application -using the following command: +Your application needs to be configured and up and running in order for the browser tests to actually run. When running the tests locally, you can start the application using the following command: `php artisan serve` From 44b48a954a1a4bfe07db538f28f1bcae118f98f7 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 8 Mar 2023 12:15:37 -0800 Subject: [PATCH 27/27] Remove unneed section of testing docs --- TESTING.md | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/TESTING.md b/TESTING.md index 74d2ebd99..3f0e58810 100644 --- a/TESTING.md +++ b/TESTING.md @@ -11,19 +11,6 @@ Before attempting to run the test suite copy the example environment file for te `cp .env.testing.example .env.testing` > Since the data in the database is flushed after each test it is recommended you create a separate mysql database for specifically for tests -Here is an example of what your `.env.testing` file might look like: - -```dotenv -# -------------------------------------------- -# REQUIRED: DATABASE SETTINGS -# -------------------------------------------- -DB_CONNECTION=mysql -DB_HOST=127.0.0.1 -DB_DATABASE=snipeit_testing -DB_USERNAME=root -DB_PASSWORD=changeme1234 -``` - Now you are ready to run the entire test suite from your terminal: `php artisan test`