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.
This commit is contained in:
Jan Tojnar 2022-06-07 23:22:33 +02:00 committed by GitHub
parent 90d22f0d80
commit 44e8007d9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 34 additions and 4 deletions

View File

@ -39,6 +39,11 @@
"ext-sqlite3": "Allows to use an SQLite database for caching", "ext-sqlite3": "Allows to use an SQLite database for caching",
"ext-dom": "Allows to use some bridges based on XPath expressions" "ext-dom": "Allows to use some bridges based on XPath expressions"
}, },
"autoload-dev": {
"psr-4": {
"RssBridge\\Tests\\": "tests"
}
},
"scripts": { "scripts": {
"test": "./vendor/bin/phpunit", "test": "./vendor/bin/phpunit",
"lint": "./vendor/bin/phpcs --standard=phpcs.xml --warning-severity=0 --extensions=php -p ./", "lint": "./vendor/bin/phpcs --standard=phpcs.xml --warning-severity=0 --extensions=php -p ./",

View File

@ -1,5 +1,9 @@
<?php <?php
namespace RssBridge\Tests\Actions;
use ActionAbstract;
use ActionInterface;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class ActionImplementationTest extends TestCase { class ActionImplementationTest extends TestCase {
@ -48,7 +52,7 @@ class ActionImplementationTest extends TestCase {
} }
private function setAction($path) { private function setAction($path) {
$this->class = basename($path, '.php'); $this->class = '\\' . basename($path, '.php');
$this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist'); $this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist');
$this->obj = new $this->class(); $this->obj = new $this->class();
} }

View File

@ -1,5 +1,9 @@
<?php <?php
namespace RssBridge\Tests\Actions;
use ActionFactory;
use BridgeFactory;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class ListActionTest extends TestCase { class ListActionTest extends TestCase {

View File

@ -1,5 +1,11 @@
<?php <?php
namespace RssBridge\Tests\Bridges;
use BridgeAbstract;
use BridgeInterface;
use FeedExpander;
use PixivBridge;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class BridgeImplementationTest extends TestCase { class BridgeImplementationTest extends TestCase {
@ -216,7 +222,7 @@ class BridgeImplementationTest extends TestCase {
} }
private function setBridge($path) { private function setBridge($path) {
$this->class = basename($path, '.php'); $this->class = '\\' . basename($path, '.php');
$this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist'); $this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist');
$this->obj = new $this->class(); $this->obj = new $this->class();
} }

View File

@ -1,5 +1,8 @@
<?php <?php
namespace RssBridge\Tests\Caches;
use CacheInterface;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class CacheImplementationTest extends TestCase { class CacheImplementationTest extends TestCase {
@ -34,7 +37,7 @@ class CacheImplementationTest extends TestCase {
} }
private function setCache($path) { private function setCache($path) {
$this->class = basename($path, '.php'); $this->class = '\\' . basename($path, '.php');
$this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist'); $this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist');
} }
} }

View File

@ -4,6 +4,9 @@
* https://tools.ietf.org/html/rfc4287 * https://tools.ietf.org/html/rfc4287
*/ */
namespace RssBridge\Tests\Formats;
use FormatFactory;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class AtomFormatTest extends TestCase { class AtomFormatTest extends TestCase {

View File

@ -3,8 +3,10 @@
* JsonFormat - JSON Feed Version 1 * JsonFormat - JSON Feed Version 1
* https://jsonfeed.org/version/1 * https://jsonfeed.org/version/1
*/ */
require_once __DIR__ . '/../lib/rssbridge.php';
namespace RssBridge\Tests\Formats;
use FormatFactory;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class JsonFormatTest extends TestCase { class JsonFormatTest extends TestCase {

View File

@ -5,6 +5,9 @@
* http://www.rssboard.org/media-rss * http://www.rssboard.org/media-rss
*/ */
namespace RssBridge\Tests\Formats;
use FormatFactory;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class MrssFormatTest extends TestCase { class MrssFormatTest extends TestCase {