Skip to content

Commit 9c7df3b

Browse files
committed
test: improved test for downloading the package to make it more robust
1 parent 9bb225f commit 9c7df3b

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

tests/phpMyFAQ/Setup/UpgradeTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,19 @@ protected function setUp(): void
2828
*/
2929
public function testDownloadPackage(): void
3030
{
31-
$actual = $this->upgrade->downloadPackage('3.1.15');
32-
$this->assertIsString($actual);
31+
if (!$this->isNetworkAvailable()) {
32+
$this->markTestSkipped('Network not available');
33+
}
34+
35+
try {
36+
$actual = $this->upgrade->downloadPackage('3.1.15');
37+
$this->assertIsString($actual);
38+
} catch (Exception $e) {
39+
if (str_contains($e->getMessage(), 'timeout') || str_contains($e->getMessage(), 'connection')) {
40+
$this->markTestSkipped('Network timeout: ' . $e->getMessage());
41+
}
42+
throw $e;
43+
}
3344

3445
$this->expectException('phpMyFAQ\Core\Exception');
3546
$this->upgrade->downloadPackage('1.2.3');
@@ -87,4 +98,13 @@ public function testGetPathForNonNightly(): void
8798

8899
$this->assertEquals('', $this->upgrade->getPath());
89100
}
101+
102+
private function isNetworkAvailable(): bool
103+
{
104+
$context = stream_context_create([
105+
'http' => ['timeout' => 5]
106+
]);
107+
108+
return @file_get_contents('https://download.phpmyfaq.de', false, $context) !== false;
109+
}
90110
}

0 commit comments

Comments
 (0)