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

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()
{