public function register(string $name, TransportInterface $transport): void
18
{
19
$this->transports[$name] = $transport;
20
}
21
22
public function get(?string $name = null): TestTransport
23
{
24
if (0 === \count($this->transports)) {
25
throw new \LogicException('No transports registered.');
26
}
27
28
if (null === $name && 1 !== \count($this->transports)) {
29
throw new \InvalidArgumentException(\sprintf('Multiple transports are registered (%s), you must specify a name.', \implode(', ', \array_keys($this->transports))));
30
}
31
32
if (null === $name) {
33
$name = \array_key_first($this->transports);
34
}
35
36
if (!$transport = $this->transports[$name] ?? null) {
37
throw new \InvalidArgumentException("Transport \"{$name}\" not registered.");
38
}
39
40
if (!$transport instanceof TestTransport) {
41
throw new \LogicException("Transport \"{$name}\" needs to be set to \"test://\" in your test config to use this feature.");