alltube/tests/JsonControllerTest.php
2020-07-15 23:38:23 +02:00

63 lines
1.3 KiB
PHP

<?php
/**
* JsonControllerTest class.
*/
namespace Alltube\Test;
use Alltube\Controller\JsonController;
use Alltube\Exception\ConfigException;
use Alltube\Exception\DependencyException;
use Alltube\Library\Exception\YoutubedlException;
use SmartyException;
/**
* Unit tests for the FrontController class.
*/
class JsonControllerTest extends ControllerTest
{
/**
* Prepare tests.
* @throws ConfigException|SmartyException|DependencyException
*/
protected function setUp(): void
{
parent::setUp();
$this->controller = new JsonController($this->container);
}
/**
* Test the json() function.
*
* @return void
* @requires download
*/
public function testJson()
{
$this->assertRequestIsOk('json', ['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU']);
}
/**
* Test the json() function with an error.
*
* @return void
* @requires download
*/
public function testJsonWithError()
{
$this->expectException(YoutubedlException::class);
$this->getRequestResult('json', ['url' => 'http://example.com/foo']);
}
/**
* Test the json() function without the URL parameter.
*
* @return void
*/
public function testJsonWithoutUrl()
{
$this->assertRequestIsClientError('json');
}
}