Switch to phpunit 8

This commit is contained in:
Pierre Rudloff 2019-11-30 14:08:18 +01:00
parent 54f41d9396
commit fea1cce2d4
21 changed files with 330 additions and 335 deletions

1
.gitignore vendored
View file

@ -13,3 +13,4 @@ config/config.yml
docs/
clover.xml
i18n/*/LC_MESSAGES/*.mo
.phpunit.result.cache

View file

@ -24,7 +24,7 @@
"ffmpeg/ffmpeg": "^4.1",
"heroku/heroku-buildpack-php": "^162.0",
"phpstan/phpstan": "~0.9.2",
"phpunit/phpunit": "~6.5.2",
"phpunit/phpunit": "^8.4",
"rg3/youtube-dl": "^2019.09",
"roave/security-advisories": "dev-master",
"smarty-gettext/smarty-gettext": "^1.6",

516
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -7,7 +7,7 @@
</whitelist>
</filter>
<testsuites>
<testsuite>
<testsuite name="Tests">
<directory>tests/</directory>
</testsuite>
</testsuites>

View file

@ -33,15 +33,16 @@ abstract class BaseTest extends TestCase
/**
* Prepare tests.
*/
protected function setUp()
protected function setUp(): void
{
Config::setFile($this->getConfigFile());
$this->checkRequirements();
}
/**
* Destroy properties after test.
*/
protected function tearDown()
protected function tearDown(): void
{
Config::destroyInstance();
}
@ -52,8 +53,6 @@ abstract class BaseTest extends TestCase
*/
protected function checkRequirements()
{
parent::checkRequirements();
$annotations = $this->getAnnotations();
$requires = [];

View file

@ -7,6 +7,7 @@
namespace Alltube\Test;
use Alltube\Config;
use Exception;
/**
* Unit tests for the Config class.
@ -23,7 +24,7 @@ class ConfigTest extends BaseTest
/**
* Prepare tests.
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
@ -65,15 +66,15 @@ class ConfigTest extends BaseTest
*/
private function assertConfig(Config $config)
{
$this->assertInternalType('array', $config->params);
$this->assertInternalType('string', $config->youtubedl);
$this->assertInternalType('string', $config->python);
$this->assertInternalType('string', $config->avconv);
$this->assertInternalType('bool', $config->convert);
$this->assertInternalType('bool', $config->uglyUrls);
$this->assertInternalType('bool', $config->stream);
$this->assertInternalType('bool', $config->remux);
$this->assertInternalType('int', $config->audioBitrate);
$this->assertIsArray($config->params);
$this->assertIsString($config->youtubedl);
$this->assertIsString($config->python);
$this->assertIsString($config->avconv);
$this->assertIsBool($config->convert);
$this->assertIsBool($config->uglyUrls);
$this->assertIsBool($config->stream);
$this->assertIsBool($config->remux);
$this->assertIsInt($config->audioBitrate);
}
/**
@ -91,10 +92,10 @@ class ConfigTest extends BaseTest
* Test the setFile function with a missing config file.
*
* @return void
* @expectedException Exception
*/
public function testSetFileWithMissingFile()
{
$this->expectException(Exception::class);
Config::setFile('foo');
}
@ -132,10 +133,10 @@ class ConfigTest extends BaseTest
* Test the setOptions function.
*
* @return void
* @expectedException Exception
*/
public function testSetOptionsWithBadYoutubedl()
{
$this->expectException(Exception::class);
Config::setOptions(['youtubedl' => 'foo']);
}
@ -143,10 +144,10 @@ class ConfigTest extends BaseTest
* Test the setOptions function.
*
* @return void
* @expectedException Exception
*/
public function testSetOptionsWithBadPython()
{
$this->expectException(Exception::class);
Config::setOptions(['python' => 'foo']);
}

View file

@ -49,7 +49,7 @@ abstract class ControllerTest extends BaseTest
/**
* Prepare tests.
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

View file

@ -18,7 +18,7 @@ class ConvertedPlaylistArchiveStreamTest extends StreamTest
/**
* Prepare tests.
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

View file

@ -18,7 +18,7 @@ class DownloadControllerTest extends ControllerTest
/**
* Prepare tests.
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

View file

@ -20,7 +20,7 @@ class FrontControllerTest extends ControllerTest
/**
* Prepare tests.
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

View file

@ -16,7 +16,7 @@ class JsonControllerTest extends ControllerTest
/**
* Prepare tests.
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

View file

@ -24,7 +24,7 @@ class LocaleManagerTest extends BaseTest
/**
* Prepare tests.
*/
protected function setUp()
protected function setUp(): void
{
$_SESSION[LocaleManager::class]['locale'] = 'foo_BAR';
$this->localeManager = LocaleManager::getInstance();
@ -35,7 +35,7 @@ class LocaleManagerTest extends BaseTest
*
* @return void
*/
protected function tearDown()
protected function tearDown(): void
{
$this->localeManager->unsetLocale();
LocaleManager::destroyInstance();

View file

@ -36,7 +36,7 @@ class LocaleMiddlewareTest extends BaseTest
/**
* Prepare tests.
*/
protected function setUp()
protected function setUp(): void
{
$this->container = new Container();
$this->container['locale'] = LocaleManager::getInstance();
@ -48,7 +48,7 @@ class LocaleMiddlewareTest extends BaseTest
*
* @return void
*/
protected function tearDown()
protected function tearDown(): void
{
$this->container['locale']->unsetLocale();
LocaleManager::destroyInstance();

View file

@ -23,7 +23,7 @@ class LocaleTest extends BaseTest
/**
* Prepare tests.
*/
protected function setUp()
protected function setUp(): void
{
$this->localeObject = new Locale('fr_FR');
}

View file

@ -18,7 +18,7 @@ class PlaylistArchiveStreamTest extends StreamTest
/**
* Prepare tests.
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

View file

@ -23,7 +23,7 @@ abstract class StreamTest extends BaseTest
*
* @return void
*/
protected function tearDown()
protected function tearDown(): void
{
$this->stream->close();
}
@ -50,7 +50,7 @@ abstract class StreamTest extends BaseTest
*/
public function testTell()
{
$this->assertInternalType('int', $this->stream->tell());
$this->assertIsInt($this->stream->tell());
}
/**
@ -82,7 +82,7 @@ abstract class StreamTest extends BaseTest
public function testRead()
{
$result = $this->stream->read(8192);
$this->assertInternalType('string', $result);
$this->assertIsString($result);
$this->assertLessThanOrEqual(8192, strlen($result));
}
@ -123,7 +123,7 @@ abstract class StreamTest extends BaseTest
*/
public function testIsSeekable()
{
$this->assertInternalType('boolean', $this->stream->isSeekable());
$this->assertIsBool($this->stream->isSeekable());
}
/**
@ -154,7 +154,7 @@ abstract class StreamTest extends BaseTest
*/
public function testIsWritable()
{
$this->assertInternalType('boolean', $this->stream->isWritable());
$this->assertIsBool($this->stream->isWritable());
}
/**
@ -174,7 +174,7 @@ abstract class StreamTest extends BaseTest
*/
public function testGetContents()
{
$this->assertInternalType('string', $this->stream->getContents());
$this->assertIsString($this->stream->getContents());
}
/**
@ -184,7 +184,7 @@ abstract class StreamTest extends BaseTest
*/
public function testGetMetadata()
{
$this->assertInternalType('array', $this->stream->getMetadata());
$this->assertIsArray($this->stream->getMetadata());
}
/**
@ -194,9 +194,9 @@ abstract class StreamTest extends BaseTest
*/
public function testGetMetadataWithKey()
{
$this->assertInternalType('string', $this->stream->getMetadata('stream_type'));
$this->assertInternalType('string', $this->stream->getMetadata('mode'));
$this->assertInternalType('boolean', $this->stream->getMetadata('seekable'));
$this->assertIsString($this->stream->getMetadata('stream_type'));
$this->assertIsString($this->stream->getMetadata('mode'));
$this->assertIsBool($this->stream->getMetadata('seekable'));
$this->assertNull($this->stream->getMetadata('foo'));
}
@ -207,7 +207,7 @@ abstract class StreamTest extends BaseTest
*/
public function testDetach()
{
$this->assertInternalType('resource', $this->stream->detach());
$this->assertIsResource($this->stream->detach());
}
/**
@ -217,7 +217,7 @@ abstract class StreamTest extends BaseTest
*/
public function testToString()
{
$this->assertInternalType('string', $this->stream->__toString());
$this->assertInternalType('string', (string) $this->stream);
$this->assertIsString($this->stream->__toString());
$this->assertIsString((string) $this->stream);
}
}

View file

@ -25,7 +25,7 @@ class UglyRouterTest extends BaseTest
/**
* Prepare tests.
*/
protected function setUp()
protected function setUp(): void
{
$this->router = new UglyRouter();
$this->router->map(['GET'], '/foo', 'print')->setName('foo');

View file

@ -9,6 +9,7 @@ namespace Alltube\Test;
use Alltube\Video;
use Mockery;
use phpmock\mockery\PHPMockery;
use Exception;
/**
* Unit tests for the Video class.
@ -26,7 +27,7 @@ class VideoStubsTest extends BaseTest
/**
* Initialize properties used by test.
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
@ -41,7 +42,7 @@ class VideoStubsTest extends BaseTest
*
* @return void
*/
protected function tearDown()
protected function tearDown(): void
{
Mockery::close();
}
@ -50,10 +51,10 @@ class VideoStubsTest extends BaseTest
* Test getAudioStream function with a buggy popen.
*
* @return void
* @expectedException Exception
*/
public function testGetAudioStreamWithPopenError()
{
$this->expectException(Exception::class);
$this->video->getAudioStream();
}
@ -61,10 +62,10 @@ class VideoStubsTest extends BaseTest
* Test getM3uStream function with a buggy popen.
*
* @return void
* @expectedException Exception
*/
public function testGetM3uStreamWithPopenError()
{
$this->expectException(Exception::class);
$this->video->getM3uStream();
}
@ -72,10 +73,10 @@ class VideoStubsTest extends BaseTest
* Test getRtmpStream function with a buggy popen.
*
* @return void
* @expectedException Exception
*/
public function testGetRtmpStreamWithPopenError()
{
$this->expectException(Exception::class);
$this->video->getRtmpStream();
}
@ -83,10 +84,10 @@ class VideoStubsTest extends BaseTest
* Test getRemuxStream function with a buggy popen.
*
* @return void
* @expectedException Exception
*/
public function testGetRemuxStreamWithPopenError()
{
$this->expectException(Exception::class);
$video = $this->video->withFormat('bestvideo+bestaudio');
$video->getRemuxStream();
}
@ -95,10 +96,10 @@ class VideoStubsTest extends BaseTest
* Test getConvertedStream function with a buggy popen.
*
* @return void
* @expectedException Exception
*/
public function testGetConvertedStreamWithPopenError()
{
$this->expectException(Exception::class);
$this->video->getConvertedStream(32, 'flv');
}
}

View file

@ -8,6 +8,7 @@ namespace Alltube\Test;
use Alltube\Config;
use Alltube\Video;
use Exception;
/**
* Unit tests for the Video class.
@ -48,7 +49,7 @@ class VideoTest extends BaseTest
) {
$video = new Video($url, $format);
foreach ($video->getUrl() as $videoURL) {
$this->assertContains($domain, $videoURL);
$this->assertStringContainsString($domain, $videoURL);
}
}
@ -61,7 +62,7 @@ class VideoTest extends BaseTest
{
$video = new Video('http://vimeo.com/68375962', 'best', 'youtube-dl');
foreach ($video->getUrl() as $videoURL) {
$this->assertContains('vimeocdn.com', $videoURL);
$this->assertStringContainsString('vimeocdn.com', $videoURL);
}
}
@ -69,10 +70,10 @@ class VideoTest extends BaseTest
* Test getUrl function with a protected video and no password.
*
* @return void
* @expectedException Alltube\Exception\PasswordException
*/
public function testgetUrlWithMissingPassword()
{
$this->expectException(Exception::class);
$video = new Video('http://vimeo.com/68375962');
$video->getUrl();
}
@ -81,10 +82,10 @@ class VideoTest extends BaseTest
* Test getUrl function with a protected video and a wrong password.
*
* @return void
* @expectedException Exception
*/
public function testgetUrlWithWrongPassword()
{
$this->expectException(Exception::class);
$video = new Video('http://vimeo.com/68375962', 'best', 'foo');
$video->getUrl();
}
@ -95,11 +96,11 @@ class VideoTest extends BaseTest
* @param string $url URL
*
* @return void
* @expectedException Exception
* @dataProvider ErrorUrlProvider
*/
public function testgetUrlError($url)
{
$this->expectException(Exception::class);
$video = new Video($url);
$video->getUrl();
}
@ -132,16 +133,10 @@ class VideoTest extends BaseTest
'bbcodspdns.fcod.llnwd.net',
],
[
'https://openload.co/f/kUEfGclsU9o', 'best[protocol^=http]',
'skyrim_no-audio_1080.mp4-kUEfGclsU9o',
'mp4',
'openload.co',
],
[
'https://vimeo.com/24195442', 'best[protocol^=http]',
'https://vimeo.com/24195442', 'http-720p',
'Carving_the_Mountains-24195442',
'mp4',
'vimeocdn.com',
'gcs-vimeo.akamaized.net',
]
];
@ -241,11 +236,11 @@ class VideoTest extends BaseTest
* @param string $url URL
*
* @return void
* @expectedException Exception
* @dataProvider ErrorURLProvider
*/
public function testGetJsonError($url)
{
$this->expectException(Exception::class);
$video = new Video($url);
$video->getJson();
}
@ -275,11 +270,11 @@ class VideoTest extends BaseTest
* @param string $url URL
*
* @return void
* @expectedException Exception
* @dataProvider ErrorUrlProvider
*/
public function testGetFilenameError($url)
{
$this->expectException(Exception::class);
$video = new Video($url);
$video->getFilename();
}
@ -306,11 +301,11 @@ class VideoTest extends BaseTest
* @param string $format Format
*
* @return void
* @expectedException Exception
* @dataProvider urlProvider
*/
public function testGetAudioStreamAvconvError($url, $format)
{
$this->expectException(Exception::class);
Config::setOptions(['avconv' => 'foobar']);
$video = new Video($url, $format);
@ -324,11 +319,11 @@ class VideoTest extends BaseTest
* @param string $format Format
*
* @return void
* @expectedException Exception
* @dataProvider m3uUrlProvider
*/
public function testGetAudioStreamM3uError($url, $format)
{
$this->expectException(Exception::class);
$video = new Video($url, $format);
$video->getAudioStream();
}
@ -337,10 +332,10 @@ class VideoTest extends BaseTest
* Test getAudioStream function with a DASH URL.
*
* @return void
* @expectedException Exception
*/
public function testGetAudioStreamDashError()
{
$this->expectException(Exception::class);
$video = new Video('https://vimeo.com/251997032', 'bestaudio/best');
$video->getAudioStream();
}
@ -349,10 +344,10 @@ class VideoTest extends BaseTest
* Test getAudioStream function with a playlist.
*
* @return void
* @expectedException Exception
*/
public function testGetAudioStreamPlaylistError()
{
$this->expectException(Exception::class);
$video = new Video(
'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC',
'best'
@ -369,7 +364,7 @@ class VideoTest extends BaseTest
*/
private function assertStream($stream)
{
$this->assertInternalType('resource', $stream);
$this->assertIsResource($stream);
$this->assertFalse(feof($stream));
}
@ -411,10 +406,10 @@ class VideoTest extends BaseTest
*
* @return void
* @dataProvider urlProvider
* @expectedException Exception
*/
public function testGetRemuxStreamWithWrongVideo($url, $format)
{
$this->expectException(Exception::class);
$video = new Video($url, $format);
$video->getRemuxStream();
}
@ -444,11 +439,11 @@ class VideoTest extends BaseTest
* @param string $format Format
*
* @return void
* @expectedException Exception
* @dataProvider m3uUrlProvider
*/
public function testGetM3uStreamAvconvError($url, $format)
{
$this->expectException(Exception::class);
Config::setOptions(['avconv' => 'foobar']);
$video = new Video($url, $format);
@ -477,11 +472,11 @@ class VideoTest extends BaseTest
* @param string $format Format
*
* @return void
* @expectedException Exception
* @dataProvider m3uUrlProvider
*/
public function testGetConvertedStreamM3uError($url, $format)
{
$this->expectException(Exception::class);
$video = new Video($url, $format);
$video->getConvertedStream(32, 'flv');
}

View file

@ -18,7 +18,7 @@ class YoutubeChunkStreamTest extends StreamTest
/**
* Prepare tests.
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

View file

@ -18,7 +18,7 @@ class YoutubeStreamTest extends StreamTest
/**
* Prepare tests.
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();