From db5f653e2d07851422fee3ad8c346068f58af207 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Wed, 26 Apr 2017 00:08:35 +0200 Subject: [PATCH] Refactor stream tests --- tests/VideoDownloadTest.php | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/tests/VideoDownloadTest.php b/tests/VideoDownloadTest.php index d9bda2c..48e094d 100644 --- a/tests/VideoDownloadTest.php +++ b/tests/VideoDownloadTest.php @@ -398,6 +398,19 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase $this->download->getAudioStream($url, $format); } + /** + * Assert that a stream is valid + * + * @param resource $stream Stream + * + * @return void + */ + private function assertStream($stream) + { + $this->assertInternalType('resource', $stream); + $this->assertFalse(feof($stream)); + } + /** * Test getM3uStream function. * @@ -409,10 +422,11 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase */ public function testGetM3uStream($url, $format) { - $video = $this->download->getJSON($url, $format); - $stream = $this->download->getM3uStream($video); - $this->assertInternalType('resource', $stream); - $this->assertFalse(feof($stream)); + $this->assertStream( + $this->download->getM3uStream( + $this->download->getJSON($url, $format) + ) + ); } /** @@ -428,9 +442,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase { $urls = $this->download->getURL($url, $format); if (count($urls) > 1) { - $stream = $this->download->getRemuxStream($urls); - $this->assertInternalType('resource', $stream); - $this->assertFalse(feof($stream)); + $this->assertStream($this->download->getRemuxStream($urls)); } } @@ -445,10 +457,11 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase */ public function testGetRtmpStream($url, $format) { - $video = $this->download->getJSON($url, $format); - $stream = $this->download->getRtmpStream($video); - $this->assertInternalType('resource', $stream); - $this->assertFalse(feof($stream)); + $this->assertStream( + $this->download->getRtmpStream( + $this->download->getJSON($url, $format) + ) + ); } /**