From d581621f1be2b16f49f1a0458ee7188c06c79d25 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 5 Dec 2017 19:42:57 +0100 Subject: [PATCH] Throw an exception when a popen stream is not created correctly --- composer.json | 6 +- composer.lock | 645 ++++++++++++++++--------------- tests/VideoDownloadStubsTest.php | 127 ++++++ tests/bootstrap.php | 2 +- 4 files changed, 455 insertions(+), 325 deletions(-) create mode 100644 tests/VideoDownloadStubsTest.php diff --git a/composer.json b/composer.json index 1ab082c..b612982 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ "barracudanetworks/archivestream-php": "~1.0.5", "smarty-gettext/smarty-gettext": "~1.5.1", "zonuexe/http-accept-language": "~0.4.1", - "rinvex/country": "~3.1.0" + "rinvex/country": "~3.1.0", + "php-mock/php-mock-mockery": "~1.2.0" }, "require-dev": { "symfony/var-dumper": "~3.3.9", @@ -25,8 +26,7 @@ "ffmpeg/ffmpeg": "dev-release", "rg3/youtube-dl": "2017.11.06", "rudloff/rtmpdump-bin": "~2.3.0", - "heroku/heroku-buildpack-php": "*", - "php-mock/php-mock-mockery": "~1.1.0" + "heroku/heroku-buildpack-php": "*" }, "extra": { "paas": { diff --git a/composer.lock b/composer.lock index f9fe3ba..ccce1b1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "195cbc39a8ad0fbd9ed135f6c81944a9", + "content-hash": "211f5fdec300d8764b22ea63c0912750", "packages": [ { "name": "aura/session", @@ -320,6 +320,54 @@ ], "time": "2017-03-20T17:10:46+00:00" }, + { + "name": "hamcrest/hamcrest-php", + "version": "v2.0.0", + "source": { + "type": "git", + "url": "https://github.com/hamcrest/hamcrest-php.git", + "reference": "776503d3a8e85d4f9a1148614f95b7a608b046ad" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/776503d3a8e85d4f9a1148614f95b7a608b046ad", + "reference": "776503d3a8e85d4f9a1148614f95b7a608b046ad", + "shasum": "" + }, + "require": { + "php": "^5.3|^7.0" + }, + "replace": { + "cordoval/hamcrest-php": "*", + "davedevelopment/hamcrest-php": "*", + "kodova/hamcrest-php": "*" + }, + "require-dev": { + "phpunit/php-file-iterator": "1.3.3", + "phpunit/phpunit": "~4.0", + "satooshi/php-coveralls": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "hamcrest" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD" + ], + "description": "This is the PHP port of Hamcrest Matchers", + "keywords": [ + "test" + ], + "time": "2016-01-20T08:20:44+00:00" + }, { "name": "mathmarques/smarty-view", "version": "1.1.1", @@ -370,6 +418,71 @@ ], "time": "2016-08-25T19:04:49+00:00" }, + { + "name": "mockery/mockery", + "version": "1.0", + "source": { + "type": "git", + "url": "https://github.com/mockery/mockery.git", + "reference": "1bac8c362b12f522fdd1f1fa3556284c91affa38" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/mockery/mockery/zipball/1bac8c362b12f522fdd1f1fa3556284c91affa38", + "reference": "1bac8c362b12f522fdd1f1fa3556284c91affa38", + "shasum": "" + }, + "require": { + "hamcrest/hamcrest-php": "~2.0", + "lib-pcre": ">=7.0", + "php": ">=5.6.0" + }, + "require-dev": { + "phpunit/phpunit": "~5.7|~6.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Mockery": "library/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Pádraic Brady", + "email": "padraic.brady@gmail.com", + "homepage": "http://blog.astrumfutura.com" + }, + { + "name": "Dave Marshall", + "email": "dave.marshall@atstsolutions.co.uk", + "homepage": "http://davedevelopment.co.uk" + } + ], + "description": "Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library, Mockery is easy to integrate with PHPUnit and can operate alongside phpunit-mock-objects without the World ending.", + "homepage": "http://github.com/mockery/mockery", + "keywords": [ + "BDD", + "TDD", + "library", + "mock", + "mock objects", + "mockery", + "stub", + "test", + "test double", + "testing" + ], + "time": "2017-10-06T16:20:43+00:00" + }, { "name": "nikic/fast-route", "version": "v1.2.0", @@ -413,6 +526,216 @@ ], "time": "2017-01-19T11:35:12+00:00" }, + { + "name": "php-mock/php-mock", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-mock/php-mock.git", + "reference": "bfa2d17d64dbf129073a7ba2051a96ce52749570" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-mock/php-mock/zipball/bfa2d17d64dbf129073a7ba2051a96ce52749570", + "reference": "bfa2d17d64dbf129073a7ba2051a96ce52749570", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpunit/php-text-template": "^1" + }, + "replace": { + "malkusch/php-mock": "*" + }, + "require-dev": { + "phpunit/phpunit": "^4|^5" + }, + "suggest": { + "php-mock/php-mock-mockery": "Allows using PHPMockery for Mockery integration", + "php-mock/php-mock-phpunit": "Allows integration into PHPUnit testcase with the trait PHPMock." + }, + "type": "library", + "autoload": { + "psr-4": { + "phpmock\\": [ + "classes/", + "tests/unit/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "WTFPL" + ], + "authors": [ + { + "name": "Markus Malkusch", + "email": "markus@malkusch.de", + "homepage": "http://markus.malkusch.de", + "role": "Developer" + } + ], + "description": "PHP-Mock can mock built-in PHP functions (e.g. time()). PHP-Mock relies on PHP's namespace fallback policy. No further extension is needed.", + "homepage": "https://github.com/php-mock/php-mock", + "keywords": [ + "BDD", + "TDD", + "function", + "mock", + "stub", + "test", + "test double" + ], + "time": "2015-11-11T22:37:09+00:00" + }, + { + "name": "php-mock/php-mock-integration", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-mock/php-mock-integration.git", + "reference": "e83fb65dd20cd3cf250d554cbd4682b96b684f4b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-mock/php-mock-integration/zipball/e83fb65dd20cd3cf250d554cbd4682b96b684f4b", + "reference": "e83fb65dd20cd3cf250d554cbd4682b96b684f4b", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "php-mock/php-mock": "^1", + "phpunit/php-text-template": "^1" + }, + "require-dev": { + "phpunit/phpunit": "^4|^5" + }, + "type": "library", + "autoload": { + "psr-4": { + "phpmock\\integration\\": "classes/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "WTFPL" + ], + "authors": [ + { + "name": "Markus Malkusch", + "email": "markus@malkusch.de", + "homepage": "http://markus.malkusch.de", + "role": "Developer" + } + ], + "description": "Integration package for PHP-Mock", + "homepage": "https://github.com/php-mock/php-mock-integration", + "keywords": [ + "BDD", + "TDD", + "function", + "mock", + "stub", + "test", + "test double" + ], + "time": "2015-10-26T21:21:42+00:00" + }, + { + "name": "php-mock/php-mock-mockery", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/php-mock/php-mock-mockery.git", + "reference": "f3d67a36558c6d1fb912ed8ba786fffaf94e0755" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-mock/php-mock-mockery/zipball/f3d67a36558c6d1fb912ed8ba786fffaf94e0755", + "reference": "f3d67a36558c6d1fb912ed8ba786fffaf94e0755", + "shasum": "" + }, + "require": { + "mockery/mockery": "^1", + "php": ">=5.6", + "php-mock/php-mock-integration": "^1" + }, + "require-dev": { + "phpunit/phpunit": "^4|^5" + }, + "type": "library", + "autoload": { + "psr-4": { + "phpmock\\mockery\\": "classes/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "WTFPL" + ], + "authors": [ + { + "name": "Markus Malkusch", + "email": "markus@malkusch.de", + "homepage": "http://markus.malkusch.de", + "role": "Developer" + } + ], + "description": "Mock built-in PHP functions (e.g. time()) with Mockery. This package relies on PHP's namespace fallback policy. No further extension is needed.", + "homepage": "https://github.com/php-mock/php-mock-mockery", + "keywords": [ + "BDD", + "TDD", + "function", + "mock", + "mockery", + "stub", + "test", + "test double" + ], + "time": "2017-10-13T09:34:01+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2015-06-21T13:50:34+00:00" + }, { "name": "pimple/pimple", "version": "v3.2.2", @@ -1065,51 +1388,6 @@ ], "type": "library" }, - { - "name": "hamcrest/hamcrest-php", - "version": "v1.2.2", - "source": { - "type": "git", - "url": "https://github.com/hamcrest/hamcrest-php.git", - "reference": "b37020aa976fa52d3de9aa904aa2522dc518f79c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/b37020aa976fa52d3de9aa904aa2522dc518f79c", - "reference": "b37020aa976fa52d3de9aa904aa2522dc518f79c", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "replace": { - "cordoval/hamcrest-php": "*", - "davedevelopment/hamcrest-php": "*", - "kodova/hamcrest-php": "*" - }, - "require-dev": { - "phpunit/php-file-iterator": "1.3.3", - "satooshi/php-coveralls": "dev-master" - }, - "type": "library", - "autoload": { - "classmap": [ - "hamcrest" - ], - "files": [ - "hamcrest/Hamcrest.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD" - ], - "description": "This is the PHP port of Hamcrest Matchers", - "keywords": [ - "test" - ], - "time": "2015-05-11T14:41:42+00:00" - }, { "name": "heroku/heroku-buildpack-php", "version": "v127", @@ -1154,71 +1432,6 @@ ], "time": "2017-11-30T16:10:52+00:00" }, - { - "name": "mockery/mockery", - "version": "0.9.9", - "source": { - "type": "git", - "url": "https://github.com/mockery/mockery.git", - "reference": "6fdb61243844dc924071d3404bb23994ea0b6856" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/mockery/mockery/zipball/6fdb61243844dc924071d3404bb23994ea0b6856", - "reference": "6fdb61243844dc924071d3404bb23994ea0b6856", - "shasum": "" - }, - "require": { - "hamcrest/hamcrest-php": "~1.1", - "lib-pcre": ">=7.0", - "php": ">=5.3.2" - }, - "require-dev": { - "phpunit/phpunit": "~4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.9.x-dev" - } - }, - "autoload": { - "psr-0": { - "Mockery": "library/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Pádraic Brady", - "email": "padraic.brady@gmail.com", - "homepage": "http://blog.astrumfutura.com" - }, - { - "name": "Dave Marshall", - "email": "dave.marshall@atstsolutions.co.uk", - "homepage": "http://davedevelopment.co.uk" - } - ], - "description": "Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library, Mockery is easy to integrate with PHPUnit and can operate alongside phpunit-mock-objects without the World ending.", - "homepage": "http://github.com/padraic/mockery", - "keywords": [ - "BDD", - "TDD", - "library", - "mock", - "mock objects", - "mockery", - "stub", - "test", - "test double", - "testing" - ], - "time": "2017-02-28T12:52:32+00:00" - }, { "name": "myclabs/deep-copy", "version": "1.7.0", @@ -1366,175 +1579,6 @@ "description": "Library for handling version information and constraints", "time": "2017-03-05T17:38:23+00:00" }, - { - "name": "php-mock/php-mock", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/php-mock/php-mock.git", - "reference": "bfa2d17d64dbf129073a7ba2051a96ce52749570" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-mock/php-mock/zipball/bfa2d17d64dbf129073a7ba2051a96ce52749570", - "reference": "bfa2d17d64dbf129073a7ba2051a96ce52749570", - "shasum": "" - }, - "require": { - "php": ">=5.5", - "phpunit/php-text-template": "^1" - }, - "replace": { - "malkusch/php-mock": "*" - }, - "require-dev": { - "phpunit/phpunit": "^4|^5" - }, - "suggest": { - "php-mock/php-mock-mockery": "Allows using PHPMockery for Mockery integration", - "php-mock/php-mock-phpunit": "Allows integration into PHPUnit testcase with the trait PHPMock." - }, - "type": "library", - "autoload": { - "psr-4": { - "phpmock\\": [ - "classes/", - "tests/unit/" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "WTFPL" - ], - "authors": [ - { - "name": "Markus Malkusch", - "email": "markus@malkusch.de", - "homepage": "http://markus.malkusch.de", - "role": "Developer" - } - ], - "description": "PHP-Mock can mock built-in PHP functions (e.g. time()). PHP-Mock relies on PHP's namespace fallback policy. No further extension is needed.", - "homepage": "https://github.com/php-mock/php-mock", - "keywords": [ - "BDD", - "TDD", - "function", - "mock", - "stub", - "test", - "test double" - ], - "time": "2015-11-11T22:37:09+00:00" - }, - { - "name": "php-mock/php-mock-integration", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/php-mock/php-mock-integration.git", - "reference": "e83fb65dd20cd3cf250d554cbd4682b96b684f4b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-mock/php-mock-integration/zipball/e83fb65dd20cd3cf250d554cbd4682b96b684f4b", - "reference": "e83fb65dd20cd3cf250d554cbd4682b96b684f4b", - "shasum": "" - }, - "require": { - "php": ">=5.5", - "php-mock/php-mock": "^1", - "phpunit/php-text-template": "^1" - }, - "require-dev": { - "phpunit/phpunit": "^4|^5" - }, - "type": "library", - "autoload": { - "psr-4": { - "phpmock\\integration\\": "classes/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "WTFPL" - ], - "authors": [ - { - "name": "Markus Malkusch", - "email": "markus@malkusch.de", - "homepage": "http://markus.malkusch.de", - "role": "Developer" - } - ], - "description": "Integration package for PHP-Mock", - "homepage": "https://github.com/php-mock/php-mock-integration", - "keywords": [ - "BDD", - "TDD", - "function", - "mock", - "stub", - "test", - "test double" - ], - "time": "2015-10-26T21:21:42+00:00" - }, - { - "name": "php-mock/php-mock-mockery", - "version": "1.1.0", - "source": { - "type": "git", - "url": "https://github.com/php-mock/php-mock-mockery.git", - "reference": "bc1fe0608cd47c939aba5eac1cb50de1cda9cbc3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-mock/php-mock-mockery/zipball/bc1fe0608cd47c939aba5eac1cb50de1cda9cbc3", - "reference": "bc1fe0608cd47c939aba5eac1cb50de1cda9cbc3", - "shasum": "" - }, - "require": { - "mockery/mockery": "^0.9", - "php": ">=5.5", - "php-mock/php-mock-integration": "^1" - }, - "require-dev": { - "phpunit/phpunit": "^4|^5" - }, - "type": "library", - "autoload": { - "psr-4": { - "phpmock\\mockery\\": "classes/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "WTFPL" - ], - "authors": [ - { - "name": "Markus Malkusch", - "email": "markus@malkusch.de", - "homepage": "http://markus.malkusch.de", - "role": "Developer" - } - ], - "description": "Mock built-in PHP functions (e.g. time()) with Mockery. This package relies on PHP's namespace fallback policy. No further extension is needed.", - "homepage": "https://github.com/php-mock/php-mock-mockery", - "keywords": [ - "BDD", - "TDD", - "function", - "mock", - "mockery", - "stub", - "test", - "test double" - ], - "time": "2015-11-11T22:48:58+00:00" - }, { "name": "phpdocumentor/reflection-common", "version": "1.0.1", @@ -1861,47 +1905,6 @@ ], "time": "2017-11-27T13:52:08+00:00" }, - { - "name": "phpunit/php-text-template", - "version": "1.2.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Simple template engine.", - "homepage": "https://github.com/sebastianbergmann/php-text-template/", - "keywords": [ - "template" - ], - "time": "2015-06-21T13:50:34+00:00" - }, { "name": "phpunit/php-timer", "version": "1.0.9", diff --git a/tests/VideoDownloadStubsTest.php b/tests/VideoDownloadStubsTest.php new file mode 100644 index 0000000..8db9d0b --- /dev/null +++ b/tests/VideoDownloadStubsTest.php @@ -0,0 +1,127 @@ +config = Config::getInstance('config/'.$configFile); + $this->download = new VideoDownload($this->config); + $this->url = 'https://www.youtube.com/watch?v=XJC9_JkzugE'; + } + + /** + * Remove stubs. + * + * @return void + */ + protected function tearDown() + { + Mockery::close(); + } + + /** + * Test getAudioStream function with a buggy popen. + * + * @return void + * @expectedException Exception + */ + public function testGetAudioStreamWithPopenError() + { + $this->download->getAudioStream($this->url, 'best'); + } + + /** + * Test getM3uStream function with a buggy popen. + * + * @return void + * @expectedException Exception + */ + public function testGetM3uStreamWithPopenError() + { + $this->download->getM3uStream($this->download->getJSON($this->url, 'best')); + } + + /** + * Test getRtmpStream function with a buggy popen. + * + * @return void + * @expectedException Exception + */ + public function testGetRtmpStreamWithPopenError() + { + $this->download->getRtmpStream($this->download->getJSON($this->url, 'best')); + } + + /** + * Test getRemuxStream function with a buggy popen. + * + * @return void + * @expectedException Exception + */ + public function testGetRemuxStreamWithPopenError() + { + $this->download->getRemuxStream([$this->url, $this->url]); + } + + /** + * Test getPlaylistArchiveStream function with a buggy popen. + * + * @return void + * @expectedException Exception + */ + public function testGetPlaylistArchiveStreamWithPopenError() + { + $video = $this->download->getJSON( + 'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC', + 'best' + ); + $this->download->getPlaylistArchiveStream($video, 'best'); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 320d6d1..4f64daf 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -16,7 +16,7 @@ session_start(); stream_wrapper_register('playlist', PlaylistArchiveStream::class); -/** +/* * @see https://bugs.php.net/bug.php?id=68541 */ PHPMockery::define('Alltube', 'popen');