New tests

This commit is contained in:
Pierre Rudloff 2016-07-30 00:47:46 +02:00
parent 26388ea1b4
commit e3cec201ee
4 changed files with 92 additions and 6 deletions

View file

@ -131,7 +131,7 @@ class VideoDownload
if (!$process->isSuccessful()) {
throw new \Exception($process->getErrorOutput());
} else {
return $process->getOutput();
return trim($process->getOutput());
}
}
@ -147,7 +147,7 @@ class VideoDownload
);
}
public function getConversionProcess($url, $format)
public function getAudioStream($url, $format)
{
if (!shell_exec('which '.$this->config->avconv)) {
throw(new \Exception('Can\'t find avconv or ffmpeg'));

View file

@ -129,7 +129,7 @@ class FrontController
$response = $response->withHeader('Content-Type', 'audio/mpeg');
if ($request->isGet()) {
$process = $this->download->getConversionProcess($params["url"], 'bestaudio/best');
$process = $this->download->getAudioStream($params["url"], 'bestaudio/best');
$response = $response->withBody(new Stream($process));
}
return $response;

View file

@ -38,5 +38,11 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
putenv('CONVERT=1');
$config = Config::getInstance();
$this->assertEquals($config->convert, true);
$this->assertInternalType('array', $config->curl_params);
$this->assertInternalType('array', $config->params);
$this->assertInternalType('string', $config->youtubedl);
$this->assertInternalType('string', $config->python);
$this->assertInternalType('string', $config->avconv);
$this->assertInternalType('string', $config->rtmpdump);
}
}

View file

@ -83,18 +83,22 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
array(
'https://www.youtube.com/watch?v=M7IpKCZ47pU', null,
"It's Not Me, It's You - Hearts Under Fire-M7IpKCZ47pU.mp4",
'googlevideo.com'
'googlevideo.com',
"It's Not Me, It's You - Hearts Under Fire-M7IpKCZ47pU.mp3"
),
array(
'https://www.youtube.com/watch?v=RJJ6FCAXvKg', 22,
"'Heart Attack' - Demi Lovato ".
"(Sam Tsui & Against The Current)-RJJ6FCAXvKg.mp4",
'googlevideo.com'
'googlevideo.com',
"'Heart Attack' - Demi Lovato ".
"(Sam Tsui & Against The Current)-RJJ6FCAXvKg.mp3"
),
array(
'https://vimeo.com/24195442', null,
"Carving the Mountains-24195442.mp4",
'vimeocdn.com'
'vimeocdn.com',
"Carving the Mountains-24195442.mp3"
),
);
}
@ -144,4 +148,80 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
{
$videoURL = $this->download->getJSON($url);
}
/**
* Test getFilename function
*
* @param string $url URL
* @param string $format Format
*
* @return void
* @dataProvider urlProvider
*/
public function testGetFilename($url, $format, $filename)
{
$videoFilename = $this->download->getFilename($url, $format);
$this->assertEquals($videoFilename, $filename);
}
/**
* Test getFilename function errors
*
* @param string $url URL
*
* @return void
* @expectedException Exception
* @dataProvider ErrorUrlProvider
*/
public function testGetFilenameError($url)
{
$this->download->getFilename($url);
}
/**
* Test getAudioFilename function
*
* @param string $url URL
* @param string $format Format
*
* @return void
* @dataProvider urlProvider
*/
public function testGetAudioFilename($url, $format, $filename, $domain, $audioFilename)
{
$videoFilename = $this->download->getAudioFilename($url, $format);
$this->assertEquals($videoFilename, $audioFilename);
}
/**
* Test getAudioStream function
*
* @param string $url URL
* @param string $format Format
*
* @return void
* @dataProvider urlProvider
*/
public function testGetAudioStream($url, $format)
{
$process = $this->download->getAudioStream($url, $format);
$this->assertInternalType('resource', $process);
}
/**
* Test getAudioStream function
*
* @param string $url URL
* @param string $format Format
*
* @return void
* @expectedException Exception
* @dataProvider urlProvider
*/
public function testGetAudioStreamAvconvError($url, $format)
{
$config = \Alltube\Config::getInstance();
$config->avconv = 'foobar';
$this->download->getAudioStream($url, $format);
}
}