Create a test container that we can use in any test
This commit is contained in:
parent
d83774ae7d
commit
3d2b518cb4
16 changed files with 179 additions and 117 deletions
|
@ -13,7 +13,6 @@ use Alltube\Locale;
|
||||||
use Alltube\Middleware\CspMiddleware;
|
use Alltube\Middleware\CspMiddleware;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Slim\Http\StatusCode;
|
use Slim\Http\StatusCode;
|
||||||
use Slim\Http\Uri;
|
|
||||||
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
|
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
|
|
57
tests/ContainerTest.php
Normal file
57
tests/ContainerTest.php
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PlaylistArchiveStreamTest class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alltube\Test;
|
||||||
|
|
||||||
|
use Alltube\Config;
|
||||||
|
use Alltube\Exception\ConfigException;
|
||||||
|
use Alltube\Exception\DependencyException;
|
||||||
|
use Alltube\Factory\LocaleManagerFactory;
|
||||||
|
use Alltube\Factory\SessionFactory;
|
||||||
|
use Alltube\Factory\ViewFactory;
|
||||||
|
use Psr\Log\NullLogger;
|
||||||
|
use Slim\Container;
|
||||||
|
use Slim\Http\Environment;
|
||||||
|
use SmartyException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for tests that require a container.
|
||||||
|
*/
|
||||||
|
abstract class ContainerTest extends BaseTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Slim dependency container.
|
||||||
|
*
|
||||||
|
* @var Container
|
||||||
|
*/
|
||||||
|
protected $container;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare tests.
|
||||||
|
* @throws ConfigException
|
||||||
|
* @throws DependencyException
|
||||||
|
* @throws SmartyException
|
||||||
|
*/
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
$this->checkRequirements();
|
||||||
|
|
||||||
|
$this->container = new Container(['environment' => Environment::mock()]);
|
||||||
|
$this->container['config'] = Config::fromFile($this->getConfigFile());
|
||||||
|
$this->container['session'] = SessionFactory::create($this->container);
|
||||||
|
$this->container['locale'] = LocaleManagerFactory::create($this->container);
|
||||||
|
$this->container['view'] = ViewFactory::create($this->container);
|
||||||
|
$this->container['logger'] = new NullLogger();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleanup after each test.
|
||||||
|
*/
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
$this->container->get('session')->clear();
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,48 +6,19 @@
|
||||||
|
|
||||||
namespace Alltube\Test;
|
namespace Alltube\Test;
|
||||||
|
|
||||||
use Alltube\Config;
|
|
||||||
use Alltube\Controller\BaseController;
|
use Alltube\Controller\BaseController;
|
||||||
use Alltube\Controller\DownloadController;
|
use Alltube\Controller\DownloadController;
|
||||||
use Alltube\Controller\FrontController;
|
use Alltube\Controller\FrontController;
|
||||||
use Alltube\Exception\ConfigException;
|
use Alltube\Exception\ConfigException;
|
||||||
use Alltube\Exception\DependencyException;
|
use Alltube\Exception\DependencyException;
|
||||||
use Alltube\Factory\LocaleManagerFactory;
|
|
||||||
use Alltube\Factory\SessionFactory;
|
|
||||||
use Alltube\Factory\ViewFactory;
|
|
||||||
use Psr\Log\NullLogger;
|
|
||||||
use Slim\Container;
|
|
||||||
use Slim\Http\Environment;
|
|
||||||
use Slim\Http\Request;
|
|
||||||
use Slim\Http\Response;
|
use Slim\Http\Response;
|
||||||
use SmartyException;
|
use SmartyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class used by the controller tests.
|
* Abstract class used by the controller tests.
|
||||||
*/
|
*/
|
||||||
abstract class ControllerTest extends BaseTest
|
abstract class ControllerTest extends ContainerTest
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Slim dependency container.
|
|
||||||
*
|
|
||||||
* @var Container
|
|
||||||
*/
|
|
||||||
protected $container;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mock HTTP request.
|
|
||||||
*
|
|
||||||
* @var Request
|
|
||||||
*/
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mock HTTP response.
|
|
||||||
*
|
|
||||||
* @var Response
|
|
||||||
*/
|
|
||||||
protected $response;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller instance used in tests.
|
* Controller instance used in tests.
|
||||||
* @var BaseController
|
* @var BaseController
|
||||||
|
@ -63,27 +34,20 @@ abstract class ControllerTest extends BaseTest
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->container = new Container();
|
|
||||||
$this->request = Request::createFromEnvironment(Environment::mock());
|
|
||||||
$this->response = new Response();
|
|
||||||
$this->container['config'] = Config::fromFile($this->getConfigFile());
|
|
||||||
$this->container['session'] = SessionFactory::create($this->container);
|
|
||||||
$this->container['locale'] = LocaleManagerFactory::create($this->container);
|
|
||||||
$this->container['view'] = ViewFactory::create($this->container, $this->request);
|
|
||||||
$this->container['logger'] = new NullLogger();
|
|
||||||
|
|
||||||
$frontController = new FrontController($this->container);
|
$frontController = new FrontController($this->container);
|
||||||
$downloadController = new DownloadController($this->container);
|
$downloadController = new DownloadController($this->container);
|
||||||
|
|
||||||
$this->container['router']->map(['GET'], '/', [$frontController, 'index'])
|
$router = $this->container->get('router');
|
||||||
|
|
||||||
|
$router->map(['GET'], '/', [$frontController, 'index'])
|
||||||
->setName('index');
|
->setName('index');
|
||||||
$this->container['router']->map(['GET'], '/video', [$frontController, 'info'])
|
$router->map(['GET'], '/video', [$frontController, 'info'])
|
||||||
->setName('info');
|
->setName('info');
|
||||||
$this->container['router']->map(['GET'], '/extractors', [$frontController, 'extractors'])
|
$router->map(['GET'], '/extractors', [$frontController, 'extractors'])
|
||||||
->setName('extractors');
|
->setName('extractors');
|
||||||
$this->container['router']->map(['GET'], '/locale', [$frontController, 'locale'])
|
$router->map(['GET'], '/locale', [$frontController, 'locale'])
|
||||||
->setName('locale');
|
->setName('locale');
|
||||||
$this->container['router']->map(['GET'], '/redirect', [$downloadController, 'download'])
|
$router->map(['GET'], '/redirect', [$downloadController, 'download'])
|
||||||
->setName('download');
|
->setName('download');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,8 +62,8 @@ abstract class ControllerTest extends BaseTest
|
||||||
protected function getRequestResult(string $request, array $params)
|
protected function getRequestResult(string $request, array $params)
|
||||||
{
|
{
|
||||||
return $this->controller->$request(
|
return $this->controller->$request(
|
||||||
$this->request->withQueryParams($params),
|
$this->container->get('request')->withQueryParams($params),
|
||||||
$this->response
|
$this->container->get('response')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
namespace Alltube\Test;
|
namespace Alltube\Test;
|
||||||
|
|
||||||
use Alltube\Exception\ConfigException;
|
use Alltube\Exception\ConfigException;
|
||||||
|
use Alltube\Exception\DependencyException;
|
||||||
use Alltube\Stream\ConvertedPlaylistArchiveStream;
|
use Alltube\Stream\ConvertedPlaylistArchiveStream;
|
||||||
|
use SmartyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the ConvertedPlaylistArchiveStream class.
|
* Unit tests for the ConvertedPlaylistArchiveStream class.
|
||||||
|
@ -15,9 +17,13 @@ use Alltube\Stream\ConvertedPlaylistArchiveStream;
|
||||||
*/
|
*/
|
||||||
class ConvertedPlaylistArchiveStreamTest extends StreamTest
|
class ConvertedPlaylistArchiveStreamTest extends StreamTest
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare tests.
|
* Prepare tests.
|
||||||
|
*
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
|
* @throws DependencyException
|
||||||
|
* @throws SmartyException
|
||||||
*/
|
*/
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
|
|
|
@ -81,7 +81,7 @@ class FrontControllerTest extends ControllerTest
|
||||||
Request::createFromEnvironment(
|
Request::createFromEnvironment(
|
||||||
Environment::mock(['REQUEST_URI' => '/foo', 'QUERY_STRING' => 'foo=bar'])
|
Environment::mock(['REQUEST_URI' => '/foo', 'QUERY_STRING' => 'foo=bar'])
|
||||||
),
|
),
|
||||||
$this->response
|
$this->container->get('response')
|
||||||
);
|
);
|
||||||
$this->assertTrue($result->isOk());
|
$this->assertTrue($result->isOk());
|
||||||
}
|
}
|
||||||
|
@ -189,9 +189,9 @@ class FrontControllerTest extends ControllerTest
|
||||||
public function testInfoWithPassword()
|
public function testInfoWithPassword()
|
||||||
{
|
{
|
||||||
$result = $this->controller->info(
|
$result = $this->controller->info(
|
||||||
$this->request->withQueryParams(['url' => 'http://vimeo.com/68375962'])
|
$this->container->get('request')->withQueryParams(['url' => 'http://vimeo.com/68375962'])
|
||||||
->withParsedBody(['password' => 'youtube-dl']),
|
->withParsedBody(['password' => 'youtube-dl']),
|
||||||
$this->response
|
$this->container->get('response')
|
||||||
);
|
);
|
||||||
$this->assertTrue($result->isOk());
|
$this->assertTrue($result->isOk());
|
||||||
}
|
}
|
||||||
|
@ -247,7 +247,11 @@ class FrontControllerTest extends ControllerTest
|
||||||
*/
|
*/
|
||||||
public function testError()
|
public function testError()
|
||||||
{
|
{
|
||||||
$result = $this->controller->error($this->request, $this->response, new Exception('foo'));
|
$result = $this->controller->error(
|
||||||
|
$this->container->get('request'),
|
||||||
|
$this->container->get('response'),
|
||||||
|
new Exception('foo')
|
||||||
|
);
|
||||||
$this->assertTrue($result->isServerError());
|
$this->assertTrue($result->isServerError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,8 +264,8 @@ class FrontControllerTest extends ControllerTest
|
||||||
{
|
{
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
$this->controller->locale(
|
$this->controller->locale(
|
||||||
$this->request,
|
$this->container->get('request'),
|
||||||
$this->response,
|
$this->container->get('response'),
|
||||||
['locale' => 'fr_FR']
|
['locale' => 'fr_FR']
|
||||||
)->isRedirect()
|
)->isRedirect()
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,15 +6,17 @@
|
||||||
|
|
||||||
namespace Alltube\Test;
|
namespace Alltube\Test;
|
||||||
|
|
||||||
|
use Alltube\Exception\ConfigException;
|
||||||
|
use Alltube\Exception\DependencyException;
|
||||||
use Alltube\Factory\SessionFactory;
|
use Alltube\Factory\SessionFactory;
|
||||||
use Alltube\Locale;
|
use Alltube\Locale;
|
||||||
use Alltube\LocaleManager;
|
use Alltube\LocaleManager;
|
||||||
use Slim\Container;
|
use SmartyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the LocaleManagerTest class.
|
* Unit tests for the LocaleManagerTest class.
|
||||||
*/
|
*/
|
||||||
class LocaleManagerTest extends BaseTest
|
class LocaleManagerTest extends ContainerTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* LocaleManager class instance.
|
* LocaleManager class instance.
|
||||||
|
@ -25,11 +27,17 @@ class LocaleManagerTest extends BaseTest
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare tests.
|
* Prepare tests.
|
||||||
|
*
|
||||||
|
* @throws ConfigException
|
||||||
|
* @throws DependencyException
|
||||||
|
* @throws SmartyException
|
||||||
*/
|
*/
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
$_SESSION[LocaleManager::class]['locale'] = 'foo_BAR';
|
$_SESSION[LocaleManager::class]['locale'] = 'foo_BAR';
|
||||||
$this->localeManager = new LocaleManager(SessionFactory::create(new Container()));
|
$this->localeManager = new LocaleManager(SessionFactory::create($this->container));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,6 +47,8 @@ class LocaleManagerTest extends BaseTest
|
||||||
*/
|
*/
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
$this->localeManager->unsetLocale();
|
$this->localeManager->unsetLocale();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,19 +6,17 @@
|
||||||
|
|
||||||
namespace Alltube\Test;
|
namespace Alltube\Test;
|
||||||
|
|
||||||
|
use Alltube\Exception\ConfigException;
|
||||||
use Alltube\Exception\DependencyException;
|
use Alltube\Exception\DependencyException;
|
||||||
use Alltube\Factory\LocaleManagerFactory;
|
|
||||||
use Alltube\Factory\SessionFactory;
|
|
||||||
use Alltube\Middleware\LocaleMiddleware;
|
use Alltube\Middleware\LocaleMiddleware;
|
||||||
use Slim\Container;
|
|
||||||
use Slim\Http\Environment;
|
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
use Slim\Http\Response;
|
use Slim\Http\Response;
|
||||||
|
use SmartyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the FrontController class.
|
* Unit tests for the FrontController class.
|
||||||
*/
|
*/
|
||||||
class LocaleMiddlewareTest extends BaseTest
|
class LocaleMiddlewareTest extends ContainerTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* LocaleMiddleware instance.
|
* LocaleMiddleware instance.
|
||||||
|
@ -27,22 +25,17 @@ class LocaleMiddlewareTest extends BaseTest
|
||||||
*/
|
*/
|
||||||
private $middleware;
|
private $middleware;
|
||||||
|
|
||||||
/**
|
|
||||||
* Slim dependency container.
|
|
||||||
*
|
|
||||||
* @var Container
|
|
||||||
*/
|
|
||||||
private $container;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare tests.
|
* Prepare tests.
|
||||||
|
*
|
||||||
* @throws DependencyException
|
* @throws DependencyException
|
||||||
|
* @throws ConfigException
|
||||||
|
* @throws SmartyException
|
||||||
*/
|
*/
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$this->container = new Container();
|
parent::setUp();
|
||||||
$this->container['session'] = SessionFactory::create($this->container);
|
|
||||||
$this->container['locale'] = LocaleManagerFactory::create($this->container);
|
|
||||||
$this->middleware = new LocaleMiddleware($this->container);
|
$this->middleware = new LocaleMiddleware($this->container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +46,9 @@ class LocaleMiddlewareTest extends BaseTest
|
||||||
*/
|
*/
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
$this->container['locale']->unsetLocale();
|
parent::tearDown();
|
||||||
|
|
||||||
|
$this->container->get('locale')->unsetLocale();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,7 +61,7 @@ class LocaleMiddlewareTest extends BaseTest
|
||||||
{
|
{
|
||||||
$locale = [
|
$locale = [
|
||||||
'language' => 'en',
|
'language' => 'en',
|
||||||
'region' => 'US',
|
'region' => 'US',
|
||||||
];
|
];
|
||||||
$this->assertEquals('en_US', $this->middleware->testLocale($locale));
|
$this->assertEquals('en_US', $this->middleware->testLocale($locale));
|
||||||
}
|
}
|
||||||
|
@ -80,7 +75,7 @@ class LocaleMiddlewareTest extends BaseTest
|
||||||
{
|
{
|
||||||
$locale = [
|
$locale = [
|
||||||
'language' => 'foo',
|
'language' => 'foo',
|
||||||
'region' => 'BAR',
|
'region' => 'BAR',
|
||||||
];
|
];
|
||||||
$this->assertNull($this->middleware->testLocale($locale));
|
$this->assertNull($this->middleware->testLocale($locale));
|
||||||
$this->assertNull($this->middleware->testLocale([]));
|
$this->assertNull($this->middleware->testLocale([]));
|
||||||
|
@ -119,9 +114,8 @@ class LocaleMiddlewareTest extends BaseTest
|
||||||
*/
|
*/
|
||||||
public function testInvoke()
|
public function testInvoke()
|
||||||
{
|
{
|
||||||
$request = Request::createFromEnvironment(Environment::mock());
|
|
||||||
$this->middleware->__invoke(
|
$this->middleware->__invoke(
|
||||||
$request->withHeader('Accept-Language', 'foo-BAR'),
|
$this->container->get('request')->withHeader('Accept-Language', 'foo-BAR'),
|
||||||
new Response(),
|
new Response(),
|
||||||
[$this, 'assertHeader']
|
[$this, 'assertHeader']
|
||||||
);
|
);
|
||||||
|
@ -134,9 +128,8 @@ class LocaleMiddlewareTest extends BaseTest
|
||||||
*/
|
*/
|
||||||
public function testInvokeWithoutHeader()
|
public function testInvokeWithoutHeader()
|
||||||
{
|
{
|
||||||
$request = Request::createFromEnvironment(Environment::mock());
|
|
||||||
$this->middleware->__invoke(
|
$this->middleware->__invoke(
|
||||||
$request->withoutHeader('Accept-Language'),
|
$this->container->get('request')->withoutHeader('Accept-Language'),
|
||||||
new Response(),
|
new Response(),
|
||||||
[$this, 'assertNoHeader']
|
[$this, 'assertNoHeader']
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,12 +6,15 @@
|
||||||
|
|
||||||
namespace Alltube\Test;
|
namespace Alltube\Test;
|
||||||
|
|
||||||
|
use Alltube\Exception\ConfigException;
|
||||||
|
use Alltube\Exception\DependencyException;
|
||||||
use Alltube\Locale;
|
use Alltube\Locale;
|
||||||
|
use SmartyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the LocaleTest class.
|
* Unit tests for the LocaleTest class.
|
||||||
*/
|
*/
|
||||||
class LocaleTest extends BaseTest
|
class LocaleTest extends ContainerTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Locale class instance.
|
* Locale class instance.
|
||||||
|
@ -22,9 +25,15 @@ class LocaleTest extends BaseTest
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare tests.
|
* Prepare tests.
|
||||||
|
*
|
||||||
|
* @throws DependencyException
|
||||||
|
* @throws ConfigException
|
||||||
|
* @throws SmartyException
|
||||||
*/
|
*/
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
$this->localeObject = new Locale('fr_FR');
|
$this->localeObject = new Locale('fr_FR');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
namespace Alltube\Test;
|
namespace Alltube\Test;
|
||||||
|
|
||||||
use Alltube\Exception\ConfigException;
|
use Alltube\Exception\ConfigException;
|
||||||
|
use Alltube\Exception\DependencyException;
|
||||||
use Alltube\Stream\PlaylistArchiveStream;
|
use Alltube\Stream\PlaylistArchiveStream;
|
||||||
|
use SmartyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the PlaylistArchiveStream class.
|
* Unit tests for the PlaylistArchiveStream class.
|
||||||
|
@ -17,7 +19,10 @@ class PlaylistArchiveStreamTest extends StreamTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Prepare tests.
|
* Prepare tests.
|
||||||
|
*
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
|
* @throws DependencyException
|
||||||
|
* @throws SmartyException
|
||||||
*/
|
*/
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,16 +6,17 @@
|
||||||
|
|
||||||
namespace Alltube\Test;
|
namespace Alltube\Test;
|
||||||
|
|
||||||
use Alltube\Config;
|
|
||||||
use Alltube\Exception\ConfigException;
|
use Alltube\Exception\ConfigException;
|
||||||
|
use Alltube\Exception\DependencyException;
|
||||||
use Alltube\Library\Downloader;
|
use Alltube\Library\Downloader;
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
use SmartyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class used by the stream tests.
|
* Abstract class used by the stream tests.
|
||||||
*/
|
*/
|
||||||
abstract class StreamTest extends BaseTest
|
abstract class StreamTest extends ContainerTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Stream instance.
|
* Stream instance.
|
||||||
|
@ -31,15 +32,16 @@ abstract class StreamTest extends BaseTest
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare tests.
|
* Prepare tests.
|
||||||
|
*
|
||||||
|
* @throws DependencyException
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
|
* @throws SmartyException
|
||||||
*/
|
*/
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
// So ffmpeg does not spam the output with broken pipe errors.
|
$this->downloader = $this->container->get('config')->getDownloader();
|
||||||
$config = new Config(['ffmpegVerbosity' => 'fatal']);
|
|
||||||
$this->downloader = $config->getDownloader();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,6 +51,8 @@ abstract class StreamTest extends BaseTest
|
||||||
*/
|
*/
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
$this->stream->close();
|
$this->stream->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,17 @@
|
||||||
|
|
||||||
namespace Alltube\Test;
|
namespace Alltube\Test;
|
||||||
|
|
||||||
|
use Alltube\Exception\ConfigException;
|
||||||
|
use Alltube\Exception\DependencyException;
|
||||||
use Alltube\UglyRouter;
|
use Alltube\UglyRouter;
|
||||||
use Slim\Http\Environment;
|
use Slim\Http\Environment;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
|
use SmartyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the UglyRouter class.
|
* Unit tests for the UglyRouter class.
|
||||||
*/
|
*/
|
||||||
class UglyRouterTest extends BaseTest
|
class UglyRouterTest extends ContainerTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* UglyRouter instance.
|
* UglyRouter instance.
|
||||||
|
@ -24,9 +27,15 @@ class UglyRouterTest extends BaseTest
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare tests.
|
* Prepare tests.
|
||||||
|
*
|
||||||
|
* @throws ConfigException
|
||||||
|
* @throws DependencyException
|
||||||
|
* @throws SmartyException
|
||||||
*/
|
*/
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
$this->router = new UglyRouter();
|
$this->router = new UglyRouter();
|
||||||
$this->router->map(['GET'], '/foo', 'print')->setName('foo');
|
$this->router->map(['GET'], '/foo', 'print')->setName('foo');
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,15 @@
|
||||||
|
|
||||||
namespace Alltube\Test;
|
namespace Alltube\Test;
|
||||||
|
|
||||||
use Alltube\Config;
|
use Alltube\Exception\ConfigException;
|
||||||
|
use Alltube\Exception\DependencyException;
|
||||||
use Alltube\Library\Downloader;
|
use Alltube\Library\Downloader;
|
||||||
use Alltube\Library\Exception\AlltubeLibraryException;
|
use Alltube\Library\Exception\AlltubeLibraryException;
|
||||||
use Alltube\Library\Exception\PopenStreamException;
|
use Alltube\Library\Exception\PopenStreamException;
|
||||||
use Alltube\Library\Video;
|
use Alltube\Library\Video;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
use phpmock\mockery\PHPMockery;
|
use phpmock\mockery\PHPMockery;
|
||||||
|
use SmartyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the Video class.
|
* Unit tests for the Video class.
|
||||||
|
@ -20,7 +22,7 @@ use phpmock\mockery\PHPMockery;
|
||||||
*
|
*
|
||||||
* @requires download
|
* @requires download
|
||||||
*/
|
*/
|
||||||
class VideoStubsTest extends BaseTest
|
class VideoStubsTest extends ContainerTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Video used in many tests.
|
* Video used in many tests.
|
||||||
|
@ -38,6 +40,10 @@ class VideoStubsTest extends BaseTest
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize properties used by test.
|
* Initialize properties used by test.
|
||||||
|
*
|
||||||
|
* @throws ConfigException
|
||||||
|
* @throws DependencyException
|
||||||
|
* @throws SmartyException
|
||||||
*/
|
*/
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
|
@ -46,8 +52,7 @@ class VideoStubsTest extends BaseTest
|
||||||
PHPMockery::mock('Alltube\Library', 'popen');
|
PHPMockery::mock('Alltube\Library', 'popen');
|
||||||
PHPMockery::mock('Alltube\Library', 'fopen');
|
PHPMockery::mock('Alltube\Library', 'fopen');
|
||||||
|
|
||||||
$config = new Config();
|
$this->downloader = $this->container->get('config')->getDownloader();
|
||||||
$this->downloader = $config->getDownloader();
|
|
||||||
$this->video = $this->downloader->getVideo('https://www.youtube.com/watch?v=XJC9_JkzugE');
|
$this->video = $this->downloader->getVideo('https://www.youtube.com/watch?v=XJC9_JkzugE');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,6 +63,8 @@ class VideoStubsTest extends BaseTest
|
||||||
*/
|
*/
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
Mockery::close();
|
Mockery::close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ namespace Alltube\Test;
|
||||||
|
|
||||||
use Alltube\Config;
|
use Alltube\Config;
|
||||||
use Alltube\Exception\ConfigException;
|
use Alltube\Exception\ConfigException;
|
||||||
|
use Alltube\Exception\DependencyException;
|
||||||
use Alltube\Library\Downloader;
|
use Alltube\Library\Downloader;
|
||||||
use Alltube\Library\Exception\AlltubeLibraryException;
|
use Alltube\Library\Exception\AlltubeLibraryException;
|
||||||
use Alltube\Library\Exception\AvconvException;
|
use Alltube\Library\Exception\AvconvException;
|
||||||
|
@ -18,13 +19,14 @@ use Alltube\Library\Exception\RemuxException;
|
||||||
use Alltube\Library\Exception\WrongPasswordException;
|
use Alltube\Library\Exception\WrongPasswordException;
|
||||||
use Alltube\Library\Exception\YoutubedlException;
|
use Alltube\Library\Exception\YoutubedlException;
|
||||||
use Alltube\Library\Video;
|
use Alltube\Library\Video;
|
||||||
|
use SmartyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the Video class.
|
* Unit tests for the Video class.
|
||||||
* @requires download
|
* @requires download
|
||||||
* @todo Split Downloader and Video tests.
|
* @todo Split Downloader and Video tests.
|
||||||
*/
|
*/
|
||||||
class VideoTest extends BaseTest
|
class VideoTest extends ContainerTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Downloader instance used in tests.
|
* Downloader instance used in tests.
|
||||||
|
@ -42,15 +44,16 @@ class VideoTest extends BaseTest
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare tests.
|
* Prepare tests.
|
||||||
|
*
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
|
* @throws DependencyException
|
||||||
|
* @throws SmartyException
|
||||||
*/
|
*/
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
// So ffmpeg does not spam the output with broken pipe errors.
|
$this->downloader = $this->container->get('config')->getDownloader();
|
||||||
$config = new Config(['ffmpegVerbosity' => 'fatal']);
|
|
||||||
$this->downloader = $config->getDownloader();
|
|
||||||
$this->format = 'best';
|
$this->format = 'best';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,38 +6,24 @@
|
||||||
|
|
||||||
namespace Alltube\Test;
|
namespace Alltube\Test;
|
||||||
|
|
||||||
use Alltube\Exception\ConfigException;
|
|
||||||
use Alltube\Exception\DependencyException;
|
|
||||||
use Alltube\Factory\ConfigFactory;
|
|
||||||
use Alltube\Factory\LocaleManagerFactory;
|
|
||||||
use Alltube\Factory\SessionFactory;
|
|
||||||
use Alltube\Factory\ViewFactory;
|
use Alltube\Factory\ViewFactory;
|
||||||
use Slim\Container;
|
|
||||||
use Slim\Http\Environment;
|
|
||||||
use Slim\Http\Request;
|
|
||||||
use Slim\Views\Smarty;
|
use Slim\Views\Smarty;
|
||||||
use SmartyException;
|
use SmartyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the ViewFactory class.
|
* Unit tests for the ViewFactory class.
|
||||||
*/
|
*/
|
||||||
class ViewFactoryTest extends BaseTest
|
class ViewFactoryTest extends ContainerTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Test the create() function.
|
* Test the create() function.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @throws SmartyException
|
* @throws SmartyException
|
||||||
* @throws DependencyException
|
|
||||||
* @throws ConfigException
|
|
||||||
*/
|
*/
|
||||||
public function testCreate()
|
public function testCreate()
|
||||||
{
|
{
|
||||||
$container = new Container();
|
$view = ViewFactory::create($this->container);
|
||||||
$container['session'] = SessionFactory::create($container);
|
|
||||||
$container['locale'] = LocaleManagerFactory::create($container);
|
|
||||||
$container['config'] = ConfigFactory::create($container);
|
|
||||||
$view = ViewFactory::create($container);
|
|
||||||
$this->assertInstanceOf(Smarty::class, $view);
|
$this->assertInstanceOf(Smarty::class, $view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,17 +32,13 @@ class ViewFactoryTest extends BaseTest
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @throws SmartyException
|
* @throws SmartyException
|
||||||
* @throws DependencyException
|
|
||||||
* @throws ConfigException
|
|
||||||
*/
|
*/
|
||||||
public function testCreateWithXForwardedProto()
|
public function testCreateWithXForwardedProto()
|
||||||
{
|
{
|
||||||
$container = new Container();
|
$view = ViewFactory::create(
|
||||||
$container['session'] = SessionFactory::create($container);
|
$this->container,
|
||||||
$container['locale'] = LocaleManagerFactory::create($container);
|
$this->container->get('request')->withHeader('X-Forwarded-Proto', 'https')
|
||||||
$container['config'] = ConfigFactory::create($container);
|
);
|
||||||
$request = Request::createFromEnvironment(Environment::mock());
|
|
||||||
$view = ViewFactory::create($container, $request->withHeader('X-Forwarded-Proto', 'https'));
|
|
||||||
$this->assertInstanceOf(Smarty::class, $view);
|
$this->assertInstanceOf(Smarty::class, $view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,10 @@
|
||||||
namespace Alltube\Test;
|
namespace Alltube\Test;
|
||||||
|
|
||||||
use Alltube\Exception\ConfigException;
|
use Alltube\Exception\ConfigException;
|
||||||
|
use Alltube\Exception\DependencyException;
|
||||||
use Alltube\Library\Exception\AlltubeLibraryException;
|
use Alltube\Library\Exception\AlltubeLibraryException;
|
||||||
use Alltube\Stream\YoutubeChunkStream;
|
use Alltube\Stream\YoutubeChunkStream;
|
||||||
|
use SmartyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the YoutubeChunkStream class.
|
* Unit tests for the YoutubeChunkStream class.
|
||||||
|
@ -18,8 +20,11 @@ class YoutubeChunkStreamTest extends StreamTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Prepare tests.
|
* Prepare tests.
|
||||||
|
*
|
||||||
* @throws AlltubeLibraryException
|
* @throws AlltubeLibraryException
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
|
* @throws DependencyException
|
||||||
|
* @throws SmartyException
|
||||||
*/
|
*/
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,8 +7,10 @@
|
||||||
namespace Alltube\Test;
|
namespace Alltube\Test;
|
||||||
|
|
||||||
use Alltube\Exception\ConfigException;
|
use Alltube\Exception\ConfigException;
|
||||||
|
use Alltube\Exception\DependencyException;
|
||||||
use Alltube\Library\Exception\AlltubeLibraryException;
|
use Alltube\Library\Exception\AlltubeLibraryException;
|
||||||
use Alltube\Stream\YoutubeStream;
|
use Alltube\Stream\YoutubeStream;
|
||||||
|
use SmartyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the YoutubeStream class.
|
* Unit tests for the YoutubeStream class.
|
||||||
|
@ -18,8 +20,11 @@ class YoutubeStreamTest extends StreamTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Prepare tests.
|
* Prepare tests.
|
||||||
|
*
|
||||||
* @throws AlltubeLibraryException
|
* @throws AlltubeLibraryException
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
|
* @throws DependencyException
|
||||||
|
* @throws SmartyException
|
||||||
*/
|
*/
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue