refactor: ./tests (#2649)

* refactor: ./tests

* test: consolidate testsuites

* refactor: move config setup into rssbridge.php

Makes it easier to unit test.

* lint
This commit is contained in:
Dag 2022-04-13 21:04:10 +02:00 committed by GitHub
parent 183004f954
commit d62b977394
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 20 additions and 42 deletions

View File

@ -1,11 +1,7 @@
<?php <?php
require_once __DIR__ . '/lib/rssbridge.php'; require_once __DIR__ . '/lib/rssbridge.php';
Configuration::verifyInstallation();
Configuration::loadConfiguration();
Authentication::showPromptIfNeeded();
/* /*
Move the CLI arguments to the $_GET array, in order to be able to use Move the CLI arguments to the $_GET array, in order to be able to use
rss-bridge from the command line rss-bridge from the command line

View File

@ -87,3 +87,7 @@ define('MAX_FILE_SIZE', 10000000); /* Allow larger files for simple_html_dom */
require_once PATH_LIB_VENDOR . 'parsedown/Parsedown.php'; require_once PATH_LIB_VENDOR . 'parsedown/Parsedown.php';
require_once PATH_LIB_VENDOR . 'php-urljoin/src/urljoin.php'; require_once PATH_LIB_VENDOR . 'php-urljoin/src/urljoin.php';
require_once PATH_LIB_VENDOR . 'simplehtmldom/simple_html_dom.php'; require_once PATH_LIB_VENDOR . 'simplehtmldom/simple_html_dom.php';
Configuration::verifyInstallation();
Configuration::loadConfiguration();
Authentication::showPromptIfNeeded();

View File

@ -1,6 +1,7 @@
<phpunit <phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
bootstrap="./lib/rssbridge.php"
colors="true" colors="true"
processIsolation="false" processIsolation="false"
timeoutForSmallTests="1" timeoutForSmallTests="1"
@ -8,14 +9,8 @@
timeoutForLargeTests="6" > timeoutForLargeTests="6" >
<testsuites> <testsuites>
<testsuite name="implementations"> <testsuite name="rss-bridge">
<directory suffix="ImplementationTest.php">tests</directory> <directory>./tests</directory>
</testsuite>
<testsuite name="formats">
<directory suffix="FormatTest.php">tests</directory>
</testsuite>
<testsuite name="actions">
<directory suffix="ActionTest.php">tests</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>

View File

@ -1,5 +1,4 @@
<?php <?php
require_once __DIR__ . '/../lib/rssbridge.php';
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -40,8 +39,6 @@ class ActionImplementationTest extends TestCase {
$this->assertEquals($allowedActionAbstract, $methods); $this->assertEquals($allowedActionAbstract, $methods);
} }
////////////////////////////////////////////////////////////////////////////
public function dataActionsProvider() { public function dataActionsProvider() {
$actions = array(); $actions = array();
foreach (glob(PATH_LIB_ACTIONS . '*.php') as $path) { foreach (glob(PATH_LIB_ACTIONS . '*.php') as $path) {

View File

@ -3,7 +3,6 @@
* AtomFormat - RFC 4287: The Atom Syndication Format * AtomFormat - RFC 4287: The Atom Syndication Format
* https://tools.ietf.org/html/rfc4287 * https://tools.ietf.org/html/rfc4287
*/ */
require_once __DIR__ . '/../lib/rssbridge.php';
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -41,8 +40,6 @@ class AtomFormatTest extends TestCase {
$this->assertXmlStringEqualsXmlFile($this->sample->expected, $this->data); $this->assertXmlStringEqualsXmlFile($this->sample->expected, $this->data);
} }
////////////////////////////////////////////////////////////////////////////
public function sampleProvider() { public function sampleProvider() {
$samples = array(); $samples = array();
foreach (glob(self::PATH_SAMPLES . '*.json') as $path) { foreach (glob(self::PATH_SAMPLES . '*.json') as $path) {
@ -84,7 +81,8 @@ class AtomFormatTest extends TestCase {
$this->format->setExtraInfos($this->sample->meta); $this->format->setExtraInfos($this->sample->meta);
$this->format->setLastModified(strtotime('2000-01-01 12:00:00 UTC')); $this->format->setLastModified(strtotime('2000-01-01 12:00:00 UTC'));
$this->data = $this->getActualOutput($this->format->display()); $_ = $this->format->display();
$this->data = $this->getActualOutput();
$this->assertNotFalse(simplexml_load_string($this->data)); $this->assertNotFalse(simplexml_load_string($this->data));
ob_clean(); ob_clean();
} }

View File

@ -1,5 +1,4 @@
<?php <?php
require_once __DIR__ . '/../lib/rssbridge.php';
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -52,7 +51,9 @@ class BridgeImplementationTest extends TestCase {
$this->setBridge($path); $this->setBridge($path);
$multiMinimum = 2; $multiMinimum = 2;
if (isset($this->obj::PARAMETERS['global'])) ++$multiMinimum; if (isset($this->obj::PARAMETERS['global'])) {
++$multiMinimum;
}
$multiContexts = (count($this->obj::PARAMETERS) >= $multiMinimum); $multiContexts = (count($this->obj::PARAMETERS) >= $multiMinimum);
$paramsSeen = array(); $paramsSeen = array();
@ -202,8 +203,6 @@ class BridgeImplementationTest extends TestCase {
$this->checkUrl($this->obj->getURI()); $this->checkUrl($this->obj->getURI());
} }
////////////////////////////////////////////////////////////////////////////
public function dataBridgesProvider() { public function dataBridgesProvider() {
$bridges = array(); $bridges = array();
foreach (glob(PATH_LIB_BRIDGES . '*.php') as $path) { foreach (glob(PATH_LIB_BRIDGES . '*.php') as $path) {

View File

@ -1,5 +1,4 @@
<?php <?php
require_once __DIR__ . '/../lib/rssbridge.php';
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;

View File

@ -1,5 +1,4 @@
<?php <?php
require_once __DIR__ . '/../lib/rssbridge.php';
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -25,8 +24,6 @@ class FormatImplementationTest extends TestCase {
$this->assertInstanceOf(FormatInterface::class, $this->obj); $this->assertInstanceOf(FormatInterface::class, $this->obj);
} }
////////////////////////////////////////////////////////////////////////////
public function dataFormatsProvider() { public function dataFormatsProvider() {
$formats = array(); $formats = array();
foreach (glob(PATH_LIB_FORMATS . '*.php') as $path) { foreach (glob(PATH_LIB_FORMATS . '*.php') as $path) {

View File

@ -41,8 +41,6 @@ class JsonFormatTest extends TestCase {
$this->assertJsonStringEqualsJsonFile($this->sample->expected, $this->data); $this->assertJsonStringEqualsJsonFile($this->sample->expected, $this->data);
} }
////////////////////////////////////////////////////////////////////////////
public function sampleProvider() { public function sampleProvider() {
$samples = array(); $samples = array();
foreach (glob(self::PATH_SAMPLES . '*.json') as $path) { foreach (glob(self::PATH_SAMPLES . '*.json') as $path) {
@ -84,7 +82,8 @@ class JsonFormatTest extends TestCase {
$this->format->setExtraInfos($this->sample->meta); $this->format->setExtraInfos($this->sample->meta);
$this->format->setLastModified(strtotime('2000-01-01 12:00:00 UTC')); $this->format->setLastModified(strtotime('2000-01-01 12:00:00 UTC'));
$this->data = $this->getActualOutput($this->format->display()); $_ = $this->format->display();
$this->data = $this->getActualOutput();
$this->assertNotNull(json_decode($this->data), 'invalid JSON output: ' . json_last_error_msg()); $this->assertNotNull(json_decode($this->data), 'invalid JSON output: ' . json_last_error_msg());
ob_clean(); ob_clean();
} }

View File

@ -1,11 +1,9 @@
<?php <?php
require_once __DIR__ . '/../lib/rssbridge.php';
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class ListActionTest extends TestCase { class ListActionTest extends TestCase {
private $action;
private $data; private $data;
/** /**
@ -75,17 +73,15 @@ class ListActionTest extends TestCase {
} }
} }
////////////////////////////////////////////////////////////////////////////
private function initAction() { private function initAction() {
$actionFac = new ActionFactory(); $actionFac = new ActionFactory();
$actionFac->setWorkingDir(PATH_LIB_ACTIONS); $actionFac->setWorkingDir(PATH_LIB_ACTIONS);
$this->action = $actionFac->create('list'); $action = $actionFac->create('list');
$this->action->setUserData(array()); /* no user data required */ $action->setUserData(array()); /* no user data required */
ob_start(); ob_start();
$this->action->execute(); $action->execute();
$this->data = ob_get_contents(); $this->data = ob_get_contents();
ob_clean(); ob_clean();
ob_end_flush(); ob_end_flush();

View File

@ -4,7 +4,6 @@
* http://www.rssboard.org/rss-specification * http://www.rssboard.org/rss-specification
* http://www.rssboard.org/media-rss * http://www.rssboard.org/media-rss
*/ */
require_once __DIR__ . '/../lib/rssbridge.php';
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -42,8 +41,6 @@ class MrssFormatTest extends TestCase {
$this->assertXmlStringEqualsXmlFile($this->sample->expected, $this->data); $this->assertXmlStringEqualsXmlFile($this->sample->expected, $this->data);
} }
////////////////////////////////////////////////////////////////////////////
public function sampleProvider() { public function sampleProvider() {
$samples = array(); $samples = array();
foreach (glob(self::PATH_SAMPLES . '*.json') as $path) { foreach (glob(self::PATH_SAMPLES . '*.json') as $path) {
@ -85,7 +82,8 @@ class MrssFormatTest extends TestCase {
$this->format->setExtraInfos($this->sample->meta); $this->format->setExtraInfos($this->sample->meta);
$this->format->setLastModified(strtotime('2000-01-01 12:00:00 UTC')); $this->format->setLastModified(strtotime('2000-01-01 12:00:00 UTC'));
$this->data = $this->getActualOutput($this->format->display()); $_ = $this->format->display();
$this->data = $this->getActualOutput();
$this->assertNotFalse(simplexml_load_string($this->data)); $this->assertNotFalse(simplexml_load_string($this->data));
ob_clean(); ob_clean();
} }