Skip to content

A free open source IT asset/license management system

One more change for --parallel

snipe535898dc394b
diff --git a/tests/Feature/AssetModels/Api/AssetModelFilesPolicyBypassTest.php b/tests/Feature/AssetModels/Api/AssetModelFilesPolicyBypassTest.php
index 9abba3070e..8c2622c614 100644
--- a/tests/Feature/AssetModels/Api/AssetModelFilesPolicyBypassTest.php
+++ b/tests/Feature/AssetModels/Api/AssetModelFilesPolicyBypassTest.php
@@ -5,6 +5,7 @@ namespace Tests\Feature\AssetModels\Api;
use App\Models\AssetModel;
use App\Models\User;
use Illuminate\Http\UploadedFile;
+use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
/**
@@ -22,6 +23,12 @@ use Tests\TestCase;
*/
class AssetModelFilesPolicyBypassTest extends TestCase
{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Storage::fake();
+ }
+
public function test_asset_viewer_can_list_model_files()
{
// Seed one file on the model as a superuser so there is something to see.
diff --git a/tests/Feature/Assets/Api/AssetFilesTest.php b/tests/Feature/Assets/Api/AssetFilesTest.php
index c731055644..825b04364f 100644
--- a/tests/Feature/Assets/Api/AssetFilesTest.php
+++ b/tests/Feature/Assets/Api/AssetFilesTest.php
@@ -5,10 +5,17 @@ namespace Tests\Feature\Assets\Api;
use App\Models\Asset;
use App\Models\User;
use Illuminate\Http\UploadedFile;
+use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class AssetFilesTest extends TestCase
{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Storage::fake();
+ }
+
public function test_asset_api_accepts_file_upload()
{
// Upload a file to an asset
diff --git a/tests/Feature/CheckoutAcceptances/Ui/AccessoryAcceptanceTest.php b/tests/Feature/CheckoutAcceptances/Ui/AccessoryAcceptanceTest.php
index 4a31e47a84..997c7c6ff7 100644
--- a/tests/Feature/CheckoutAcceptances/Ui/AccessoryAcceptanceTest.php
+++ b/tests/Feature/CheckoutAcceptances/Ui/AccessoryAcceptanceTest.php
@@ -10,10 +10,17 @@ use App\Models\User;
use App\Notifications\AcceptanceItemAcceptedNotification;
use App\Notifications\AcceptanceItemDeclinedNotification;
use Illuminate\Support\Facades\Notification;
+use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class AccessoryAcceptanceTest extends TestCase
{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Storage::fake();
+ }
+
public function test_can_accept_accessory_checkout()
{
$assignee = User::factory()->create();
diff --git a/tests/Feature/CheckoutAcceptances/Ui/AssetAcceptanceTest.php b/tests/Feature/CheckoutAcceptances/Ui/AssetAcceptanceTest.php
index c5c85100b7..18a2d8cd06 100644
--- a/tests/Feature/CheckoutAcceptances/Ui/AssetAcceptanceTest.php
+++ b/tests/Feature/CheckoutAcceptances/Ui/AssetAcceptanceTest.php
@@ -12,10 +12,17 @@ use App\Models\User;
use App\Notifications\AcceptanceItemAcceptedNotification;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Notification;
+use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class AssetAcceptanceTest extends TestCase
{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Storage::fake();
+ }
+
public function test_asset_checkout_accept_page_renders()
{
$checkoutAcceptance = CheckoutAcceptance::factory()->pending()->create();
@@ -135,7 +142,7 @@ class AssetAcceptanceTest extends TestCase
public function test_user_can_decline_asset()
{
Event::fake([CheckoutAccepted::class]);
- $this->settings->disableAlertEmail(); //otherwise it tries to send an email without having enough information
+ $this->settings->disableAlertEmail(); // otherwise it tries to send an email without having enough information
$checkoutAcceptance = CheckoutAcceptance::factory()->pending()->create();
diff --git a/tests/Feature/CheckoutAcceptances/Ui/ComponentAcceptanceTest.php b/tests/Feature/CheckoutAcceptances/Ui/ComponentAcceptanceTest.php
index 4c13e703af..ea9481f129 100644
--- a/tests/Feature/CheckoutAcceptances/Ui/ComponentAcceptanceTest.php
+++ b/tests/Feature/CheckoutAcceptances/Ui/ComponentAcceptanceTest.php
@@ -5,10 +5,17 @@ namespace Tests\Feature\CheckoutAcceptances\Ui;
use App\Models\CheckoutAcceptance;
use App\Models\Component;
use App\Models\User;
+use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class ComponentAcceptanceTest extends TestCase
{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Storage::fake();
+ }
+
public function test_component_checkout_accept_page_renders()
{
$checkoutAcceptance = CheckoutAcceptance::factory()
diff --git a/tests/Feature/CheckoutAcceptances/Ui/ConsumableAcceptanceTest.php b/tests/Feature/CheckoutAcceptances/Ui/ConsumableAcceptanceTest.php
index 9c7c0724b5..4a60a10e67 100644
--- a/tests/Feature/CheckoutAcceptances/Ui/ConsumableAcceptanceTest.php
+++ b/tests/Feature/CheckoutAcceptances/Ui/ConsumableAcceptanceTest.php
@@ -5,10 +5,17 @@ namespace Tests\Feature\CheckoutAcceptances\Ui;
use App\Models\CheckoutAcceptance;
use App\Models\Consumable;
use App\Models\User;
+use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class ConsumableAcceptanceTest extends TestCase
{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Storage::fake();
+ }
+
public function test_can_accept_consumable_checkout()
{
$assignee = User::factory()->create();
diff --git a/tests/Feature/Consumables/Api/ConsumableFileTest.php b/tests/Feature/Consumables/Api/ConsumableFileTest.php
index 78948e7541..78cbf15a49 100644
--- a/tests/Feature/Consumables/Api/ConsumableFileTest.php
+++ b/tests/Feature/Consumables/Api/ConsumableFileTest.php
@@ -5,10 +5,17 @@ namespace Tests\Feature\Consumables\Api;
use App\Models\Consumable;
use App\Models\User;
use Illuminate\Http\UploadedFile;
+use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class ConsumableFileTest extends TestCase
{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Storage::fake();
+ }
+
public function test_consumable_api_accepts_file_upload()
{
// Upload a file to a model
diff --git a/tests/Feature/FileUploads/UploadDeleteStorageFailureTest.php b/tests/Feature/FileUploads/UploadDeleteStorageFailureTest.php
index 259f598b4d..6d3b7dbfea 100644
--- a/tests/Feature/FileUploads/UploadDeleteStorageFailureTest.php
+++ b/tests/Feature/FileUploads/UploadDeleteStorageFailureTest.php
@@ -24,6 +24,12 @@ use Tests\TestCase;
*/
class UploadDeleteStorageFailureTest extends TestCase
{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Storage::fake();
+ }
+
private function seedAssetWithUpload(User $actor): array
{
$asset = Asset::factory()->create();
diff --git a/tests/Feature/Importing/AssetImportCheckoutAcceptanceTest.php b/tests/Feature/Importing/AssetImportCheckoutAcceptanceTest.php
index 823ad06990..22c41a3764 100644
--- a/tests/Feature/Importing/AssetImportCheckoutAcceptanceTest.php
+++ b/tests/Feature/Importing/AssetImportCheckoutAcceptanceTest.php
@@ -12,6 +12,7 @@ use App\Models\Location;
use App\Models\Statuslabel;
use App\Models\User;
use PHPUnit\Framework\Attributes\Test;
+use Tests\Support\Importing\CleansUpImportFiles;
use Tests\TestCase;
/**
@@ -30,6 +31,8 @@ use Tests\TestCase;
*/
class AssetImportCheckoutAcceptanceTest extends TestCase
{
+ use CleansUpImportFiles;
+
#[Test]
public function importing_a_user_checkout_creates_an_acceptance_record_when_category_requires_it(): void
{
diff --git a/tests/Feature/Importing/AssetImportCheckoutTargetsTest.php b/tests/Feature/Importing/AssetImportCheckoutTargetsTest.php
index b7778f8e3a..d6e50f1272 100644
--- a/tests/Feature/Importing/AssetImportCheckoutTargetsTest.php
+++ b/tests/Feature/Importing/AssetImportCheckoutTargetsTest.php
@@ -11,6 +11,7 @@ use App\Models\Location;
use App\Models\Statuslabel;
use App\Models\User;
use PHPUnit\Framework\Attributes\Test;
+use Tests\Support\Importing\CleansUpImportFiles;
use Tests\TestCase;
/**
@@ -26,6 +27,8 @@ use Tests\TestCase;
*/
class AssetImportCheckoutTargetsTest extends TestCase
{
+ use CleansUpImportFiles;
+
private function importCsv(string $csv, array $mappings, array $extraPayload = []): void
{
Category::factory()->create(['category_type' => 'asset']);
diff --git a/tests/Feature/Importing/AssetImportCheckoutWelcomeEmailTest.php b/tests/Feature/Importing/AssetImportCheckoutWelcomeEmailTest.php
index be93732dcc..ed646368b8 100644
--- a/tests/Feature/Importing/AssetImportCheckoutWelcomeEmailTest.php
+++ b/tests/Feature/Importing/AssetImportCheckoutWelcomeEmailTest.php
@@ -13,6 +13,7 @@ use App\Models\User;
use App\Notifications\WelcomeNotification;
use Illuminate\Support\Facades\Notification;
use PHPUnit\Framework\Attributes\Test;
+use Tests\Support\Importing\CleansUpImportFiles;
use Tests\TestCase;
/**
@@ -24,6 +25,8 @@ use Tests\TestCase;
*/
class AssetImportCheckoutWelcomeEmailTest extends TestCase
{
+ use CleansUpImportFiles;
+
private function importCsv(string $csv, array $mappings, array $extraPayload = []): void
{
Category::factory()->create(['category_type' => 'asset']);
diff --git a/tests/Feature/Importing/AssetImportCreatedAtTest.php b/tests/Feature/Importing/AssetImportCreatedAtTest.php
index 3e85375415..e177e3d117 100644
--- a/tests/Feature/Importing/AssetImportCreatedAtTest.php
+++ b/tests/Feature/Importing/AssetImportCreatedAtTest.php
@@ -11,10 +11,13 @@ use App\Models\Location;
use App\Models\Statuslabel;
use App\Models\User;
use PHPUnit\Framework\Attributes\Test;
+use Tests\Support\Importing\CleansUpImportFiles;
use Tests\TestCase;
class AssetImportCreatedAtTest extends TestCase
{
+ use CleansUpImportFiles;
+
/**
* Test that importing assets doesn't modify created_at timestamps on existing assets
* This test addresses the reported bug where large imports caused random created_at changes
diff --git a/tests/Feature/Importing/AssetImportCreatedByTest.php b/tests/Feature/Importing/AssetImportCreatedByTest.php
index 3efc5bb655..ec5232ded1 100644
--- a/tests/Feature/Importing/AssetImportCreatedByTest.php
+++ b/tests/Feature/Importing/AssetImportCreatedByTest.php
@@ -12,6 +12,7 @@ use App\Models\Location;
use App\Models\Statuslabel;
use App\Models\User;
use PHPUnit\Framework\Attributes\Test;
+use Tests\Support\Importing\CleansUpImportFiles;
use Tests\TestCase;
/**
@@ -26,6 +27,8 @@ use Tests\TestCase;
*/
class AssetImportCreatedByTest extends TestCase
{
+ use CleansUpImportFiles;
+
#[Test]
public function new_asset_created_via_import_records_the_importing_users_id_as_created_by(): void
{
diff --git a/tests/Feature/Importing/AssetImportDefaultLocationTest.php b/tests/Feature/Importing/AssetImportDefaultLocationTest.php
index 376c8bbaf5..298968661d 100644
--- a/tests/Feature/Importing/AssetImportDefaultLocationTest.php
+++ b/tests/Feature/Importing/AssetImportDefaultLocationTest.php
@@ -11,10 +11,13 @@ use App\Models\Location;
use App\Models\Statuslabel;
use App\Models\User;
use PHPUnit\Framework\Attributes\Test;
+use Tests\Support\Importing\CleansUpImportFiles;
use Tests\TestCase;
class AssetImportDefaultLocationTest extends TestCase
{
+ use CleansUpImportFiles;
+
private function runAssetImport(string $csv, array $mappings): void
{
Category::factory()->create(['category_type' => 'asset', 'name' => 'Default Loc Test Category']);
diff --git a/tests/Feature/Importing/AssetImportPreserveBlanksTest.php b/tests/Feature/Importing/AssetImportPreserveBlanksTest.php
index 214097788b..4eaffc424a 100644
--- a/tests/Feature/Importing/AssetImportPreserveBlanksTest.php
+++ b/tests/Feature/Importing/AssetImportPreserveBlanksTest.php
@@ -11,6 +11,7 @@ use App\Models\Location;
use App\Models\Statuslabel;
use App\Models\User;
use PHPUnit\Framework\Attributes\Test;
+use Tests\Support\Importing\CleansUpImportFiles;
use Tests\TestCase;
/**
@@ -22,6 +23,8 @@ use Tests\TestCase;
*/
class AssetImportPreserveBlanksTest extends TestCase
{
+ use CleansUpImportFiles;
+
#[Test]
public function default_update_clears_db_value_when_csv_cell_is_blank()
{
diff --git a/tests/Feature/Importing/Ui/ImportTest.php b/tests/Feature/Importing/Ui/ImportTest.php
index 1866a66b9a..08be8fdc81 100644
--- a/tests/Feature/Importing/Ui/ImportTest.php
+++ b/tests/Feature/Importing/Ui/ImportTest.php
@@ -4,11 +4,18 @@ namespace Tests\Feature\Importing\Ui;
use App\Models\User;
use Illuminate\Http\UploadedFile;
+use Illuminate\Support\Facades\Storage;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class ImportTest extends TestCase
{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Storage::fake();
+ }
+
public function test_page_renders()
{
$this->actingAs(User::factory()->superuser()->create())
diff --git a/tests/Feature/Reporting/ActivityReportTest.php b/tests/Feature/Reporting/ActivityReportTest.php
index 693751ea26..c6e44c5c97 100644
--- a/tests/Feature/Reporting/ActivityReportTest.php
+++ b/tests/Feature/Reporting/ActivityReportTest.php
@@ -8,11 +8,18 @@ use App\Models\AssetModel;
use App\Models\Company;
use App\Models\User;
use Illuminate\Http\UploadedFile;
+use Illuminate\Support\Facades\Storage;
use Illuminate\Testing\Fluent\AssertableJson;
use Tests\TestCase;
class ActivityReportTest extends TestCase
{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Storage::fake();
+ }
+
public function test_requires_permission_to_view_activity()
{
$this->actingAsForApi(User::factory()->create())
diff --git a/tests/TestCase.php b/tests/TestCase.php
index e4a7f6e96b..7f4f7894f9 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -8,6 +8,7 @@ use App\Models\Company;
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Http\UploadedFile;
+use Illuminate\Support\Facades\Storage;
use RuntimeException;
use Tests\Support\AssertHasActionLogs;
use Tests\Support\AssertsAgainstSlackNotifications;
@@ -50,9 +51,10 @@ abstract class TestCase extends BaseTestCase
* pollute the local dev dirs. Covers both the private-uploads tree
* (acceptance signatures, eula pdfs, imports, audits, model-owned
* attachments, etc) and the public-uploads tree (avatars, barcodes,
- * and model images). Disabled under `artisan test --parallel`
- * because workers isolate DBs but share the filesystem, so
- * Worker A's tearDown would race Worker B's in-flight writes.
+ * and model images). Skipped under `artisan test --parallel`
+ * because workers share the filesystem, so Worker A's tearDown
+ * would race Worker B's in-flight writes. Parallel mode uses
+ * Storage::fake() in setUp instead.
*
* @var array<int, string>
*/
@@ -87,7 +89,18 @@ abstract class TestCase extends BaseTestCase
// rolled-back model references between tests otherwise.
\App\Models\SyncAdapterConfig::flushInstanceCache();
- if (! $this->isRunningInParallel()) {
+ if ($this->isRunningInParallel()) {
+ // Parallel mode uses Laravel's fake public disk (rooted
+ // per worker under storage/framework/testing/disks/public)
+ // so controllers that call Storage::disk('public')->put()
+ // for avatars, item images, and barcodes land in the test
+ // garbage dir rather than polluting the real public tree.
+ // The default disk stays real because the import flow
+ // mixes Storage::put() writes with storage_path() reads
+ // and the two must agree. Single-process mode keeps the
+ // snapshot/diff sweep instead.
+ Storage::fake('public');
+ } else {
$this->uploadTreeSnapshot = $this->currentUploadTreeListing();
}
}
diff --git a/tests/Unit/AssetTest.php b/tests/Unit/AssetTest.php
index 22aa4f5ed1..a735472350 100644
--- a/tests/Unit/AssetTest.php
+++ b/tests/Unit/AssetTest.php
@@ -303,28 +303,31 @@ class AssetTest extends TestCase
public function test_get_image_url_method()
{
- $urlBase = config('filesystems.disks.public.url');
+ // Build expected URLs through the same disk the model uses so
+ // the assertion stays valid whether or not the public disk is
+ // faked (base setUp fakes it under --parallel).
+ $publicDisk = \Illuminate\Support\Facades\Storage::disk('public');
$category = Category::factory()->create(['image' => 'category-image.jpg']);
$model = AssetModel::factory()->for($category)->create(['image' => 'asset-model-image.jpg']);
$asset = Asset::factory()->for($model, 'model')->create(['image' => 'asset-image.jpg']);
$this->assertEquals(
- "{$urlBase}/assets/asset-image.jpg",
+ $publicDisk->url('assets/asset-image.jpg'),
$asset->getImageUrl()
);
$asset->update(['image' => null]);
$this->assertEquals(
- "{$urlBase}/models/asset-model-image.jpg",
+ $publicDisk->url('models/asset-model-image.jpg'),
$asset->refresh()->getImageUrl()
);
$model->update(['image' => null]);
$this->assertEquals(
- "{$urlBase}/categories/category-image.jpg",
+ $publicDisk->url('categories/category-image.jpg'),
$asset->refresh()->getImageUrl()
);