From f14bec35ea4ecdb7d0bc8e19a2fd5ded29701993 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Fri, 8 Apr 2016 20:08:04 +0200 Subject: [PATCH] getURL() should not return an array --- classes/VideoDownload.php | 4 ++-- controllers/FrontController.php | 4 ++-- tests/VideoDownloadTest.php | 16 +++++++++------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/classes/VideoDownload.php b/classes/VideoDownload.php index 5803b9f..8643207 100644 --- a/classes/VideoDownload.php +++ b/classes/VideoDownload.php @@ -104,7 +104,7 @@ class VideoDownload * @param string $url URL of page * @param string $format Format to use for the video * - * @return string JSON + * @return object Decoded JSON * */ public function getJSON($url, $format = null) { @@ -150,7 +150,7 @@ class VideoDownload if (!$process->isSuccessful()) { throw new \Exception($process->getErrorOutput()); } else { - return array('success'=>true, 'url'=>$process->getOutput()); + return $process->getOutput(); } } diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 0f5846a..29778c4 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -225,8 +225,8 @@ class FrontController global $app; if (isset($_GET["url"])) { try { - $video = $this->download->getURL($_GET["url"]); - return $response->withRedirect($video['url']); + $url = $this->download->getURL($_GET["url"]); + return $response->withRedirect($url); } catch (\Exception $e) { echo $e->getMessage().PHP_EOL; return $response->withHeader('Content-Type', 'text/plain'); diff --git a/tests/VideoDownloadTest.php b/tests/VideoDownloadTest.php index 35b632d..d137735 100644 --- a/tests/VideoDownloadTest.php +++ b/tests/VideoDownloadTest.php @@ -62,11 +62,10 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase * @return void * @dataProvider urlProvider */ - public function testGetURL($url, $format) + public function testGetURL($url, $format, $filename, $domain) { $videoURL = $this->download->getURL($url, $format); - $this->assertArrayHasKey('success', $videoURL); - $this->assertArrayHasKey('url', $videoURL); + $this->assertContains($domain, $videoURL); } /** @@ -80,7 +79,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase */ public function testGetURLError($url) { - $videoURL = $this->download->getURL($url); + $this->download->getURL($url); } /** @@ -93,16 +92,19 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase return array( array( 'https://www.youtube.com/watch?v=M7IpKCZ47pU', null, - "It's Not Me, It's You - Hearts Under Fire-M7IpKCZ47pU.mp4" + "It's Not Me, It's You - Hearts Under Fire-M7IpKCZ47pU.mp4", + 'googlevideo.com' ), array( 'https://www.youtube.com/watch?v=RJJ6FCAXvKg', 22, "'Heart Attack' - Demi Lovato ". - "(Sam Tsui & Against The Current)-RJJ6FCAXvKg.mp4" + "(Sam Tsui & Against The Current)-RJJ6FCAXvKg.mp4", + 'googlevideo.com' ), array( 'https://vimeo.com/24195442', null, - "Carving the Mountains-24195442.mp4" + "Carving the Mountains-24195442.mp4", + 'vimeocdn.com' ), ); }