From 44e8007d9c85489438ff0b4e011bd418a3d26317 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Tue, 7 Jun 2022 23:22:33 +0200 Subject: [PATCH] tests: Use PSR-4-style namespaces (#2778) We cannot yet switch to namespaces for RSS-Bridge itself but for tests we are not limited by BC. It does not actually do anything since PHPUnit will search for the test files without the help of the autoloader but it still makes the directory cleaner. --- composer.json | 5 +++++ tests/{ => Actions}/ActionImplementationTest.php | 6 +++++- tests/{ => Actions}/ListActionTest.php | 4 ++++ tests/{ => Bridges}/BridgeImplementationTest.php | 8 +++++++- tests/{ => Caches}/CacheImplementationTest.php | 5 ++++- tests/{ => Formats}/AtomFormatTest.php | 3 +++ tests/{ => Formats}/FormatImplementationTest.php | 0 tests/{ => Formats}/JsonFormatTest.php | 4 +++- tests/{ => Formats}/MrssFormatTest.php | 3 +++ .../samples/expectedAtomFormat/feed.common.xml | 0 .../samples/expectedAtomFormat/feed.empty.xml | 0 .../samples/expectedAtomFormat/feed.emptyItems.xml | 0 .../samples/expectedAtomFormat/feed.microblog.xml | 0 .../samples/expectedJsonFormat/feed.common.json | 0 .../samples/expectedJsonFormat/feed.empty.json | 0 .../samples/expectedJsonFormat/feed.emptyItems.json | 0 .../samples/expectedJsonFormat/feed.microblog.json | 0 .../samples/expectedMrssFormat/feed.common.xml | 0 .../samples/expectedMrssFormat/feed.empty.xml | 0 .../samples/expectedMrssFormat/feed.emptyItems.xml | 0 .../samples/expectedMrssFormat/feed.microblog.xml | 0 tests/{ => Formats}/samples/feed.common.json | 0 tests/{ => Formats}/samples/feed.empty.json | 0 tests/{ => Formats}/samples/feed.emptyItems.json | 0 tests/{ => Formats}/samples/feed.microblog.json | 0 25 files changed, 34 insertions(+), 4 deletions(-) rename tests/{ => Actions}/ActionImplementationTest.php (91%) rename tests/{ => Actions}/ListActionTest.php (96%) rename tests/{ => Bridges}/BridgeImplementationTest.php (97%) rename tests/{ => Caches}/CacheImplementationTest.php (91%) rename tests/{ => Formats}/AtomFormatTest.php (97%) rename tests/{ => Formats}/FormatImplementationTest.php (100%) rename tests/{ => Formats}/JsonFormatTest.php (97%) rename tests/{ => Formats}/MrssFormatTest.php (97%) rename tests/{ => Formats}/samples/expectedAtomFormat/feed.common.xml (100%) rename tests/{ => Formats}/samples/expectedAtomFormat/feed.empty.xml (100%) rename tests/{ => Formats}/samples/expectedAtomFormat/feed.emptyItems.xml (100%) rename tests/{ => Formats}/samples/expectedAtomFormat/feed.microblog.xml (100%) rename tests/{ => Formats}/samples/expectedJsonFormat/feed.common.json (100%) rename tests/{ => Formats}/samples/expectedJsonFormat/feed.empty.json (100%) rename tests/{ => Formats}/samples/expectedJsonFormat/feed.emptyItems.json (100%) rename tests/{ => Formats}/samples/expectedJsonFormat/feed.microblog.json (100%) rename tests/{ => Formats}/samples/expectedMrssFormat/feed.common.xml (100%) rename tests/{ => Formats}/samples/expectedMrssFormat/feed.empty.xml (100%) rename tests/{ => Formats}/samples/expectedMrssFormat/feed.emptyItems.xml (100%) rename tests/{ => Formats}/samples/expectedMrssFormat/feed.microblog.xml (100%) rename tests/{ => Formats}/samples/feed.common.json (100%) rename tests/{ => Formats}/samples/feed.empty.json (100%) rename tests/{ => Formats}/samples/feed.emptyItems.json (100%) rename tests/{ => Formats}/samples/feed.microblog.json (100%) diff --git a/composer.json b/composer.json index 5243f583..c6b1b378 100644 --- a/composer.json +++ b/composer.json @@ -39,6 +39,11 @@ "ext-sqlite3": "Allows to use an SQLite database for caching", "ext-dom": "Allows to use some bridges based on XPath expressions" }, + "autoload-dev": { + "psr-4": { + "RssBridge\\Tests\\": "tests" + } + }, "scripts": { "test": "./vendor/bin/phpunit", "lint": "./vendor/bin/phpcs --standard=phpcs.xml --warning-severity=0 --extensions=php -p ./", diff --git a/tests/ActionImplementationTest.php b/tests/Actions/ActionImplementationTest.php similarity index 91% rename from tests/ActionImplementationTest.php rename to tests/Actions/ActionImplementationTest.php index 7a3c33f5..b10d44e5 100644 --- a/tests/ActionImplementationTest.php +++ b/tests/Actions/ActionImplementationTest.php @@ -1,5 +1,9 @@ class = basename($path, '.php'); + $this->class = '\\' . basename($path, '.php'); $this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist'); $this->obj = new $this->class(); } diff --git a/tests/ListActionTest.php b/tests/Actions/ListActionTest.php similarity index 96% rename from tests/ListActionTest.php rename to tests/Actions/ListActionTest.php index e914b7d3..e5ef9570 100644 --- a/tests/ListActionTest.php +++ b/tests/Actions/ListActionTest.php @@ -1,5 +1,9 @@ class = basename($path, '.php'); + $this->class = '\\' . basename($path, '.php'); $this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist'); $this->obj = new $this->class(); } diff --git a/tests/CacheImplementationTest.php b/tests/Caches/CacheImplementationTest.php similarity index 91% rename from tests/CacheImplementationTest.php rename to tests/Caches/CacheImplementationTest.php index 1e430998..12018685 100644 --- a/tests/CacheImplementationTest.php +++ b/tests/Caches/CacheImplementationTest.php @@ -1,5 +1,8 @@ class = basename($path, '.php'); + $this->class = '\\' . basename($path, '.php'); $this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist'); } } diff --git a/tests/AtomFormatTest.php b/tests/Formats/AtomFormatTest.php similarity index 97% rename from tests/AtomFormatTest.php rename to tests/Formats/AtomFormatTest.php index 1d692c40..73268cb7 100644 --- a/tests/AtomFormatTest.php +++ b/tests/Formats/AtomFormatTest.php @@ -4,6 +4,9 @@ * https://tools.ietf.org/html/rfc4287 */ +namespace RssBridge\Tests\Formats; + +use FormatFactory; use PHPUnit\Framework\TestCase; class AtomFormatTest extends TestCase { diff --git a/tests/FormatImplementationTest.php b/tests/Formats/FormatImplementationTest.php similarity index 100% rename from tests/FormatImplementationTest.php rename to tests/Formats/FormatImplementationTest.php diff --git a/tests/JsonFormatTest.php b/tests/Formats/JsonFormatTest.php similarity index 97% rename from tests/JsonFormatTest.php rename to tests/Formats/JsonFormatTest.php index 9b536c18..d99c55b3 100644 --- a/tests/JsonFormatTest.php +++ b/tests/Formats/JsonFormatTest.php @@ -3,8 +3,10 @@ * JsonFormat - JSON Feed Version 1 * https://jsonfeed.org/version/1 */ -require_once __DIR__ . '/../lib/rssbridge.php'; +namespace RssBridge\Tests\Formats; + +use FormatFactory; use PHPUnit\Framework\TestCase; class JsonFormatTest extends TestCase { diff --git a/tests/MrssFormatTest.php b/tests/Formats/MrssFormatTest.php similarity index 97% rename from tests/MrssFormatTest.php rename to tests/Formats/MrssFormatTest.php index ed7dc3a3..3becd8eb 100644 --- a/tests/MrssFormatTest.php +++ b/tests/Formats/MrssFormatTest.php @@ -5,6 +5,9 @@ * http://www.rssboard.org/media-rss */ +namespace RssBridge\Tests\Formats; + +use FormatFactory; use PHPUnit\Framework\TestCase; class MrssFormatTest extends TestCase { diff --git a/tests/samples/expectedAtomFormat/feed.common.xml b/tests/Formats/samples/expectedAtomFormat/feed.common.xml similarity index 100% rename from tests/samples/expectedAtomFormat/feed.common.xml rename to tests/Formats/samples/expectedAtomFormat/feed.common.xml diff --git a/tests/samples/expectedAtomFormat/feed.empty.xml b/tests/Formats/samples/expectedAtomFormat/feed.empty.xml similarity index 100% rename from tests/samples/expectedAtomFormat/feed.empty.xml rename to tests/Formats/samples/expectedAtomFormat/feed.empty.xml diff --git a/tests/samples/expectedAtomFormat/feed.emptyItems.xml b/tests/Formats/samples/expectedAtomFormat/feed.emptyItems.xml similarity index 100% rename from tests/samples/expectedAtomFormat/feed.emptyItems.xml rename to tests/Formats/samples/expectedAtomFormat/feed.emptyItems.xml diff --git a/tests/samples/expectedAtomFormat/feed.microblog.xml b/tests/Formats/samples/expectedAtomFormat/feed.microblog.xml similarity index 100% rename from tests/samples/expectedAtomFormat/feed.microblog.xml rename to tests/Formats/samples/expectedAtomFormat/feed.microblog.xml diff --git a/tests/samples/expectedJsonFormat/feed.common.json b/tests/Formats/samples/expectedJsonFormat/feed.common.json similarity index 100% rename from tests/samples/expectedJsonFormat/feed.common.json rename to tests/Formats/samples/expectedJsonFormat/feed.common.json diff --git a/tests/samples/expectedJsonFormat/feed.empty.json b/tests/Formats/samples/expectedJsonFormat/feed.empty.json similarity index 100% rename from tests/samples/expectedJsonFormat/feed.empty.json rename to tests/Formats/samples/expectedJsonFormat/feed.empty.json diff --git a/tests/samples/expectedJsonFormat/feed.emptyItems.json b/tests/Formats/samples/expectedJsonFormat/feed.emptyItems.json similarity index 100% rename from tests/samples/expectedJsonFormat/feed.emptyItems.json rename to tests/Formats/samples/expectedJsonFormat/feed.emptyItems.json diff --git a/tests/samples/expectedJsonFormat/feed.microblog.json b/tests/Formats/samples/expectedJsonFormat/feed.microblog.json similarity index 100% rename from tests/samples/expectedJsonFormat/feed.microblog.json rename to tests/Formats/samples/expectedJsonFormat/feed.microblog.json diff --git a/tests/samples/expectedMrssFormat/feed.common.xml b/tests/Formats/samples/expectedMrssFormat/feed.common.xml similarity index 100% rename from tests/samples/expectedMrssFormat/feed.common.xml rename to tests/Formats/samples/expectedMrssFormat/feed.common.xml diff --git a/tests/samples/expectedMrssFormat/feed.empty.xml b/tests/Formats/samples/expectedMrssFormat/feed.empty.xml similarity index 100% rename from tests/samples/expectedMrssFormat/feed.empty.xml rename to tests/Formats/samples/expectedMrssFormat/feed.empty.xml diff --git a/tests/samples/expectedMrssFormat/feed.emptyItems.xml b/tests/Formats/samples/expectedMrssFormat/feed.emptyItems.xml similarity index 100% rename from tests/samples/expectedMrssFormat/feed.emptyItems.xml rename to tests/Formats/samples/expectedMrssFormat/feed.emptyItems.xml diff --git a/tests/samples/expectedMrssFormat/feed.microblog.xml b/tests/Formats/samples/expectedMrssFormat/feed.microblog.xml similarity index 100% rename from tests/samples/expectedMrssFormat/feed.microblog.xml rename to tests/Formats/samples/expectedMrssFormat/feed.microblog.xml diff --git a/tests/samples/feed.common.json b/tests/Formats/samples/feed.common.json similarity index 100% rename from tests/samples/feed.common.json rename to tests/Formats/samples/feed.common.json diff --git a/tests/samples/feed.empty.json b/tests/Formats/samples/feed.empty.json similarity index 100% rename from tests/samples/feed.empty.json rename to tests/Formats/samples/feed.empty.json diff --git a/tests/samples/feed.emptyItems.json b/tests/Formats/samples/feed.emptyItems.json similarity index 100% rename from tests/samples/feed.emptyItems.json rename to tests/Formats/samples/feed.emptyItems.json diff --git a/tests/samples/feed.microblog.json b/tests/Formats/samples/feed.microblog.json similarity index 100% rename from tests/samples/feed.microblog.json rename to tests/Formats/samples/feed.microblog.json