alltube/tests/PlaylistArchiveStreamTest.php

117 lines
2.5 KiB
PHP
Raw Normal View History

2017-05-02 15:04:55 +00:00
<?php
/**
* PlaylistArchiveStreamTest class.
*/
namespace Alltube\Test;
use Alltube\Config;
2017-05-02 15:04:55 +00:00
use Alltube\PlaylistArchiveStream;
2017-10-26 08:46:22 +00:00
use PHPUnit\Framework\TestCase;
2017-05-02 15:04:55 +00:00
/**
* Unit tests for the ViewFactory class.
*/
2017-10-26 08:46:22 +00:00
class PlaylistArchiveStreamTest extends TestCase
2017-05-02 15:04:55 +00:00
{
2017-05-04 22:08:43 +00:00
/**
* PlaylistArchiveStream instance.
*
* @var PlaylistArchiveStream
*/
private $stream;
2017-05-02 15:04:55 +00:00
/**
* Prepare tests.
*/
protected function setUp()
{
if (PHP_OS == 'WINNT') {
$configFile = 'config_test_windows.yml';
} else {
$configFile = 'config_test.yml';
}
$this->stream = new PlaylistArchiveStream(Config::getInstance('config/'.$configFile));
2017-05-02 15:04:55 +00:00
}
/**
* Test the stream_open() function.
*
* @return void
*/
public function testStreamOpen()
{
2017-05-04 22:16:16 +00:00
$this->assertTrue($this->stream->stream_open('playlist://foo'));
2017-05-02 15:04:55 +00:00
}
/**
* Test the stream_write() function.
*
* @return void
*/
public function testStreamWrite()
{
$this->assertEquals(0, $this->stream->stream_write());
}
/**
* Test the stream_stat() function.
*
* @return void
*/
public function testStreamStat()
{
2017-10-29 22:21:13 +00:00
$this->assertEquals(['mode' => 4096], $this->stream->stream_stat());
2017-05-02 15:04:55 +00:00
}
/**
* Test the stream_tell() function.
*
* @return void
*/
public function testStreamTell()
{
2017-05-04 22:16:16 +00:00
$this->stream->stream_open('playlist://foo');
2017-05-02 15:04:55 +00:00
$this->assertInternalType('int', $this->stream->stream_tell());
}
/**
* Test the stream_seek() function.
*
* @return void
*/
public function testStreamSeek()
{
2017-05-04 22:16:16 +00:00
$this->stream->stream_open('playlist://foo');
2017-05-02 15:04:55 +00:00
$this->assertInternalType('bool', $this->stream->stream_seek(3));
}
/**
* Test the stream_read() function.
*
* @return void
*/
public function testStreamRead()
{
2017-05-04 22:16:16 +00:00
$this->stream->stream_open('playlist://BaW_jenozKc;BaW_jenozKc/worst');
2017-05-02 15:04:55 +00:00
while (!$this->stream->stream_eof()) {
$result = $this->stream->stream_read(8192);
$this->assertInternalType('string', $result);
if (is_string($result)) {
$this->assertLessThanOrEqual(8192, strlen($result));
}
2017-05-02 15:04:55 +00:00
}
}
/**
* Test the stream_eof() function.
*
* @return void
*/
public function testStreamEof()
{
2017-05-04 22:16:16 +00:00
$this->stream->stream_open('playlist://foo');
$this->assertFalse($this->stream->stream_eof());
2017-05-02 15:04:55 +00:00
}
}