2017-05-02 15:04:55 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PlaylistArchiveStreamTest class.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Alltube\Test;
|
|
|
|
|
2017-11-11 12:58:55 +00:00
|
|
|
use Alltube\Config;
|
2019-04-21 16:30:02 +00:00
|
|
|
use Alltube\Video;
|
2017-05-02 15:04:55 +00:00
|
|
|
use Alltube\PlaylistArchiveStream;
|
2017-10-26 08:46:22 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-04-20 22:34:12 +00:00
|
|
|
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.
|
|
|
|
*/
|
2019-04-21 16:30:02 +00:00
|
|
|
class PlaylistArchiveStreamTest extends BaseTest
|
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()
|
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
parent::setUp();
|
2019-04-20 22:34:12 +00:00
|
|
|
|
2019-04-21 16:30:02 +00:00
|
|
|
$video = new Video('https://www.youtube.com/playlist?list=PL1j4Ff8cAqPu5iowaeUAY8lRgkfT4RybJ');
|
2019-04-20 22:34:12 +00:00
|
|
|
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->stream = new PlaylistArchiveStream($video);
|
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()
|
|
|
|
{
|
2019-04-20 22:34:12 +00:00
|
|
|
$this->stream->close();
|
2019-04-19 22:37:49 +00:00
|
|
|
}
|
|
|
|
|
2017-05-02 15:04:55 +00:00
|
|
|
/**
|
2019-04-20 22:34:12 +00:00
|
|
|
* Test the write() function.
|
2017-05-02 15:04:55 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-04-20 22:34:12 +00:00
|
|
|
public function testWrite()
|
2017-05-02 15:04:55 +00:00
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->assertNull($this->stream->write('foo'));
|
2017-05-02 15:04:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-20 22:34:12 +00:00
|
|
|
* Test the tell() function.
|
2017-05-02 15:04:55 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-04-20 22:34:12 +00:00
|
|
|
public function testTell()
|
2017-05-02 15:04:55 +00:00
|
|
|
{
|
2019-04-20 22:34:12 +00:00
|
|
|
$this->assertInternalType('int', $this->stream->tell());
|
2017-05-02 15:04:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-20 22:34:12 +00:00
|
|
|
* Test the seek() function.
|
2017-05-02 15:04:55 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-04-20 22:34:12 +00:00
|
|
|
public function testSeek()
|
2017-05-02 15:04:55 +00:00
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->stream->write('foobar');
|
|
|
|
$this->stream->seek(3);
|
|
|
|
$this->assertEquals(3, $this->stream->tell());
|
2017-05-02 15:04:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-20 22:34:12 +00:00
|
|
|
* Test the read() function.
|
2017-05-02 15:04:55 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-04-20 22:34:12 +00:00
|
|
|
public function testRead()
|
2017-05-02 15:04:55 +00:00
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
$result = $this->stream->read(8192);
|
|
|
|
$this->assertInternalType('string', $result);
|
|
|
|
$this->assertLessThanOrEqual(8192, strlen($result));
|
2017-05-02 15:04:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-20 22:34:12 +00:00
|
|
|
* Test the eof() function.
|
2017-05-02 15:04:55 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-04-20 22:34:12 +00:00
|
|
|
public function testEof()
|
2017-05-02 15:04:55 +00:00
|
|
|
{
|
2019-04-20 22:34:12 +00:00
|
|
|
$this->assertFalse($this->stream->eof());
|
2017-05-02 15:04:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-20 22:34:12 +00:00
|
|
|
* Test the getSize() function.
|
2017-05-02 15:04:55 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-04-20 22:34:12 +00:00
|
|
|
public function testGetSize()
|
2017-05-02 15:04:55 +00:00
|
|
|
{
|
2019-04-20 22:34:12 +00:00
|
|
|
$this->assertNull($this->stream->getSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the isSeekable() function.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testIsSeekable()
|
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->assertTrue($this->stream->isSeekable());
|
2019-04-20 22:34:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the rewind() function.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRewind()
|
|
|
|
{
|
|
|
|
$this->stream->rewind();
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->assertEquals(0, $this->stream->tell());
|
2019-04-20 22:34:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the isWritable() function.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testIsWritable()
|
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->assertTrue($this->stream->isWritable());
|
2019-04-20 22:34:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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()
|
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->assertInternalType('array', $this->stream->getMetadata());
|
2019-04-20 22:34:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the detach() function.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDetach()
|
|
|
|
{
|
|
|
|
$this->assertInternalType('resource', $this->stream->detach());
|
2017-05-02 15:04:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-20 22:34:12 +00:00
|
|
|
* Test the __toString() function.
|
2017-05-02 15:04:55 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-04-20 22:34:12 +00:00
|
|
|
public function testToString()
|
2017-05-02 15:04:55 +00:00
|
|
|
{
|
2019-04-20 22:34:12 +00:00
|
|
|
$this->assertInternalType('string', $this->stream->__toString());
|
|
|
|
$this->assertInternalType('string', (string) $this->stream);
|
2017-05-02 15:04:55 +00:00
|
|
|
}
|
|
|
|
}
|