Make tests run on Windows (fixes #137)

Use AppVeyor to run tests
This commit is contained in:
Pierre Rudloff 2017-11-11 13:58:55 +01:00
parent 88ea150d5a
commit 2432a06c1b
9 changed files with 116 additions and 29 deletions

20
.appveyor.yml Normal file
View file

@ -0,0 +1,20 @@
---
install:
- sc config wuauserv start= auto
- net start wuauserv
- cinst php composer ffmpeg rtmpdump
- refreshenv
- copy C:\tools\php71\php.ini-development C:\tools\php71\php.ini
- echo extension=C:\tools\php71\ext\php_gmp.dll >> C:\tools\php71\php.ini
- echo extension=C:\tools\php71\ext\php_gettext.dll >> C:\tools\php71\php.ini
- echo extension=C:\tools\php71\ext\php_intl.dll >> C:\tools\php71\php.ini
- echo extension=C:\tools\php71\ext\php_openssl.dll >> C:\tools\php71\php.ini
- echo extension=C:\tools\php71\ext\php_mbstring.dll >> C:\tools\php71\php.ini
- composer install --no-dev
- composer global require phpunit/phpunit
- C:\Python36\python.exe -m pip install youtube-dl
test_script:
- phpunit
build: "off"

View file

@ -61,10 +61,10 @@ class PlaylistArchiveStream extends TarArchive
/**
* PlaylistArchiveStream constructor.
*/
public function __construct()
public function __construct(Config $config = null)
{
$this->client = new \GuzzleHttp\Client();
$this->download = new VideoDownload();
$this->download = new VideoDownload($config);
}
/**

View file

@ -58,7 +58,7 @@ class VideoDownload
* */
public function listExtractors()
{
return explode(PHP_EOL, trim($this->getProp(null, null, 'list-extractors')));
return explode("\n", trim($this->getProp(null, null, 'list-extractors')));
}
/**
@ -135,7 +135,7 @@ class VideoDownload
* */
public function getURL($url, $format = null, $password = null)
{
return explode(PHP_EOL, $this->getProp($url, $format, 'get-url', $password));
return explode("\n", $this->getProp($url, $format, 'get-url', $password));
}
/**

View file

@ -7,10 +7,10 @@ python: /usr/bin/python
# An array of parameters to pass to youtube-dl
params:
- --no-playlist
- --no-warnings
- --playlist-end
- 1
- --ignore-errors
- --flat-playlist
- --restrict-filenames
# True to enable audio conversion
convert: false

View file

@ -0,0 +1,12 @@
---
convert: false
python: C:\Python36\python.exe
avconv: C:\ProgramData\chocolatey\bin\ffmpeg.exe
rtmpdump: C:\ProgramData\chocolatey\bin\rtmpdump
youtubedl: C:\Python36\Lib\site-packages\youtube_dl\__main__.py
params:
- --no-warnings
- --ignore-errors
- --flat-playlist
- --restrict-filenames
- --no-check-certificate

View file

@ -83,7 +83,7 @@ class FrontController
} else {
$this->config = Config::getInstance();
}
$this->download = new VideoDownload();
$this->download = new VideoDownload($this->config);
$this->container = $container;
$this->view = $this->container->get('view');
$this->localeManager = $this->container->get('locale');

View file

@ -48,6 +48,13 @@ class FrontControllerTest extends TestCase
*/
private $controller;
/**
* Config class instance.
*
* @var Config
*/
private $config;
/**
* Prepare tests.
*/
@ -58,7 +65,15 @@ class FrontControllerTest extends TestCase
$this->response = new Response();
$this->container['view'] = ViewFactory::create($this->container, $this->request);
$this->container['locale'] = new LocaleManager();
$this->controller = new FrontController($this->container, Config::getInstance('config/config_test.yml'));
if (PHP_OS == 'WINNT') {
$configFile = 'config_test_windows.yml';
} else {
$configFile = 'config_test.yml';
}
$this->config = Config::getInstance('config/'.$configFile);
$this->controller = new FrontController($this->container, $this->config);
$this->container['router']->map(['GET'], '/', [$this->controller, 'index'])
->setName('index');
$this->container['router']->map(['GET'], '/video', [$this->controller, 'video'])
@ -150,6 +165,18 @@ class FrontControllerTest extends TestCase
* @return void
*/
public function testConstructor()
{
$controller = new FrontController($this->container, $this->config);
$this->assertInstanceOf(FrontController::class, $controller);
}
/**
* Test the constructor with a default config.
*
* @return void
* @requires OS Linux
*/
public function testConstructorWithDefaultConfig()
{
$controller = new FrontController($this->container);
$this->assertInstanceOf(FrontController::class, $controller);
@ -162,7 +189,8 @@ class FrontControllerTest extends TestCase
*/
public function testConstructorWithStream()
{
$controller = new FrontController($this->container, new Config(['stream' => true]));
$this->config->stream = true;
$controller = new FrontController($this->container, $this->config);
$this->assertInstanceOf(FrontController::class, $controller);
}
@ -302,12 +330,12 @@ class FrontControllerTest extends TestCase
*/
public function testVideoWithStream()
{
$config = new Config(['stream' => true]);
$this->assertRequestIsOk('video', ['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU'], $config);
$this->config->stream = true;
$this->assertRequestIsOk('video', ['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU'], $this->config);
$this->assertRequestIsOk(
'video',
['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'audio' => true],
$config
$this->config
);
}
@ -375,10 +403,11 @@ class FrontControllerTest extends TestCase
*/
public function testRedirectWithStream()
{
$this->config->stream = true;
$this->assertRequestIsOk(
'redirect',
['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU'],
new Config(['stream' => true])
$this->config
);
}
@ -389,10 +418,11 @@ class FrontControllerTest extends TestCase
*/
public function testRedirectWithM3uStream()
{
$this->config->stream = true;
$this->assertRequestIsOk(
'redirect',
['url' => 'https://twitter.com/verge/status/813055465324056576/video/1'],
new Config(['stream' => true])
$this->config
);
}
@ -403,10 +433,11 @@ class FrontControllerTest extends TestCase
*/
public function testRedirectWithRtmpStream()
{
$this->config->stream = true;
$this->assertRequestIsOk(
'redirect',
['url' => 'http://www.canalc2.tv/video/12163', 'format' => 'rtmp'],
new Config(['stream' => true])
$this->config
);
}
@ -417,13 +448,14 @@ class FrontControllerTest extends TestCase
*/
public function testRedirectWithRemux()
{
$this->config->remux = true;
$this->assertRequestIsOk(
'redirect',
[
'url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU',
'format' => 'bestvideo+bestaudio',
],
new Config(['remux' => true])
$this->config
);
}
@ -481,13 +513,15 @@ class FrontControllerTest extends TestCase
* Test the redirect() function with a playlist stream.
*
* @return void
* @requires OS Linux
*/
public function testRedirectWithPlaylist()
{
$this->config->stream = true;
$this->assertRequestIsOk(
'redirect',
['url' => 'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC'],
new Config(['stream' => true])
$this->config
);
}

View file

@ -5,6 +5,7 @@
namespace Alltube\Test;
use Alltube\Config;
use Alltube\PlaylistArchiveStream;
use PHPUnit\Framework\TestCase;
@ -25,7 +26,12 @@ class PlaylistArchiveStreamTest extends TestCase
*/
protected function setUp()
{
$this->stream = new PlaylistArchiveStream();
if (PHP_OS == 'WINNT') {
$configFile = 'config_test_windows.yml';
} else {
$configFile = 'config_test.yml';
}
$this->stream = new PlaylistArchiveStream(Config::getInstance('config/'.$configFile));
}
/**

View file

@ -21,12 +21,25 @@ class VideoDownloadTest extends TestCase
*/
private $download;
/**
* Config class instance.
*
* @var Config
*/
private $config;
/**
* Initialize properties used by test.
*/
protected function setUp()
{
$this->download = new VideoDownload(Config::getInstance('config/config_test.yml'));
if (PHP_OS == 'WINNT') {
$configFile = 'config_test_windows.yml';
} else {
$configFile = 'config_test.yml';
}
$this->config = Config::getInstance('config/'.$configFile);
$this->download = new VideoDownload($this->config);
}
/**
@ -45,9 +58,8 @@ class VideoDownloadTest extends TestCase
*/
public function testConstructorWithMissingYoutubedl()
{
new VideoDownload(
new Config(['youtubedl' => 'foo'])
);
$this->config->youtubedl = 'foo';
new VideoDownload($this->config);
}
/**
@ -58,9 +70,8 @@ class VideoDownloadTest extends TestCase
*/
public function testConstructorWithMissingPython()
{
new VideoDownload(
new Config(['python' => 'foo'])
);
$this->config->python = 'foo';
new VideoDownload($this->config);
}
/**
@ -364,7 +375,8 @@ class VideoDownloadTest extends TestCase
*/
public function testGetAudioStreamAvconvError($url, $format)
{
$download = new VideoDownload(new Config(['avconv' => 'foobar']));
$this->config->avconv = 'foobar';
$download = new VideoDownload($this->config);
$download->getAudioStream($url, $format);
}
@ -380,7 +392,8 @@ class VideoDownloadTest extends TestCase
*/
public function testGetAudioStreamRtmpError($url, $format)
{
$download = new VideoDownload(new Config(['rtmpdump' => 'foobar']));
$this->config->rtmpdump = 'foobar';
$download = new VideoDownload($this->config);
$download->getAudioStream($url, $format);
}
@ -477,7 +490,8 @@ class VideoDownloadTest extends TestCase
*/
public function testGetM3uStreamAvconvError($url, $format)
{
$download = new VideoDownload(new Config(['avconv' => 'foobar']));
$this->config->avconv = 'foobar';
$download = new VideoDownload($this->config);
$video = $download->getJSON($url, $format);
$download->getM3uStream($video);
}
@ -486,6 +500,7 @@ class VideoDownloadTest extends TestCase
* Test getPlaylistArchiveStream function without avconv.
*
* @return void
* @requires OS Linux
*/
public function testGetPlaylistArchiveStream()
{