. * */ namespace Ampache\Config\Init; use Ampache\Config\AmpConfig; use Ampache\Config\Init\Exception\EnvironmentNotSuitableException; use Ampache\MockeryTestCase; use Ampache\Module\System\Update\UpdaterInterface; use Mockery\MockInterface; use Override; use PHPUnit\Framework\Attributes\RunInSeparateProcess; /** * `hasPendingUpdates()` needs a reachable database, which this unit suite has none of, so only the bypass and * an unreachable database are covered here; the pending-update branch has to be proven against a real instance. */ class InitializationHandlerDatabaseUpdateTest extends MockeryTestCase { private string $originalHostname; private MockInterface|UpdaterInterface|null $updater; public function testAnUnreachableDatabaseIsReportedAsEnvironmentNotSuitable(): void { // an empty hostname makes Dba::_connect() return null without attempting any connection, so this // is deterministic regardless of what database (if any) the running environment can actually reach AmpConfig::set('database_hostname', '', true); $this->updater->shouldNotReceive('hasPendingUpdates'); $this->expectException(EnvironmentNotSuitableException::class); new InitializationHandlerDatabaseUpdate($this->updater)->init(); } #[RunInSeparateProcess] public function testOutdatedDatabaseOkSkipsTheCheckEntirely(): void { define('OUTDATED_DATABASE_OK', 1); $this->updater->shouldNotReceive('hasPendingUpdates'); new InitializationHandlerDatabaseUpdate($this->updater)->init(); } #[Override] protected function setUp(): void { $this->updater = $this->mock(UpdaterInterface::class); $this->originalHostname = (string) AmpConfig::get('database_hostname', ''); } #[Override] protected function tearDown(): void { AmpConfig::set('database_hostname', $this->originalHostname, true); parent::tearDown(); } }