Stabilize discovery workflow
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Domovoy\Tests\Inventory;
|
||||
|
||||
use Domovoy\Models\Device;
|
||||
use Domovoy\Models\DiscoveredHost;
|
||||
use Domovoy\Repositories\DeviceRepository;
|
||||
use Domovoy\Services\Inventory\MergeSuggestionService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class MergeSuggestionServiceTest extends TestCase
|
||||
{
|
||||
public function testSuggestsDeviceByIpWhenMacAndHostnameDoNotMatch(): void
|
||||
{
|
||||
$device = new Device();
|
||||
$device->id = 10;
|
||||
$device->name = 'router';
|
||||
$device->primaryIp = '192.168.1.1';
|
||||
|
||||
$repository = new FakeDeviceRepository(ipMatch: $device);
|
||||
$service = new MergeSuggestionService($repository);
|
||||
|
||||
$host = new DiscoveredHost();
|
||||
$host->ipAddress = '192.168.1.1';
|
||||
|
||||
$suggestions = $service->findSuggestions($host);
|
||||
|
||||
self::assertSame($device, $suggestions[0]['device']);
|
||||
self::assertSame(40, $suggestions[0]['confidence']);
|
||||
self::assertSame('IP адрес совпадает', $suggestions[0]['reason']);
|
||||
}
|
||||
}
|
||||
|
||||
final class FakeDeviceRepository extends DeviceRepository
|
||||
{
|
||||
public function __construct(
|
||||
private ?Device $macMatch = null,
|
||||
private ?Device $nameMatch = null,
|
||||
private ?Device $ipMatch = null
|
||||
) {
|
||||
}
|
||||
|
||||
public function findByMac(string $macAddress): ?Device
|
||||
{
|
||||
return $this->macMatch;
|
||||
}
|
||||
|
||||
public function findByName(string $name): ?Device
|
||||
{
|
||||
return $this->nameMatch;
|
||||
}
|
||||
|
||||
public function findByIp(string $ipAddress): ?Device
|
||||
{
|
||||
return $this->ipMatch;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user