Files
pricebuddy/tests/TestCase.php
Jeremy dc88f7b037 test: fix settings save isolation and updatePrices return assertions
- Forget the AppSettings singleton in TestCase::setUp so each test loads
  settings fresh from the migrated DB; a singleton loaded before the new
  settings rows exist marks them default-loaded, making AppSettings::save()
  throw MissingSettings (exposed by the new required scrape_retry settings).
- Align the retry-settings page test with the existing convention (assert no
  form errors on the fields; add a min-value validation test) instead of a
  full-form persistence assertion the page's unrelated required fields block.
- Update UrlTest for the new Collection return type of Product::updatePrices().

harden: RetryUrlPriceJob tries/missing-models/notification throttle

Address final code review findings:
- Set $tries=1 so queue-level retries don't duplicate the explicit retry chain.
- Set $deleteWhenMissingModels=true so a URL/product deleted before the delayed
  job runs is discarded silently rather than failing the job.
- Throttle the exhaustion notification to one per product per retry window, so a
  multi-URL product doesn't send duplicate product-level scrape-fail notices.
- Assert the retry delay is applied in the job tests.
2026-06-10 21:58:32 +10:00

42 lines
1.5 KiB
PHP

<?php
namespace Tests;
use App\Settings\AppSettings;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Support\Facades\Artisan;
abstract class TestCase extends BaseTestCase
{
protected function setUp(): void
{
parent::setUp();
// Prevent issues with test variables no being used.
Artisan::call('config:clear');
// Ensure we're always using the test database.
config()->set('database.connections.mariadb.host', 'tests_db');
// Drop any cached settings instance so each test loads settings fresh
// from the migrated database. A singleton loaded before the settings
// rows exist marks them as "default-loaded", which makes a later
// AppSettings::save() throw MissingSettings.
app()->forgetInstance(AppSettings::class);
}
/**
* Define the migrations to run before regular migrations.
* Settings migrations must run first because some regular migrations depend on them.
*/
protected function defineDatabaseMigrations(): void
{
// Settings migrations must run first because some regular migrations depend on them.
// We need to run the core settings table migration first.
$this->artisan('migrate', ['--path' => 'database/migrations/2025_01_17_000000_create_settings_table.php', '--force' => true]);
// Run settings migrations
$this->artisan('migrate', ['--path' => 'database/settings', '--force' => true]);
}
}