Add unit tests for cleaner and machine relay flows, refactor relay logic with hard set methods, enhance route handling for lane state transitions, and update session management.
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
app_require('modules/selfserve/traits/selfserve_lane_port_controller_t.php');
|
||||
app_require('modules/selfserve/helpers/selfserve_lane_port.php');
|
||||
app_require('modules/shelly/helpers/shelly_device_switch.php');
|
||||
|
||||
use modules\selfserve\helpers\selfserve_lane_port;
|
||||
use modules\selfserve\traits\selfserve_lane_port_controller_t;
|
||||
use modules\shelly\helpers\shelly_device_switch;
|
||||
|
||||
class SelfserveLanePortValueFake
|
||||
{
|
||||
public function __construct(private readonly string $value) {}
|
||||
|
||||
public function value(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
class SelfserveLanePortDepartmentLaneFake
|
||||
{
|
||||
public SelfserveLanePortValueFake $relay_in_id;
|
||||
public SelfserveLanePortValueFake $relay_out_id;
|
||||
|
||||
public function __construct(string $relayInId, string $relayOutId)
|
||||
{
|
||||
$this->relay_in_id = new SelfserveLanePortValueFake($relayInId);
|
||||
$this->relay_out_id = new SelfserveLanePortValueFake($relayOutId);
|
||||
}
|
||||
}
|
||||
|
||||
class SelfserveLanePortSwitchFake extends shelly_device_switch
|
||||
{
|
||||
/** @var array<int,array{id:string,on:bool}> */
|
||||
public array $switchCalls = [];
|
||||
|
||||
public function switch(bool $on, ?bool $skip_toggle_after = false): array|object|null
|
||||
{
|
||||
$this->switchCalls[] = [
|
||||
'id' => $this->id,
|
||||
'on' => $on,
|
||||
];
|
||||
return ['ok' => true];
|
||||
}
|
||||
}
|
||||
|
||||
class SelfserveLanePortControllerHarness
|
||||
{
|
||||
use selfserve_lane_port_controller_t;
|
||||
|
||||
public int $id = 55;
|
||||
public object $department_lane;
|
||||
public SelfserveLanePortSwitchFake $switchFake;
|
||||
|
||||
public function __construct(string $relayInId, string $relayOutId)
|
||||
{
|
||||
$this->department_lane = new SelfserveLanePortDepartmentLaneFake($relayInId, $relayOutId);
|
||||
$this->switchFake = new SelfserveLanePortSwitchFake();
|
||||
}
|
||||
|
||||
protected function createShellySwitchDevice(): shelly_device_switch
|
||||
{
|
||||
return $this->switchFake;
|
||||
}
|
||||
}
|
||||
|
||||
it('opens exit port by switching relay_in_id on', function (): void {
|
||||
$lane = new SelfserveLanePortControllerHarness(
|
||||
relayInId: 'relay-in-123',
|
||||
relayOutId: 'relay-out-123'
|
||||
);
|
||||
|
||||
$result = $lane->shellyOpenPort(selfserve_lane_port::EXIT);
|
||||
|
||||
expect($result)->toBeTrue();
|
||||
expect($lane->switchFake->switchCalls)->toBe([
|
||||
[
|
||||
'id' => 'relay-in-123',
|
||||
'on' => true,
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
it('opens entrance port by switching relay_out_id on', function (): void {
|
||||
$lane = new SelfserveLanePortControllerHarness(
|
||||
relayInId: 'relay-in-123',
|
||||
relayOutId: 'relay-out-123'
|
||||
);
|
||||
|
||||
$result = $lane->shellyOpenPort(selfserve_lane_port::ENTRANCE);
|
||||
|
||||
expect($result)->toBeTrue();
|
||||
expect($lane->switchFake->switchCalls)->toBe([
|
||||
[
|
||||
'id' => 'relay-out-123',
|
||||
'on' => true,
|
||||
],
|
||||
]);
|
||||
});
|
||||
Reference in New Issue
Block a user