alltube/tests/PlaylistArchiveStreamTest.php

191 lines
3.6 KiB
PHP
Raw Normal View History

2017-05-02 15:04:55 +00:00
<?php
/**
* PlaylistArchiveStreamTest class.
*/
namespace Alltube\Test;
use Alltube\PlaylistArchiveStream;
2019-04-21 16:35:24 +00:00
use Alltube\Video;
2017-05-02 15:04:55 +00:00
/**
* Unit tests for the ViewFactory class.
*/
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()
{
parent::setUp();
$video = new Video('https://www.youtube.com/playlist?list=PL1j4Ff8cAqPu5iowaeUAY8lRgkfT4RybJ');
$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()
{
$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
*/
public function testWrite()
2017-05-02 15:04:55 +00:00
{
$this->assertNull($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
*/
public function testSeek()
2017-05-02 15:04:55 +00:00
{
$this->stream->write('foobar');
$this->stream->seek(3);
$this->assertEquals(3, $this->stream->tell());
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
{
$result = $this->stream->read(8192);
$this->assertInternalType('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->assertTrue($this->stream->isSeekable());
}
/**
* Test the rewind() function.
*
* @return void
*/
public function testRewind()
{
$this->stream->rewind();
$this->assertEquals(0, $this->stream->tell());
}
/**
* Test the isWritable() function.
*
* @return void
*/
public function testIsWritable()
{
$this->assertTrue($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->assertInternalType('array', $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
}
}