Skip to content
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
fix: handle getNetInterfaces error
Signed-off-by: Daniel Kesselberg <[email protected]>
  • Loading branch information
kesselb committed Jun 24, 2024
commit ce95c08b1b0bb782fc58e18a9b81b5cd2e58c9cf
8 changes: 7 additions & 1 deletion lib/OperatingSystems/FreeBSD.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,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 @@ -144,7 +144,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 @@ -134,6 +134,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 @@ -245,4 +245,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);
}
}