2026-04-21 19:00:17 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Chrisyue\PhpM3u8\Test\Line;
|
|
|
|
|
|
|
|
|
|
use Chrisyue\PhpM3u8\Line\Line;
|
|
|
|
|
use Chrisyue\PhpM3u8\Line\Lines;
|
|
|
|
|
use Chrisyue\PhpM3u8\Stream\StreamInterface;
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
2026-09-13 14:14:23 +03:00
|
|
|
class LinesTest extends TestCase {
|
|
|
|
|
public function testValid(): void {
|
2026-04-21 19:00:17 +03:00
|
|
|
$stream = new class([false], [null]) implements StreamInterface {
|
|
|
|
|
private array $validSequence;
|
|
|
|
|
private array $currentSequence;
|
|
|
|
|
private int $position = 0;
|
|
|
|
|
|
2026-09-13 14:14:23 +03:00
|
|
|
public function __construct(array $validSequence, array $currentSequence) {
|
2026-04-21 19:00:17 +03:00
|
|
|
$this->validSequence = $validSequence;
|
|
|
|
|
$this->currentSequence = $currentSequence;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-13 14:14:23 +03:00
|
|
|
public function current(): mixed {
|
2026-04-21 19:00:17 +03:00
|
|
|
return $this->currentSequence[$this->position] ?? null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-13 14:14:23 +03:00
|
|
|
public function next(): void {
|
2026-04-21 19:00:17 +03:00
|
|
|
++$this->position;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-13 14:14:23 +03:00
|
|
|
public function key(): mixed {
|
2026-04-21 19:00:17 +03:00
|
|
|
return $this->position;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-13 14:14:23 +03:00
|
|
|
public function valid(): bool {
|
2026-04-21 19:00:17 +03:00
|
|
|
return $this->validSequence[$this->position] ?? false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-13 14:14:23 +03:00
|
|
|
public function rewind(): void {
|
2026-04-21 19:00:17 +03:00
|
|
|
$this->position = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-13 14:14:23 +03:00
|
|
|
public function add($line): void {
|
2026-04-21 19:00:17 +03:00
|
|
|
$this->currentSequence[] = $line;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
$lines = new Lines($stream);
|
|
|
|
|
|
|
|
|
|
$this->assertFalse($lines->valid());
|
|
|
|
|
|
|
|
|
|
$tag = 'EXT-X-FOO:1';
|
|
|
|
|
$stream = new class([true], [$tag]) implements StreamInterface {
|
|
|
|
|
private array $validSequence;
|
|
|
|
|
private array $currentSequence;
|
|
|
|
|
private int $position = 0;
|
|
|
|
|
|
2026-09-13 14:14:23 +03:00
|
|
|
public function __construct(array $validSequence, array $currentSequence) {
|
2026-04-21 19:00:17 +03:00
|
|
|
$this->validSequence = $validSequence;
|
|
|
|
|
$this->currentSequence = $currentSequence;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-13 14:14:23 +03:00
|
|
|
public function current(): mixed {
|
2026-04-21 19:00:17 +03:00
|
|
|
return $this->currentSequence[$this->position] ?? null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-13 14:14:23 +03:00
|
|
|
public function next(): void {
|
2026-04-21 19:00:17 +03:00
|
|
|
++$this->position;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-13 14:14:23 +03:00
|
|
|
public function key(): mixed {
|
2026-04-21 19:00:17 +03:00
|
|
|
return $this->position;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-13 14:14:23 +03:00
|
|
|
public function valid(): bool {
|
2026-04-21 19:00:17 +03:00
|
|
|
return $this->validSequence[$this->position] ?? false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-13 14:14:23 +03:00
|
|
|
public function rewind(): void {
|
2026-04-21 19:00:17 +03:00
|
|
|
$this->position = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-13 14:14:23 +03:00
|
|
|
public function add($line): void {
|
2026-04-21 19:00:17 +03:00
|
|
|
$this->currentSequence[] = $line;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
$lines = new Lines($stream);
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($lines->valid());
|
|
|
|
|
$this->assertEquals(Line::fromString($tag), $lines->current());
|
|
|
|
|
}
|
|
|
|
|
}
|