alltube/tests/PlaylistArchiveStreamTest.php

127 lines
2.7 KiB
PHP
Raw Normal View History

2017-05-02 17:04:55 +02:00
<?php
/**
* PlaylistArchiveStreamTest class.
*/
namespace Alltube\Test;
use Alltube\Config;
2017-05-02 17:04:55 +02:00
use Alltube\PlaylistArchiveStream;
2017-10-26 10:46:22 +02:00
use PHPUnit\Framework\TestCase;
2017-05-02 17:04:55 +02:00
/**
* Unit tests for the ViewFactory class.
*/
2017-10-26 10:46:22 +02:00
class PlaylistArchiveStreamTest extends TestCase
2017-05-02 17:04:55 +02:00
{
2017-05-05 00:08:43 +02:00
/**
* PlaylistArchiveStream instance.
*
* @var PlaylistArchiveStream
*/
private $stream;
2017-05-02 17:04:55 +02: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 17:04:55 +02:00
}
2019-04-20 00:37:49 +02:00
/**
* Clean variables used in tests.
*
* @return void
*/
protected function tearDown()
{
$this->stream->stream_close();
}
2017-05-02 17:04:55 +02:00
/**
* Test the stream_open() function.
*
* @return void
*/
public function testStreamOpen()
{
2017-05-05 00:16:16 +02:00
$this->assertTrue($this->stream->stream_open('playlist://foo'));
2017-05-02 17:04:55 +02: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 23:21:13 +01:00
$this->assertEquals(['mode' => 4096], $this->stream->stream_stat());
2017-05-02 17:04:55 +02:00
}
/**
* Test the stream_tell() function.
*
* @return void
*/
public function testStreamTell()
{
2017-05-05 00:16:16 +02:00
$this->stream->stream_open('playlist://foo');
2017-05-02 17:04:55 +02:00
$this->assertInternalType('int', $this->stream->stream_tell());
}
/**
* Test the stream_seek() function.
*
* @return void
*/
public function testStreamSeek()
{
2017-05-05 00:16:16 +02:00
$this->stream->stream_open('playlist://foo');
2017-05-02 17:04:55 +02:00
$this->assertInternalType('bool', $this->stream->stream_seek(3));
}
/**
* Test the stream_read() function.
*
* @return void
*/
public function testStreamRead()
{
2017-05-05 00:16:16 +02:00
$this->stream->stream_open('playlist://BaW_jenozKc;BaW_jenozKc/worst');
2017-05-02 17:04:55 +02: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 17:04:55 +02:00
}
}
/**
* Test the stream_eof() function.
*
* @return void
*/
public function testStreamEof()
{
2017-05-05 00:16:16 +02:00
$this->stream->stream_open('playlist://foo');
$this->assertFalse($this->stream->stream_eof());
2017-05-02 17:04:55 +02:00
}
}