Lines 62.50% 5 / 8
Functions and Methods 57.14% 4 / 7
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
RecordingExposedSelect 62.50% 5 / 8 57.14% 4 / 7 11.38 0.00% 0 / 1
 getConfig 0.00% 0 / 1 0.00% 0 / 1 2
 updateConfig 0.00% 0 / 1 0.00% 0 / 1 2
 getOption 100.00% 2 / 2 100.00% 1 / 1 2
 setOption 100.00% 1 / 1 100.00% 1 / 1 1
 watchCommands 0.00% 0 / 1 0.00% 0 / 1 2
 pushCommand 100.00% 1 / 1 100.00% 1 / 1 1
 pushOption 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Testing\Exposure;
6
7use Stewart\Contracts\EventStream;
8use Stewart\Contracts\Exception\CommandException;
9use Stewart\Contracts\Exposure\Command\SelectCommand;
10use Stewart\Contracts\Exposure\ExposedSelect;
11use Stewart\Contracts\Exposure\ExposedState;
12use Stewart\Contracts\Exposure\ExposedStateChange;
13use Stewart\Contracts\Exposure\SelectConfig;
14use Stewart\Contracts\State\EventContext;
15
16/** @extends RecordingExposedEntity<SelectConfig> */
17final class RecordingExposedSelect extends RecordingExposedEntity implements ExposedSelect
18{
19    public function getConfig(): SelectConfig
20    {
21        return $this->config;
22    }
23
24    public function updateConfig(SelectConfig $config): void
25    {
26        $this->recordConfig($config);
27    }
28
29    public function getOption(): ?string
30    {
31        $value = $this->findStateValue();
32
33        return \is_string($value) ? $value : null;
34    }
35
36    public function setOption(?string $option, ?array $attributes = null): void
37    {
38        $this->recordChange(new ExposedStateChange(new ExposedState($option), $attributes));
39    }
40
41    public function watchCommands(): EventStream
42    {
43        /** @var EventStream<SelectCommand> */
44        return $this->watchPushedCommands();
45    }
46
47    /** @throws CommandException */
48    public function pushCommand(SelectCommand $command): void
49    {
50        $this->deliverCommand($command);
51    }
52
53    /** @throws CommandException */
54    public function pushOption(string $option, ?EventContext $context = null): void
55    {
56        $this->pushCommand(new SelectCommand($option, $context ?? EventContext::unknown()));
57    }
58}