diff options
author | 2022-04-13 21:04:10 +0200 | |
---|---|---|
committer | 2022-04-13 21:04:10 +0200 | |
commit | d62b9773940cb8f110899ba4737be173d8f21da7 (patch) | |
tree | 6825283980fcaafb7aa5774b68405a5759af67c4 | |
parent | 183004f954fe139236e7373e335be4189d37837d (diff) | |
download | rss-bridge-d62b9773940cb8f110899ba4737be173d8f21da7.tar.gz rss-bridge-d62b9773940cb8f110899ba4737be173d8f21da7.tar.zst rss-bridge-d62b9773940cb8f110899ba4737be173d8f21da7.zip |
refactor: ./tests (#2649)
* refactor: ./tests
* test: consolidate testsuites
* refactor: move config setup into rssbridge.php
Makes it easier to unit test.
* lint
-rw-r--r-- | index.php | 6 | ||||
-rw-r--r-- | lib/rssbridge.php | 4 | ||||
-rw-r--r-- | phpunit.xml | 11 | ||||
-rw-r--r-- | tests/ActionImplementationTest.php | 3 | ||||
-rw-r--r-- | tests/AtomFormatTest.php | 6 | ||||
-rw-r--r-- | tests/BridgeImplementationTest.php | 7 | ||||
-rw-r--r-- | tests/CacheImplementationTest.php | 1 | ||||
-rw-r--r-- | tests/FormatImplementationTest.php | 3 | ||||
-rw-r--r-- | tests/JsonFormatTest.php | 5 | ||||
-rw-r--r-- | tests/ListActionTest.php | 10 | ||||
-rw-r--r-- | tests/MrssFormatTest.php | 6 |
11 files changed, 20 insertions, 42 deletions
@@ -1,10 +1,6 @@ <?php -require_once __DIR__ . '/lib/rssbridge.php'; - -Configuration::verifyInstallation(); -Configuration::loadConfiguration(); -Authentication::showPromptIfNeeded(); +require_once __DIR__ . '/lib/rssbridge.php'; /* Move the CLI arguments to the $_GET array, in order to be able to use diff --git a/lib/rssbridge.php b/lib/rssbridge.php index 47a92e73..d74af3c3 100644 --- a/lib/rssbridge.php +++ b/lib/rssbridge.php @@ -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 . 'php-urljoin/src/urljoin.php'; require_once PATH_LIB_VENDOR . 'simplehtmldom/simple_html_dom.php'; + +Configuration::verifyInstallation(); +Configuration::loadConfiguration(); +Authentication::showPromptIfNeeded(); diff --git a/phpunit.xml b/phpunit.xml index 62937c47..c1f529d5 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,7 @@ <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd" + bootstrap="./lib/rssbridge.php" colors="true" processIsolation="false" timeoutForSmallTests="1" @@ -8,14 +9,8 @@ timeoutForLargeTests="6" > <testsuites> - <testsuite name="implementations"> - <directory suffix="ImplementationTest.php">tests</directory> - </testsuite> - <testsuite name="formats"> - <directory suffix="FormatTest.php">tests</directory> - </testsuite> - <testsuite name="actions"> - <directory suffix="ActionTest.php">tests</directory> + <testsuite name="rss-bridge"> + <directory>./tests</directory> </testsuite> </testsuites> diff --git a/tests/ActionImplementationTest.php b/tests/ActionImplementationTest.php index 554432f3..6a36c2f1 100644 --- a/tests/ActionImplementationTest.php +++ b/tests/ActionImplementationTest.php @@ -1,5 +1,4 @@ <?php -require_once __DIR__ . '/../lib/rssbridge.php'; use PHPUnit\Framework\TestCase; @@ -40,8 +39,6 @@ class ActionImplementationTest extends TestCase { $this->assertEquals($allowedActionAbstract, $methods); } - //////////////////////////////////////////////////////////////////////////// - public function dataActionsProvider() { $actions = array(); foreach (glob(PATH_LIB_ACTIONS . '*.php') as $path) { diff --git a/tests/AtomFormatTest.php b/tests/AtomFormatTest.php index 818b82eb..91d6c1d8 100644 --- a/tests/AtomFormatTest.php +++ b/tests/AtomFormatTest.php @@ -3,7 +3,6 @@ * AtomFormat - RFC 4287: The Atom Syndication Format * https://tools.ietf.org/html/rfc4287 */ -require_once __DIR__ . '/../lib/rssbridge.php'; use PHPUnit\Framework\TestCase; @@ -41,8 +40,6 @@ class AtomFormatTest extends TestCase { $this->assertXmlStringEqualsXmlFile($this->sample->expected, $this->data); } - //////////////////////////////////////////////////////////////////////////// - public function sampleProvider() { $samples = array(); foreach (glob(self::PATH_SAMPLES . '*.json') as $path) { @@ -84,7 +81,8 @@ class AtomFormatTest extends TestCase { $this->format->setExtraInfos($this->sample->meta); $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)); ob_clean(); } diff --git a/tests/BridgeImplementationTest.php b/tests/BridgeImplementationTest.php index e634aacf..28d8ec1e 100644 --- a/tests/BridgeImplementationTest.php +++ b/tests/BridgeImplementationTest.php @@ -1,5 +1,4 @@ <?php -require_once __DIR__ . '/../lib/rssbridge.php'; use PHPUnit\Framework\TestCase; @@ -52,7 +51,9 @@ class BridgeImplementationTest extends TestCase { $this->setBridge($path); $multiMinimum = 2; - if (isset($this->obj::PARAMETERS['global'])) ++$multiMinimum; + if (isset($this->obj::PARAMETERS['global'])) { + ++$multiMinimum; + } $multiContexts = (count($this->obj::PARAMETERS) >= $multiMinimum); $paramsSeen = array(); @@ -202,8 +203,6 @@ class BridgeImplementationTest extends TestCase { $this->checkUrl($this->obj->getURI()); } - //////////////////////////////////////////////////////////////////////////// - public function dataBridgesProvider() { $bridges = array(); foreach (glob(PATH_LIB_BRIDGES . '*.php') as $path) { diff --git a/tests/CacheImplementationTest.php b/tests/CacheImplementationTest.php index 25189134..68741d8b 100644 --- a/tests/CacheImplementationTest.php +++ b/tests/CacheImplementationTest.php @@ -1,5 +1,4 @@ <?php -require_once __DIR__ . '/../lib/rssbridge.php'; use PHPUnit\Framework\TestCase; diff --git a/tests/FormatImplementationTest.php b/tests/FormatImplementationTest.php index f2df6350..d4d7249f 100644 --- a/tests/FormatImplementationTest.php +++ b/tests/FormatImplementationTest.php @@ -1,5 +1,4 @@ <?php -require_once __DIR__ . '/../lib/rssbridge.php'; use PHPUnit\Framework\TestCase; @@ -25,8 +24,6 @@ class FormatImplementationTest extends TestCase { $this->assertInstanceOf(FormatInterface::class, $this->obj); } - //////////////////////////////////////////////////////////////////////////// - public function dataFormatsProvider() { $formats = array(); foreach (glob(PATH_LIB_FORMATS . '*.php') as $path) { diff --git a/tests/JsonFormatTest.php b/tests/JsonFormatTest.php index a9417e25..9e19fe8f 100644 --- a/tests/JsonFormatTest.php +++ b/tests/JsonFormatTest.php @@ -41,8 +41,6 @@ class JsonFormatTest extends TestCase { $this->assertJsonStringEqualsJsonFile($this->sample->expected, $this->data); } - //////////////////////////////////////////////////////////////////////////// - public function sampleProvider() { $samples = array(); foreach (glob(self::PATH_SAMPLES . '*.json') as $path) { @@ -84,7 +82,8 @@ class JsonFormatTest extends TestCase { $this->format->setExtraInfos($this->sample->meta); $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()); ob_clean(); } diff --git a/tests/ListActionTest.php b/tests/ListActionTest.php index 6d22b916..f15e1b73 100644 --- a/tests/ListActionTest.php +++ b/tests/ListActionTest.php @@ -1,11 +1,9 @@ <?php -require_once __DIR__ . '/../lib/rssbridge.php'; use PHPUnit\Framework\TestCase; class ListActionTest extends TestCase { - private $action; private $data; /** @@ -75,17 +73,15 @@ class ListActionTest extends TestCase { } } - //////////////////////////////////////////////////////////////////////////// - private function initAction() { $actionFac = new ActionFactory(); $actionFac->setWorkingDir(PATH_LIB_ACTIONS); - $this->action = $actionFac->create('list'); - $this->action->setUserData(array()); /* no user data required */ + $action = $actionFac->create('list'); + $action->setUserData(array()); /* no user data required */ ob_start(); - $this->action->execute(); + $action->execute(); $this->data = ob_get_contents(); ob_clean(); ob_end_flush(); diff --git a/tests/MrssFormatTest.php b/tests/MrssFormatTest.php index 0ddc33c4..5ece3904 100644 --- a/tests/MrssFormatTest.php +++ b/tests/MrssFormatTest.php @@ -4,7 +4,6 @@ * http://www.rssboard.org/rss-specification * http://www.rssboard.org/media-rss */ -require_once __DIR__ . '/../lib/rssbridge.php'; use PHPUnit\Framework\TestCase; @@ -42,8 +41,6 @@ class MrssFormatTest extends TestCase { $this->assertXmlStringEqualsXmlFile($this->sample->expected, $this->data); } - //////////////////////////////////////////////////////////////////////////// - public function sampleProvider() { $samples = array(); foreach (glob(self::PATH_SAMPLES . '*.json') as $path) { @@ -85,7 +82,8 @@ class MrssFormatTest extends TestCase { $this->format->setExtraInfos($this->sample->meta); $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)); ob_clean(); } |