From d62b9773940cb8f110899ba4737be173d8f21da7 Mon Sep 17 00:00:00 2001 From: Dag Date: Wed, 13 Apr 2022 21:04:10 +0200 Subject: [PATCH] refactor: ./tests (#2649) * refactor: ./tests * test: consolidate testsuites * refactor: move config setup into rssbridge.php Makes it easier to unit test. * lint --- index.php | 6 +----- lib/rssbridge.php | 4 ++++ phpunit.xml | 11 +++-------- tests/ActionImplementationTest.php | 3 --- tests/AtomFormatTest.php | 6 ++---- tests/BridgeImplementationTest.php | 7 +++---- tests/CacheImplementationTest.php | 1 - tests/FormatImplementationTest.php | 3 --- tests/JsonFormatTest.php | 5 ++--- tests/ListActionTest.php | 10 +++------- tests/MrssFormatTest.php | 6 ++---- 11 files changed, 20 insertions(+), 42 deletions(-) diff --git a/index.php b/index.php index dc6b8938..87c4c546 100644 --- a/index.php +++ b/index.php @@ -1,11 +1,7 @@ - - tests - - - tests - - - tests + + ./tests 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 @@ 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 @@ 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 @@ 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 @@ 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(); }