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;
|
|
|
|
|
2019-04-21 16:30:02 +00:00
|
|
|
use Alltube\Video;
|
2017-12-05 18:42:57 +00:00
|
|
|
use Mockery;
|
|
|
|
use phpmock\mockery\PHPMockery;
|
2019-11-30 13:08:18 +00:00
|
|
|
use Exception;
|
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.
|
|
|
|
*/
|
2019-04-21 16:30:02 +00:00
|
|
|
class VideoStubsTest extends BaseTest
|
2017-12-05 18:42:57 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Video URL used in many tests.
|
|
|
|
*
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize properties used by test.
|
|
|
|
*/
|
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();
|
|
|
|
|
2017-12-05 18:42:57 +00:00
|
|
|
PHPMockery::mock('Alltube', 'popen');
|
|
|
|
PHPMockery::mock('Alltube', 'fopen');
|
|
|
|
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->video = new Video('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
|
|
|
{
|
|
|
|
Mockery::close();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test getAudioStream function with a buggy popen.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetAudioStreamWithPopenError()
|
|
|
|
{
|
2019-11-30 13:08:18 +00:00
|
|
|
$this->expectException(Exception::class);
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->video->getAudioStream();
|
2017-12-05 18:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test getM3uStream function with a buggy popen.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetM3uStreamWithPopenError()
|
|
|
|
{
|
2019-11-30 13:08:18 +00:00
|
|
|
$this->expectException(Exception::class);
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->video->getM3uStream();
|
2017-12-05 18:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test getRtmpStream function with a buggy popen.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetRtmpStreamWithPopenError()
|
|
|
|
{
|
2019-11-30 13:08:18 +00:00
|
|
|
$this->expectException(Exception::class);
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->video->getRtmpStream();
|
2017-12-05 18:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test getRemuxStream function with a buggy popen.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetRemuxStreamWithPopenError()
|
|
|
|
{
|
2019-11-30 13:08:18 +00:00
|
|
|
$this->expectException(Exception::class);
|
2019-04-21 16:30:02 +00:00
|
|
|
$video = $this->video->withFormat('bestvideo+bestaudio');
|
|
|
|
$video->getRemuxStream();
|
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
|
|
|
|
*/
|
|
|
|
public function testGetConvertedStreamWithPopenError()
|
|
|
|
{
|
2019-11-30 13:08:18 +00:00
|
|
|
$this->expectException(Exception::class);
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->video->getConvertedStream(32, 'flv');
|
2018-01-24 22:30:24 +00:00
|
|
|
}
|
2017-12-05 18:42:57 +00:00
|
|
|
}
|