alltube/tests/VideoStubsTest.php
Pierre Rudloff 5c2823e3f1 Move Video class to a separate library
+ improve error handling
+ youtube-dl update
2020-06-21 15:12:03 +02:00

126 lines
3 KiB
PHP

<?php
/**
* VideoStubsTest class.
*/
namespace Alltube\Test;
use Alltube\Config;
use Alltube\Exception\ConfigException;
use Alltube\Library\Downloader;
use Alltube\Library\Exception\AlltubeLibraryException;
use Alltube\Library\Exception\PopenStreamException;
use Alltube\Library\Video;
use Mockery;
use phpmock\mockery\PHPMockery;
/**
* Unit tests for the Video class.
* They are in a separate file so they can safely replace PHP functions with stubs.
*
* @requires download
*/
class VideoStubsTest extends BaseTest
{
/**
* Video used in many tests.
*
* @var Video
*/
private $video;
/**
* Downloader instance used in tests.
*
* @var Downloader
*/
private $downloader;
/**
* Initialize properties used by test.
* @throws ConfigException
*/
protected function setUp(): void
{
parent::setUp();
PHPMockery::mock('Alltube\Library', 'popen');
PHPMockery::mock('Alltube\Library', 'fopen');
$config = Config::getInstance();
$this->downloader = $config->getDownloader();
$this->video = $this->downloader->getVideo('https://www.youtube.com/watch?v=XJC9_JkzugE');
}
/**
* Remove stubs.
*
* @return void
*/
protected function tearDown(): void
{
Mockery::close();
}
/**
* Test getAudioStream function with a buggy popen.
*
* @return void
* @throws AlltubeLibraryException
*/
public function testGetAudioStreamWithPopenError()
{
$this->expectException(PopenStreamException::class);
$this->downloader->getAudioStream($this->video);
}
/**
* Test getM3uStream function with a buggy popen.
*
* @return void
* @throws AlltubeLibraryException
*/
public function testGetM3uStreamWithPopenError()
{
$this->expectException(PopenStreamException::class);
$this->downloader->getM3uStream($this->video);
}
/**
* Test getRtmpStream function with a buggy popen.
*
* @return void
* @throws AlltubeLibraryException
*/
public function testGetRtmpStreamWithPopenError()
{
$this->expectException(PopenStreamException::class);
$this->downloader->getRtmpStream($this->video);
}
/**
* Test getRemuxStream function with a buggy popen.
*
* @return void
* @throws AlltubeLibraryException
*/
public function testGetRemuxStreamWithPopenError()
{
$this->expectException(PopenStreamException::class);
$video = $this->video->withFormat('bestvideo+bestaudio');
$this->downloader->getRemuxStream($video);
}
/**
* Test getConvertedStream function with a buggy popen.
*
* @return void
* @throws AlltubeLibraryException
*/
public function testGetConvertedStreamWithPopenError()
{
$this->expectException(PopenStreamException::class);
$this->downloader->getConvertedStream($this->video, 32, 'flv');
}
}