alltube/tests/PlaylistArchiveStreamTest.php

206 lines
3.9 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;
use RuntimeException;
2019-04-20 22:58:04 +00:00
use stdClass;
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';
}
$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 15:04:55 +00:00
}
2019-04-19 22:37:49 +00:00
/**
* Clean variables used in tests.
*
* @return void
*/
protected function tearDown()
{
$this->stream->close();
2019-04-19 22:37:49 +00:00
}
2017-05-02 15:04:55 +00:00
/**
* Test the write() function.
2017-05-02 15:04:55 +00:00
*
* @return void
* @expectedException RuntimeException
2017-05-02 15:04:55 +00:00
*/
public function testWrite()
2017-05-02 15:04:55 +00:00
{
$this->stream->write('foo');
2017-05-02 15:04:55 +00:00
}
/**
* Test the tell() function.
2017-05-02 15:04:55 +00:00
*
* @return void
*/
public function testTell()
2017-05-02 15:04:55 +00:00
{
$this->assertInternalType('int', $this->stream->tell());
2017-05-02 15:04:55 +00:00
}
/**
* Test the seek() function.
2017-05-02 15:04:55 +00:00
*
* @return void
* @expectedException RuntimeException
2017-05-02 15:04:55 +00:00
*/
public function testSeek()
2017-05-02 15:04:55 +00:00
{
$this->stream->seek(42);
2017-05-02 15:04:55 +00:00
}
/**
* Test the read() function.
2017-05-02 15:04:55 +00:00
*
* @return void
*/
public function testRead()
2017-05-02 15:04:55 +00: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 15:04:55 +00:00
}
/**
* Test the eof() function.
2017-05-02 15:04:55 +00:00
*
* @return void
*/
public function testEof()
2017-05-02 15:04:55 +00:00
{
$this->assertFalse($this->stream->eof());
2017-05-02 15:04:55 +00:00
}
/**
* Test the getSize() function.
2017-05-02 15:04:55 +00:00
*
* @return void
*/
public function testGetSize()
2017-05-02 15:04:55 +00: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 15:04:55 +00:00
}
/**
* Test the __toString() function.
2017-05-02 15:04:55 +00:00
*
* @return void
*/
public function testToString()
2017-05-02 15:04:55 +00:00
{
$this->assertInternalType('string', $this->stream->__toString());
$this->assertInternalType('string', (string) $this->stream);
2017-05-02 15:04:55 +00:00
}
}