Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable29] fix: handle getNetInterfaces error #633

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/OperatingSystems/FreeBSD.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ public function getNetworkInfo(): array {
public function getNetworkInterfaces(): array {
$data = [];

foreach ($this->getNetInterfaces() as $interfaceName => $interface) {
try {
$interfaces = $this->getNetInterfaces();
} catch (RuntimeException) {
return $data;
}

foreach ($interfaces as $interfaceName => $interface) {
$netInterface = new NetInterface($interfaceName, $interface['up']);
$data[] = $netInterface;

Expand Down
8 changes: 7 additions & 1 deletion lib/OperatingSystems/Linux.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,13 @@ public function getNetworkInfo(): array {
public function getNetworkInterfaces(): array {
$data = [];

foreach ($this->getNetInterfaces() as $interfaceName => $interface) {
try {
$interfaces = $this->getNetInterfaces();
} catch (RuntimeException) {
return $data;
}

foreach ($interfaces as $interfaceName => $interface) {
$netInterface = new NetInterface($interfaceName, $interface['up']);
$data[] = $netInterface;

Expand Down
10 changes: 10 additions & 0 deletions tests/lib/FreeBSDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ public function testGetNetworkInterfaces(): void {
$this->assertEquals($expected, $actual);
}

public function testGetNetworkInterfacesError(): void {
$this->os->method('getNetInterfaces')
->willThrowException(new RuntimeException('Unable to get network interfaces'));

$expected = [];
$actual = $this->os->getNetworkInterfaces();

$this->assertEquals($expected, $actual);
}

public function testSupported(): void {
$this->assertFalse($this->os->supported());
}
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/LinuxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,14 @@ public function testGetNetworkInterfaces(): void {

$this->assertEquals($expected, $actual);
}

public function testGetNetworkInterfacesError(): void {
$this->os->method('getNetInterfaces')
->willThrowException(new RuntimeException('Unable to get network interfaces'));

$expected = [];
$actual = $this->os->getNetworkInterfaces();

$this->assertEquals($expected, $actual);
}
}
Loading