alltube/tests/VideoStubsTest.php

106 lines
2.2 KiB
PHP
Raw Normal View History

<?php
/**
* VideoStubsTest class.
*/
namespace Alltube\Test;
use Alltube\Video;
use Mockery;
use phpmock\mockery\PHPMockery;
2019-11-30 13:08:18 +00:00
use Exception;
/**
* Unit tests for the Video class.
* They are in a separate file so they can safely replace PHP functions with stubs.
*/
class VideoStubsTest extends BaseTest
{
/**
* Video URL used in many tests.
*
* @var Video
*/
private $video;
/**
* Initialize properties used by test.
*/
2019-11-30 13:08:18 +00:00
protected function setUp(): void
{
parent::setUp();
PHPMockery::mock('Alltube', 'popen');
PHPMockery::mock('Alltube', 'fopen');
$this->video = new Video('https://www.youtube.com/watch?v=XJC9_JkzugE');
}
/**
* Remove stubs.
*
* @return void
*/
2019-11-30 13:08:18 +00:00
protected function tearDown(): void
{
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);
$this->video->getAudioStream();
}
/**
* Test getM3uStream function with a buggy popen.
*
* @return void
*/
public function testGetM3uStreamWithPopenError()
{
2019-11-30 13:08:18 +00:00
$this->expectException(Exception::class);
$this->video->getM3uStream();
}
/**
* Test getRtmpStream function with a buggy popen.
*
* @return void
*/
public function testGetRtmpStreamWithPopenError()
{
2019-11-30 13:08:18 +00:00
$this->expectException(Exception::class);
$this->video->getRtmpStream();
}
/**
* Test getRemuxStream function with a buggy popen.
*
* @return void
*/
public function testGetRemuxStreamWithPopenError()
{
2019-11-30 13:08:18 +00:00
$this->expectException(Exception::class);
$video = $this->video->withFormat('bestvideo+bestaudio');
$video->getRemuxStream();
}
/**
* Test getConvertedStream function with a buggy popen.
*
* @return void
*/
public function testGetConvertedStreamWithPopenError()
{
2019-11-30 13:08:18 +00:00
$this->expectException(Exception::class);
$this->video->getConvertedStream(32, 'flv');
}
}