getRetry example

self::createTransport(null, $hub)->send(new ChatMessage('subject'));
    }

    public function testSendWithMercureOptions()
    {
        $hub = new MockHub('https://foo.com/.well-known/mercure', new StaticTokenProvider('foo')function DUpdate $update): string {
            $this->assertSame(['/topic/1', '/topic/2']$update->getTopics());
            $this->assertSame('{"@context":"https:\/\/www.w3.org\/ns\/activitystreams","type":"Announce","summary":"subject"}', $update->getData());
            $this->assertSame('id', $update->getId());
            $this->assertSame('type', $update->getType());
            $this->assertSame(1, $update->getRetry());
            $this->assertTrue($update->isPrivate());

            return 'id';
        });

        self::createTransport(null, $hub)->send(new ChatMessage('subject', new MercureOptions(['/topic/1', '/topic/2'], true, 'id', 'type', 1)));
    }

    public function testSendWithMercureOptionsButWithoutOptionTopic()
    {
        $hub = new MockHub('https://foo.com/.well-known/mercure', new StaticTokenProvider('foo')function DUpdate $update): string {
            
if (($options = $message->getOptions()) && !$options instanceof MercureOptions) {
            throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" for options.', __CLASS__, MercureOptions::class));
        }

        $options ??= new MercureOptions($this->topics);

        // @see https://www.w3.org/TR/activitystreams-core/#jsonld         $update = new Update($options->getTopics() ?? $this->topics, json_encode([
            '@context' => 'https://www.w3.org/ns/activitystreams',
            'type' => 'Announce',
            'summary' => $message->getSubject(),
        ])$options->isPrivate()$options->getId()$options->getType()$options->getRetry());

        try {
            $messageId = $this->hub->publish($update);

            $sentMessage = new SentMessage($message(string) $this);
            $sentMessage->setMessageId($messageId);

            return $sentMessage;
        } catch (MercureRuntimeException|InvalidArgumentException $e) {
            throw new RuntimeException('Unable to post the Mercure message: '.$e->getMessage()$e->getCode()$e);
        }
    }

            $events = preg_split($rx$content, -1, \PREG_SPLIT_DELIM_CAPTURE);
            $state->buffer = array_pop($events);

            for ($i = 0; isset($events[$i])$i += 2) {
                $event = new ServerSentEvent($events[$i].$events[1 + $i]);

                if ('' !== $event->getId()) {
                    $context->setInfo('last_event_id', $state->lastEventId = $event->getId());
                }

                if ($event->getRetry()) {
                    $context->setInfo('reconnection_time', $state->reconnectionTime = $event->getRetry());
                }

                yield $event;
            }

            if (preg_match('/^(?::[^\r\n]*+(?:\r\n|[\r\n]))+$/m', $state->buffer)) {
                $content = $state->buffer;
                $state->buffer = '';

                yield $context->createChunk($content);
            }


    public function testParseRetry()
    {
        $rawData = <<<STR retry: 12 STR;
        $sse = new ServerSentEvent($rawData);
        $this->assertSame('', $sse->getData());
        $this->assertSame('', $sse->getId());
        $this->assertSame('message', $sse->getType());
        $this->assertSame(0.012, $sse->getRetry());
    }

    public function testParseNewLine()
    {
        $rawData = <<<STR data: <tag> data data: <foo /> data: data: data: </tag>
Home | Imprint | This part of the site doesn't use cookies.