2026-04-21 19:00:17 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Chrisyue\PhpM3u8\Test\Line;
|
|
|
|
|
|
|
|
|
|
use Chrisyue\PhpM3u8\Line\Line;
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
2026-09-13 14:14:23 +03:00
|
|
|
class LineTest extends TestCase {
|
2026-04-21 19:00:17 +03:00
|
|
|
/**
|
|
|
|
|
* @dataProvider stringTransformationSamples
|
|
|
|
|
*/
|
2026-09-13 14:14:23 +03:00
|
|
|
public function testFromString($string, $expected): void {
|
2026-04-21 19:00:17 +03:00
|
|
|
$line = Line::fromString($string);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $line);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider stringTransformationSamples
|
|
|
|
|
*/
|
2026-09-13 14:14:23 +03:00
|
|
|
public function testToString($string, Line $line = null): void {
|
2026-04-21 19:00:17 +03:00
|
|
|
if (null === $line) {
|
|
|
|
|
$this->expectNotToPerformAssertions();
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($string, (string) $line);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-13 14:14:23 +03:00
|
|
|
public static function stringTransformationSamples(): array {
|
2026-04-21 19:00:17 +03:00
|
|
|
return [
|
|
|
|
|
['#foo:bar', null],
|
|
|
|
|
['#EXT-FOO', new Line('EXT-FOO', true)],
|
|
|
|
|
['bar', new Line(null, 'bar')],
|
|
|
|
|
[' ', null],
|
|
|
|
|
['#', null],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider typeSamples
|
|
|
|
|
*/
|
2026-09-13 14:14:23 +03:00
|
|
|
public function testIsType(Line $line, $type): void {
|
2026-04-21 19:00:17 +03:00
|
|
|
$this->assertTrue($line->isType($type));
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-13 14:14:23 +03:00
|
|
|
public static function typeSamples(): array {
|
2026-04-21 19:00:17 +03:00
|
|
|
return [
|
|
|
|
|
[new Line('foo', 'bar'), Line::TYPE_TAG],
|
|
|
|
|
[new Line(null, 'foobar'), Line::TYPE_URI],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|