alltube/tests/PlaylistArchiveStreamTest.php

206 lines
3.9 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;
use RuntimeException;
2019-04-21 00:58:04 +02:00
use stdClass;
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';
}
$entry = new stdClass();
$entry->url = 'BaW_jenozKc';
$video = new stdClass();
$video->entries = [$entry, $entry];
$this->stream = new PlaylistArchiveStream(Config::getInstance('config/'.$configFile), $video, 'worst');
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->close();
2019-04-20 00:37:49 +02:00
}
2017-05-02 17:04:55 +02:00
/**
* Test the write() function.
2017-05-02 17:04:55 +02:00
*
* @return void
* @expectedException RuntimeException
2017-05-02 17:04:55 +02:00
*/
public function testWrite()
2017-05-02 17:04:55 +02:00
{
$this->stream->write('foo');
2017-05-02 17:04:55 +02:00
}
/**
* Test the tell() function.
2017-05-02 17:04:55 +02:00
*
* @return void
*/
public function testTell()
2017-05-02 17:04:55 +02:00
{
$this->assertInternalType('int', $this->stream->tell());
2017-05-02 17:04:55 +02:00
}
/**
* Test the seek() function.
2017-05-02 17:04:55 +02:00
*
* @return void
* @expectedException RuntimeException
2017-05-02 17:04:55 +02:00
*/
public function testSeek()
2017-05-02 17:04:55 +02:00
{
$this->stream->seek(42);
2017-05-02 17:04:55 +02:00
}
/**
* Test the read() function.
2017-05-02 17:04:55 +02:00
*
* @return void
*/
public function testRead()
2017-05-02 17:04:55 +02:00
{
while (!$this->stream->eof()) {
$result = $this->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 eof() function.
2017-05-02 17:04:55 +02:00
*
* @return void
*/
public function testEof()
2017-05-02 17:04:55 +02:00
{
$this->assertFalse($this->stream->eof());
2017-05-02 17:04:55 +02:00
}
/**
* Test the getSize() function.
2017-05-02 17:04:55 +02:00
*
* @return void
*/
public function testGetSize()
2017-05-02 17:04:55 +02:00
{
$this->assertNull($this->stream->getSize());
}
/**
* Test the isSeekable() function.
*
* @return void
*/
public function testIsSeekable()
{
$this->assertFalse($this->stream->isSeekable());
}
/**
* Test the rewind() function.
*
* @return void
* @expectedException RuntimeException
*/
public function testRewind()
{
$this->stream->rewind();
}
/**
* Test the isWritable() function.
*
* @return void
*/
public function testIsWritable()
{
$this->assertFalse($this->stream->isWritable());
}
/**
* Test the isReadable() function.
*
* @return void
*/
public function testIsReadable()
{
$this->assertTrue($this->stream->isReadable());
}
/**
* Test the getContents() function.
*
* @return void
*/
public function testGetContents()
{
$this->assertInternalType('string', $this->stream->getContents());
}
/**
* Test the getMetadata() function.
*
* @return void
*/
public function testGetMetadata()
{
$this->assertNull($this->stream->getMetadata());
}
/**
* Test the detach() function.
*
* @return void
*/
public function testDetach()
{
$this->assertInternalType('resource', $this->stream->detach());
2017-05-02 17:04:55 +02:00
}
/**
* Test the __toString() function.
2017-05-02 17:04:55 +02:00
*
* @return void
*/
public function testToString()
2017-05-02 17:04:55 +02:00
{
$this->assertInternalType('string', $this->stream->__toString());
$this->assertInternalType('string', (string) $this->stream);
2017-05-02 17:04:55 +02:00
}
}