2017-12-05 18:42:57 +00:00
|
|
|
<?php
|
2019-10-03 19:24:12 +00:00
|
|
|
|
2017-12-05 18:42:57 +00:00
|
|
|
/**
|
2019-04-21 16:30:02 +00:00
|
|
|
* VideoStubsTest class.
|
2017-12-05 18:42:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Alltube\Test;
|
|
|
|
|
2020-10-22 20:39:09 +00:00
|
|
|
use Alltube\Exception\ConfigException;
|
|
|
|
use Alltube\Exception\DependencyException;
|
2020-06-20 23:44:20 +00:00
|
|
|
use Alltube\Library\Downloader;
|
|
|
|
use Alltube\Library\Exception\AlltubeLibraryException;
|
|
|
|
use Alltube\Library\Exception\PopenStreamException;
|
|
|
|
use Alltube\Library\Video;
|
2017-12-05 18:42:57 +00:00
|
|
|
use Mockery;
|
|
|
|
use phpmock\mockery\PHPMockery;
|
2020-10-22 20:39:09 +00:00
|
|
|
use SmartyException;
|
2017-12-05 18:42:57 +00:00
|
|
|
|
|
|
|
/**
|
2019-04-21 16:30:02 +00:00
|
|
|
* Unit tests for the Video class.
|
2017-12-05 18:42:57 +00:00
|
|
|
* They are in a separate file so they can safely replace PHP functions with stubs.
|
2020-06-20 23:44:20 +00:00
|
|
|
*
|
|
|
|
* @requires download
|
2017-12-05 18:42:57 +00:00
|
|
|
*/
|
2020-10-22 20:39:09 +00:00
|
|
|
class VideoStubsTest extends ContainerTest
|
2017-12-05 18:42:57 +00:00
|
|
|
{
|
|
|
|
/**
|
2020-06-20 23:44:20 +00:00
|
|
|
* Video used in many tests.
|
2017-12-05 18:42:57 +00:00
|
|
|
*
|
2019-04-21 16:30:02 +00:00
|
|
|
* @var Video
|
2017-12-05 18:42:57 +00:00
|
|
|
*/
|
2019-04-21 16:30:02 +00:00
|
|
|
private $video;
|
2017-12-05 18:42:57 +00:00
|
|
|
|
2020-06-20 23:44:20 +00:00
|
|
|
/**
|
|
|
|
* Downloader instance used in tests.
|
|
|
|
*
|
|
|
|
* @var Downloader
|
|
|
|
*/
|
|
|
|
private $downloader;
|
|
|
|
|
2017-12-05 18:42:57 +00:00
|
|
|
/**
|
|
|
|
* Initialize properties used by test.
|
2020-10-22 20:39:09 +00:00
|
|
|
*
|
|
|
|
* @throws ConfigException
|
|
|
|
* @throws DependencyException
|
|
|
|
* @throws SmartyException
|
2017-12-05 18:42:57 +00:00
|
|
|
*/
|
2019-11-30 13:08:18 +00:00
|
|
|
protected function setUp(): void
|
2017-12-05 18:42:57 +00:00
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
2020-06-20 23:44:20 +00:00
|
|
|
PHPMockery::mock('Alltube\Library', 'popen');
|
|
|
|
PHPMockery::mock('Alltube\Library', 'fopen');
|
2017-12-05 18:42:57 +00:00
|
|
|
|
2020-10-22 20:39:09 +00:00
|
|
|
$this->downloader = $this->container->get('config')->getDownloader();
|
2020-06-20 23:44:20 +00:00
|
|
|
$this->video = $this->downloader->getVideo('https://www.youtube.com/watch?v=XJC9_JkzugE');
|
2017-12-05 18:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove stubs.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-11-30 13:08:18 +00:00
|
|
|
protected function tearDown(): void
|
2017-12-05 18:42:57 +00:00
|
|
|
{
|
2020-10-22 20:39:09 +00:00
|
|
|
parent::tearDown();
|
|
|
|
|
2017-12-05 18:42:57 +00:00
|
|
|
Mockery::close();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test getAudioStream function with a buggy popen.
|
|
|
|
*
|
|
|
|
* @return void
|
2020-06-20 23:44:20 +00:00
|
|
|
* @throws AlltubeLibraryException
|
2017-12-05 18:42:57 +00:00
|
|
|
*/
|
|
|
|
public function testGetAudioStreamWithPopenError()
|
|
|
|
{
|
2020-06-20 23:44:20 +00:00
|
|
|
$this->expectException(PopenStreamException::class);
|
|
|
|
$this->downloader->getAudioStream($this->video);
|
2017-12-05 18:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test getM3uStream function with a buggy popen.
|
|
|
|
*
|
|
|
|
* @return void
|
2020-06-20 23:44:20 +00:00
|
|
|
* @throws AlltubeLibraryException
|
2017-12-05 18:42:57 +00:00
|
|
|
*/
|
|
|
|
public function testGetM3uStreamWithPopenError()
|
|
|
|
{
|
2020-06-20 23:44:20 +00:00
|
|
|
$this->expectException(PopenStreamException::class);
|
|
|
|
$this->downloader->getM3uStream($this->video);
|
2017-12-05 18:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test getRtmpStream function with a buggy popen.
|
|
|
|
*
|
|
|
|
* @return void
|
2020-06-20 23:44:20 +00:00
|
|
|
* @throws AlltubeLibraryException
|
2017-12-05 18:42:57 +00:00
|
|
|
*/
|
|
|
|
public function testGetRtmpStreamWithPopenError()
|
|
|
|
{
|
2020-06-20 23:44:20 +00:00
|
|
|
$this->expectException(PopenStreamException::class);
|
|
|
|
$this->downloader->getRtmpStream($this->video);
|
2017-12-05 18:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test getRemuxStream function with a buggy popen.
|
|
|
|
*
|
|
|
|
* @return void
|
2020-06-20 23:44:20 +00:00
|
|
|
* @throws AlltubeLibraryException
|
2017-12-05 18:42:57 +00:00
|
|
|
*/
|
|
|
|
public function testGetRemuxStreamWithPopenError()
|
|
|
|
{
|
2020-06-20 23:44:20 +00:00
|
|
|
$this->expectException(PopenStreamException::class);
|
2019-04-21 16:30:02 +00:00
|
|
|
$video = $this->video->withFormat('bestvideo+bestaudio');
|
2020-06-20 23:44:20 +00:00
|
|
|
$this->downloader->getRemuxStream($video);
|
2017-12-05 18:42:57 +00:00
|
|
|
}
|
|
|
|
|
2018-01-24 22:30:24 +00:00
|
|
|
/**
|
|
|
|
* Test getConvertedStream function with a buggy popen.
|
|
|
|
*
|
|
|
|
* @return void
|
2020-06-20 23:44:20 +00:00
|
|
|
* @throws AlltubeLibraryException
|
2018-01-24 22:30:24 +00:00
|
|
|
*/
|
|
|
|
public function testGetConvertedStreamWithPopenError()
|
|
|
|
{
|
2020-06-20 23:44:20 +00:00
|
|
|
$this->expectException(PopenStreamException::class);
|
|
|
|
$this->downloader->getConvertedStream($this->video, 32, 'flv');
|
2018-01-24 22:30:24 +00:00
|
|
|
}
|
2017-12-05 18:42:57 +00:00
|
|
|
}
|