From 830a73dcf6a9079d30790fdf47f6da225666c09d Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 5 Apr 2021 11:00:28 +0200 Subject: [PATCH] Coding style: manually fix remaining errors in tests after PHPCBF Related to #95 --- composer.json | 6 +++ phpcs.xml | 6 +++ tests/ThumbnailerTest.php | 4 +- tests/TimeZoneTest.php | 6 ++- tests/UtilsTest.php | 9 ++-- tests/api/ApiMiddlewareTest.php | 5 +- tests/api/controllers/history/HistoryTest.php | 10 ++-- tests/api/controllers/info/InfoTest.php | 9 ++-- .../api/controllers/links/DeleteLinkTest.php | 8 ++-- tests/api/controllers/links/GetLinkIdTest.php | 7 +-- tests/api/controllers/links/GetLinksTest.php | 9 ++-- tests/api/controllers/links/PostLinkTest.php | 10 ++-- tests/api/controllers/links/PutLinkTest.php | 10 ++-- tests/api/controllers/tags/DeleteTagTest.php | 8 ++-- tests/api/controllers/tags/GetTagNameTest.php | 7 +-- tests/api/controllers/tags/GetTagsTest.php | 7 +-- tests/api/controllers/tags/PutTagTest.php | 10 ++-- tests/bookmark/BookmarkArrayTest.php | 3 +- tests/bookmark/BookmarkFileServiceTest.php | 13 ++--- tests/bookmark/BookmarkFilterTest.php | 7 +-- tests/bookmark/BookmarkInitializerTest.php | 3 +- tests/bookmark/LinkUtilsTest.php | 12 +++-- tests/bootstrap.php | 17 ++++--- tests/config/ConfigPluginTest.php | 7 ++- tests/feed/FeedBuilderTest.php | 29 +++++++++--- .../admin/PluginsControllerTest.php | 2 +- .../visitor/InstallControllerTest.php | 2 +- tests/helper/ApplicationUtilsTest.php | 4 +- tests/helper/DailyPageHelperTest.php | 47 ++++++++++--------- tests/http/HttpUtils/ClientIpIdTest.php | 2 - tests/http/HttpUtils/GetHttpUrlTest.php | 2 - .../HttpUtils/GetIpAdressFromProxyTest.php | 2 - tests/http/HttpUtils/IndexUrlTest.php | 2 - tests/http/HttpUtils/IsHttpsTest.php | 2 - tests/http/HttpUtils/PageUrlTest.php | 2 - tests/http/HttpUtils/ServerUrlTest.php | 2 - tests/http/UrlUtils/CleanupUrlTest.php | 2 - tests/http/UrlUtils/GetUrlSchemeTest.php | 4 +- tests/http/UrlUtils/UnparseUrlTest.php | 4 +- .../http/UrlUtils/WhitelistProtocolsTest.php | 4 +- tests/languages/de/UtilsDeTest.php | 3 +- tests/languages/en/UtilsEnTest.php | 3 +- tests/languages/fr/LanguagesFrTest.php | 6 ++- tests/languages/fr/UtilsFrTest.php | 3 +- tests/legacy/LegacyLinkDBTest.php | 6 +-- tests/legacy/LegacyLinkFilterTest.php | 3 +- tests/legacy/LegacyUpdaterTest.php | 20 ++++---- tests/netscape/BookmarkExportTest.php | 7 ++- tests/plugins/PluginArchiveorgTest.php | 4 -- tests/plugins/PluginIssoTest.php | 15 ++++-- tests/plugins/PluginPlayvideosTest.php | 4 -- tests/plugins/PluginQrcodeTest.php | 4 -- tests/security/SessionManagerTest.php | 3 +- tests/updater/DummyUpdater.php | 3 +- tests/updater/UpdaterTest.php | 6 ++- tests/utils/FakeApplicationUtils.php | 2 +- tests/utils/FakeBookmarkService.php | 8 +--- tests/utils/RainTPL.php | 6 +++ tests/utils/ReferenceHistory.php | 3 ++ tests/utils/ReferenceLinkDB.php | 21 +++++---- tests/utils/ReferenceSessionIdHashes.php | 2 + 61 files changed, 243 insertions(+), 194 deletions(-) create mode 100644 tests/utils/RainTPL.php diff --git a/composer.json b/composer.json index 138319ca..2563906f 100644 --- a/composer.json +++ b/composer.json @@ -71,5 +71,11 @@ "Shaarli\\Updater\\": "application/updater", "Shaarli\\Updater\\Exception\\": "application/updater/exception" } + }, + "autoload-dev": { + "psr-4": { + "Shaarli\\Tests\\": "tests", + "Shaarli\\Tests\\Utils\\": "tests/utils" + } } } diff --git a/phpcs.xml b/phpcs.xml index 0852ab26..a2749b57 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -19,5 +19,11 @@ index.php plugins/* + tests/bootstrap.php + tests/utils/RainTPL.php + + + + tests/utils/RainTPL.php diff --git a/tests/ThumbnailerTest.php b/tests/ThumbnailerTest.php index 8238ad76..f9c7abd4 100644 --- a/tests/ThumbnailerTest.php +++ b/tests/ThumbnailerTest.php @@ -15,9 +15,9 @@ use WebThumbnailer\Application\ConfigManager as WTConfigManager; */ class ThumbnailerTest extends TestCase { - const WIDTH = 190; + protected const WIDTH = 190; - const HEIGHT = 210; + protected const HEIGHT = 210; /** * @var Thumbnailer; diff --git a/tests/TimeZoneTest.php b/tests/TimeZoneTest.php index fcfb2337..ba520cf1 100644 --- a/tests/TimeZoneTest.php +++ b/tests/TimeZoneTest.php @@ -4,12 +4,14 @@ * TimeZone's tests */ -require_once 'application/TimeZone.php'; +namespace Shaarli\Tests; + +use Shaarli\TestCase; /** * Unitary tests for timezone utilities */ -class TimeZoneTest extends \Shaarli\TestCase +class TimeZoneTest extends TestCase { /** * @var array of timezones diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index 4b37387b..a18c01bc 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -4,14 +4,15 @@ * Utilities' tests */ -require_once 'application/Utils.php'; -require_once 'application/Languages.php'; +namespace Shaarli\Tests; +use DateTime; +use Shaarli\TestCase; /** * Unitary tests for Shaarli utilities */ -class UtilsTest extends \Shaarli\TestCase +class UtilsTest extends TestCase { // Log file protected static $testLogFile = 'tests.log'; @@ -55,7 +56,7 @@ class UtilsTest extends \Shaarli\TestCase /** * Returns a list of the elements from the last logged entry * - * @return list (date, ip address, message) + * @return array (date, ip address, message) */ protected function getLastLogEntry() { diff --git a/tests/api/ApiMiddlewareTest.php b/tests/api/ApiMiddlewareTest.php index 983cee3e..6e222681 100644 --- a/tests/api/ApiMiddlewareTest.php +++ b/tests/api/ApiMiddlewareTest.php @@ -5,6 +5,7 @@ namespace Shaarli\Api; use Shaarli\Config\ConfigManager; use Shaarli\History; use Shaarli\Plugin\PluginManager; +use Shaarli\Tests\Utils\ReferenceLinkDB; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; @@ -33,7 +34,7 @@ class ApiMiddlewareTest extends \Shaarli\TestCase protected $conf; /** - * @var \ReferenceLinkDB instance. + * @var ReferenceLinkDB instance. */ protected $refDB = null; @@ -50,7 +51,7 @@ class ApiMiddlewareTest extends \Shaarli\TestCase $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('api.secret', 'NapoleonWasALizard'); - $this->refDB = new \ReferenceLinkDB(); + $this->refDB = new ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); $history = new History('sandbox/history.php'); diff --git a/tests/api/controllers/history/HistoryTest.php b/tests/api/controllers/history/HistoryTest.php index 84f8716e..f0596b91 100644 --- a/tests/api/controllers/history/HistoryTest.php +++ b/tests/api/controllers/history/HistoryTest.php @@ -4,14 +4,14 @@ namespace Shaarli\Api\Controllers; use Shaarli\Config\ConfigManager; use Shaarli\History; +use Shaarli\TestCase; +use Shaarli\Tests\Utils\ReferenceHistory; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; use Slim\Http\Response; -require_once 'tests/utils/ReferenceHistory.php'; - -class HistoryTest extends \Shaarli\TestCase +class HistoryTest extends TestCase { /** * @var string datastore to test write operations @@ -24,7 +24,7 @@ class HistoryTest extends \Shaarli\TestCase protected $conf; /** - * @var \ReferenceHistory instance. + * @var ReferenceHistory instance. */ protected $refHistory = null; @@ -44,7 +44,7 @@ class HistoryTest extends \Shaarli\TestCase protected function setUp(): void { $this->conf = new ConfigManager('tests/utils/config/configJson'); - $this->refHistory = new \ReferenceHistory(); + $this->refHistory = new ReferenceHistory(); $this->refHistory->write(self::$testHistory); $this->container = new Container(); $this->container['conf'] = $this->conf; diff --git a/tests/api/controllers/info/InfoTest.php b/tests/api/controllers/info/InfoTest.php index 17b6e169..2b0fd510 100644 --- a/tests/api/controllers/info/InfoTest.php +++ b/tests/api/controllers/info/InfoTest.php @@ -8,6 +8,7 @@ use Shaarli\Config\ConfigManager; use Shaarli\History; use Shaarli\Plugin\PluginManager; use Shaarli\TestCase; +use Shaarli\Tests\Utils\ReferenceLinkDB; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; @@ -33,7 +34,7 @@ class InfoTest extends TestCase protected $conf; /** - * @var \ReferenceLinkDB instance. + * @var ReferenceLinkDB instance. */ protected $refDB = null; @@ -55,7 +56,7 @@ class InfoTest extends TestCase $mutex = new NoMutex(); $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); - $this->refDB = new \ReferenceLinkDB(); + $this->refDB = new ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); $this->pluginManager = new PluginManager($this->conf); $history = new History('sandbox/history.php'); @@ -96,7 +97,7 @@ class InfoTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); $data = json_decode((string) $response->getBody(), true); - $this->assertEquals(\ReferenceLinkDB::$NB_LINKS_TOTAL, $data['global_counter']); + $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, $data['global_counter']); $this->assertEquals(2, $data['private_counter']); $this->assertEquals('Shaarli', $data['settings']['title']); $this->assertEquals('?', $data['settings']['header_link']); @@ -119,7 +120,7 @@ class InfoTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); $data = json_decode((string) $response->getBody(), true); - $this->assertEquals(\ReferenceLinkDB::$NB_LINKS_TOTAL, $data['global_counter']); + $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, $data['global_counter']); $this->assertEquals(2, $data['private_counter']); $this->assertEquals($title, $data['settings']['title']); $this->assertEquals($headerLink, $data['settings']['header_link']); diff --git a/tests/api/controllers/links/DeleteLinkTest.php b/tests/api/controllers/links/DeleteLinkTest.php index 20010e6f..2c3c3ecc 100644 --- a/tests/api/controllers/links/DeleteLinkTest.php +++ b/tests/api/controllers/links/DeleteLinkTest.php @@ -7,6 +7,8 @@ use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Config\ConfigManager; use Shaarli\History; use Shaarli\Plugin\PluginManager; +use Shaarli\Tests\Utils\ReferenceHistory; +use Shaarli\Tests\Utils\ReferenceLinkDB; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; @@ -30,7 +32,7 @@ class DeleteLinkTest extends \Shaarli\TestCase protected $conf; /** - * @var \ReferenceLinkDB instance. + * @var ReferenceLinkDB instance. */ protected $refDB = null; @@ -68,9 +70,9 @@ class DeleteLinkTest extends \Shaarli\TestCase $this->mutex = new NoMutex(); $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); - $this->refDB = new \ReferenceLinkDB(); + $this->refDB = new ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); - $refHistory = new \ReferenceHistory(); + $refHistory = new ReferenceHistory(); $refHistory->write(self::$testHistory); $this->history = new History(self::$testHistory); $this->pluginManager = new PluginManager($this->conf); diff --git a/tests/api/controllers/links/GetLinkIdTest.php b/tests/api/controllers/links/GetLinkIdTest.php index c93a3b4b..5fbb7505 100644 --- a/tests/api/controllers/links/GetLinkIdTest.php +++ b/tests/api/controllers/links/GetLinkIdTest.php @@ -8,6 +8,7 @@ use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Config\ConfigManager; use Shaarli\History; use Shaarli\Plugin\PluginManager; +use Shaarli\Tests\Utils\ReferenceLinkDB; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; @@ -35,7 +36,7 @@ class GetLinkIdTest extends \Shaarli\TestCase protected $conf; /** - * @var \ReferenceLinkDB instance. + * @var ReferenceLinkDB instance. */ protected $refDB = null; @@ -52,7 +53,7 @@ class GetLinkIdTest extends \Shaarli\TestCase /** * Number of JSON fields per link. */ - const NB_FIELDS_LINK = 9; + protected const NB_FIELDS_LINK = 9; /** * Before each test, instantiate a new Api with its config, plugins and bookmarks. @@ -62,7 +63,7 @@ class GetLinkIdTest extends \Shaarli\TestCase $mutex = new NoMutex(); $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); - $this->refDB = new \ReferenceLinkDB(); + $this->refDB = new ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); $history = new History('sandbox/history.php'); diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php index cd28a63c..217eb5d1 100644 --- a/tests/api/controllers/links/GetLinksTest.php +++ b/tests/api/controllers/links/GetLinksTest.php @@ -9,6 +9,7 @@ use Shaarli\Bookmark\LinkDB; use Shaarli\Config\ConfigManager; use Shaarli\History; use Shaarli\Plugin\PluginManager; +use Shaarli\Tests\Utils\ReferenceLinkDB; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; @@ -36,7 +37,7 @@ class GetLinksTest extends \Shaarli\TestCase protected $conf; /** - * @var \ReferenceLinkDB instance. + * @var ReferenceLinkDB instance. */ protected $refDB = null; @@ -53,7 +54,7 @@ class GetLinksTest extends \Shaarli\TestCase /** * Number of JSON field per link. */ - const NB_FIELDS_LINK = 9; + protected const NB_FIELDS_LINK = 9; /** * Before every test, instantiate a new Api with its config, plugins and bookmarks. @@ -63,7 +64,7 @@ class GetLinksTest extends \Shaarli\TestCase $mutex = new NoMutex(); $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); - $this->refDB = new \ReferenceLinkDB(); + $this->refDB = new ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); $history = new History('sandbox/history.php'); @@ -431,7 +432,7 @@ class GetLinksTest extends \Shaarli\TestCase $response = $this->controller->getLinks($request, new Response()); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode((string) $response->getBody(), true); - $this->assertEquals(\ReferenceLinkDB::$NB_LINKS_TOTAL, count($data)); + $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data)); $this->assertEquals(10, $data[0]['id']); $this->assertEquals(41, $data[2]['id']); diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php index a54e4a16..faf43ee1 100644 --- a/tests/api/controllers/links/PostLinkTest.php +++ b/tests/api/controllers/links/PostLinkTest.php @@ -9,6 +9,8 @@ use Shaarli\Config\ConfigManager; use Shaarli\History; use Shaarli\Plugin\PluginManager; use Shaarli\TestCase; +use Shaarli\Tests\Utils\ReferenceHistory; +use Shaarli\Tests\Utils\ReferenceLinkDB; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; @@ -40,7 +42,7 @@ class PostLinkTest extends TestCase protected $conf; /** - * @var \ReferenceLinkDB instance. + * @var ReferenceLinkDB instance. */ protected $refDB = null; @@ -67,7 +69,7 @@ class PostLinkTest extends TestCase /** * Number of JSON field per link. */ - const NB_FIELDS_LINK = 9; + protected const NB_FIELDS_LINK = 9; /** * Before every test, instantiate a new Api with its config, plugins and bookmarks. @@ -77,9 +79,9 @@ class PostLinkTest extends TestCase $mutex = new NoMutex(); $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); - $this->refDB = new \ReferenceLinkDB(); + $this->refDB = new ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); - $refHistory = new \ReferenceHistory(); + $refHistory = new ReferenceHistory(); $refHistory->write(self::$testHistory); $this->history = new History(self::$testHistory); $pluginManager = new PluginManager($this->conf); diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php index 5220187b..9bd196db 100644 --- a/tests/api/controllers/links/PutLinkTest.php +++ b/tests/api/controllers/links/PutLinkTest.php @@ -8,6 +8,8 @@ use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Config\ConfigManager; use Shaarli\History; use Shaarli\Plugin\PluginManager; +use Shaarli\Tests\Utils\ReferenceHistory; +use Shaarli\Tests\Utils\ReferenceLinkDB; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; @@ -31,7 +33,7 @@ class PutLinkTest extends \Shaarli\TestCase protected $conf; /** - * @var \ReferenceLinkDB instance. + * @var ReferenceLinkDB instance. */ protected $refDB = null; @@ -58,7 +60,7 @@ class PutLinkTest extends \Shaarli\TestCase /** * Number of JSON field per link. */ - const NB_FIELDS_LINK = 9; + protected const NB_FIELDS_LINK = 9; /** * Before every test, instantiate a new Api with its config, plugins and bookmarks. @@ -68,9 +70,9 @@ class PutLinkTest extends \Shaarli\TestCase $mutex = new NoMutex(); $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); - $this->refDB = new \ReferenceLinkDB(); + $this->refDB = new ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); - $refHistory = new \ReferenceHistory(); + $refHistory = new ReferenceHistory(); $refHistory->write(self::$testHistory); $this->history = new History(self::$testHistory); $pluginManager = new PluginManager($this->conf); diff --git a/tests/api/controllers/tags/DeleteTagTest.php b/tests/api/controllers/tags/DeleteTagTest.php index c76f30e8..63a3e264 100644 --- a/tests/api/controllers/tags/DeleteTagTest.php +++ b/tests/api/controllers/tags/DeleteTagTest.php @@ -8,6 +8,8 @@ use Shaarli\Bookmark\LinkDB; use Shaarli\Config\ConfigManager; use Shaarli\History; use Shaarli\Plugin\PluginManager; +use Shaarli\Tests\Utils\ReferenceHistory; +use Shaarli\Tests\Utils\ReferenceLinkDB; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; @@ -31,7 +33,7 @@ class DeleteTagTest extends \Shaarli\TestCase protected $conf; /** - * @var \ReferenceLinkDB instance. + * @var ReferenceLinkDB instance. */ protected $refDB = null; @@ -69,9 +71,9 @@ class DeleteTagTest extends \Shaarli\TestCase $this->mutex = new NoMutex(); $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); - $this->refDB = new \ReferenceLinkDB(); + $this->refDB = new ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); - $refHistory = new \ReferenceHistory(); + $refHistory = new ReferenceHistory(); $refHistory->write(self::$testHistory); $this->history = new History(self::$testHistory); $this->pluginManager = new PluginManager($this->conf); diff --git a/tests/api/controllers/tags/GetTagNameTest.php b/tests/api/controllers/tags/GetTagNameTest.php index 0ad71495..8ba4b83c 100644 --- a/tests/api/controllers/tags/GetTagNameTest.php +++ b/tests/api/controllers/tags/GetTagNameTest.php @@ -8,6 +8,7 @@ use Shaarli\Bookmark\LinkDB; use Shaarli\Config\ConfigManager; use Shaarli\History; use Shaarli\Plugin\PluginManager; +use Shaarli\Tests\Utils\ReferenceLinkDB; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; @@ -33,7 +34,7 @@ class GetTagNameTest extends \Shaarli\TestCase protected $conf; /** - * @var \ReferenceLinkDB instance. + * @var ReferenceLinkDB instance. */ protected $refDB = null; @@ -53,7 +54,7 @@ class GetTagNameTest extends \Shaarli\TestCase /** * Number of JSON fields per link. */ - const NB_FIELDS_TAG = 2; + protected const NB_FIELDS_TAG = 2; /** * Before each test, instantiate a new Api with its config, plugins and bookmarks. @@ -63,7 +64,7 @@ class GetTagNameTest extends \Shaarli\TestCase $mutex = new NoMutex(); $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); - $this->refDB = new \ReferenceLinkDB(); + $this->refDB = new ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); $history = new History('sandbox/history.php'); diff --git a/tests/api/controllers/tags/GetTagsTest.php b/tests/api/controllers/tags/GetTagsTest.php index 64d10f4a..1a183081 100644 --- a/tests/api/controllers/tags/GetTagsTest.php +++ b/tests/api/controllers/tags/GetTagsTest.php @@ -8,6 +8,7 @@ use Shaarli\Bookmark\LinkDB; use Shaarli\Config\ConfigManager; use Shaarli\History; use Shaarli\Plugin\PluginManager; +use Shaarli\Tests\Utils\ReferenceLinkDB; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; @@ -33,7 +34,7 @@ class GetTagsTest extends \Shaarli\TestCase protected $conf; /** - * @var \ReferenceLinkDB instance. + * @var ReferenceLinkDB instance. */ protected $refDB = null; @@ -58,7 +59,7 @@ class GetTagsTest extends \Shaarli\TestCase /** * Number of JSON field per link. */ - const NB_FIELDS_TAG = 2; + protected const NB_FIELDS_TAG = 2; /** * Before every test, instantiate a new Api with its config, plugins and bookmarks. @@ -68,7 +69,7 @@ class GetTagsTest extends \Shaarli\TestCase $mutex = new NoMutex(); $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); - $this->refDB = new \ReferenceLinkDB(); + $this->refDB = new ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); $history = new History('sandbox/history.php'); $this->pluginManager = new PluginManager($this->conf); diff --git a/tests/api/controllers/tags/PutTagTest.php b/tests/api/controllers/tags/PutTagTest.php index 045473e6..b2ebcd52 100644 --- a/tests/api/controllers/tags/PutTagTest.php +++ b/tests/api/controllers/tags/PutTagTest.php @@ -9,6 +9,8 @@ use Shaarli\Bookmark\LinkDB; use Shaarli\Config\ConfigManager; use Shaarli\History; use Shaarli\Plugin\PluginManager; +use Shaarli\Tests\Utils\ReferenceHistory; +use Shaarli\Tests\Utils\ReferenceLinkDB; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; @@ -32,7 +34,7 @@ class PutTagTest extends \Shaarli\TestCase protected $conf; /** - * @var \ReferenceLinkDB instance. + * @var ReferenceLinkDB instance. */ protected $refDB = null; @@ -62,7 +64,7 @@ class PutTagTest extends \Shaarli\TestCase /** * Number of JSON field per link. */ - const NB_FIELDS_TAG = 2; + protected const NB_FIELDS_TAG = 2; /** * Before every test, instantiate a new Api with its config, plugins and bookmarks. @@ -72,9 +74,9 @@ class PutTagTest extends \Shaarli\TestCase $mutex = new NoMutex(); $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); - $this->refDB = new \ReferenceLinkDB(); + $this->refDB = new ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); - $refHistory = new \ReferenceHistory(); + $refHistory = new ReferenceHistory(); $refHistory->write(self::$testHistory); $this->history = new History(self::$testHistory); $this->pluginManager = new PluginManager($this->conf); diff --git a/tests/bookmark/BookmarkArrayTest.php b/tests/bookmark/BookmarkArrayTest.php index 23afec1b..c2f90d66 100644 --- a/tests/bookmark/BookmarkArrayTest.php +++ b/tests/bookmark/BookmarkArrayTest.php @@ -3,6 +3,7 @@ namespace Shaarli\Bookmark; use Shaarli\TestCase; +use Shaarli\Tests\Utils\ReferenceLinkDB; /** * Class BookmarkArrayTest @@ -194,7 +195,7 @@ class BookmarkArrayTest extends TestCase */ public function testReorder() { - $refDB = new \ReferenceLinkDB(); + $refDB = new ReferenceLinkDB(); $refDB->write('sandbox/datastore.php'); diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php index a6a91152..c12cd2b0 100644 --- a/tests/bookmark/BookmarkFileServiceTest.php +++ b/tests/bookmark/BookmarkFileServiceTest.php @@ -8,7 +8,6 @@ namespace Shaarli\Bookmark; use DateTime; use malkusch\lock\mutex\NoMutex; -use ReferenceLinkDB; use ReflectionClass; use Shaarli; use Shaarli\Bookmark\Exception\BookmarkNotFoundException; @@ -17,6 +16,8 @@ use Shaarli\Formatter\BookmarkMarkdownFormatter; use Shaarli\History; use Shaarli\Plugin\PluginManager; use Shaarli\TestCase; +use Shaarli\Tests\Utils\FakeBookmarkService; +use Shaarli\Tests\Utils\ReferenceLinkDB; /** * Unitary tests for LegacyLinkDBTest @@ -95,7 +96,7 @@ class BookmarkFileServiceTest extends TestCase $this->conf = new ConfigManager(self::$testConf); $this->conf->set('resource.datastore', self::$testDatastore); $this->conf->set('resource.updates', self::$testUpdates); - $this->refDB = new \ReferenceLinkDB(); + $this->refDB = new ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); $this->history = new History('sandbox/history.php'); $this->pluginManager = new PluginManager($this->conf); @@ -124,12 +125,12 @@ class BookmarkFileServiceTest extends TestCase define('SHAARLI_VERSION', 'dev'); } - $this->refDB = new \ReferenceLinkDB(true); + $this->refDB = new ReferenceLinkDB(true); $this->refDB->write(self::$testDatastore); $db = self::getMethod('migrate'); $db->invokeArgs($this->privateLinkDB, []); - $db = new \FakeBookmarkService( + $db = new FakeBookmarkService( $this->conf, $this->pluginManager, $this->history, @@ -204,7 +205,7 @@ class BookmarkFileServiceTest extends TestCase $this->assertEquals($updated, $bookmark->getUpdated()); // reload from file - $this->privateLinkDB = new \FakeBookmarkService( + $this->privateLinkDB = new FakeBookmarkService( $this->conf, $this->pluginManager, $this->history, @@ -715,7 +716,7 @@ class BookmarkFileServiceTest extends TestCase { unlink(self::$testDatastore); $this->assertFileNotExists(self::$testDatastore); - $db = new \FakeBookmarkService($this->conf, $this->pluginManager, $this->history, $this->mutex, false); + $db = new FakeBookmarkService($this->conf, $this->pluginManager, $this->history, $this->mutex, false); $this->assertFileNotExists(self::$testDatastore); $this->assertInstanceOf(BookmarkArray::class, $db->getBookmarks()); $this->assertCount(0, $db->getBookmarks()); diff --git a/tests/bookmark/BookmarkFilterTest.php b/tests/bookmark/BookmarkFilterTest.php index 6ae5f232..d7cbca16 100644 --- a/tests/bookmark/BookmarkFilterTest.php +++ b/tests/bookmark/BookmarkFilterTest.php @@ -3,11 +3,12 @@ namespace Shaarli\Bookmark; use malkusch\lock\mutex\NoMutex; -use ReferenceLinkDB; use Shaarli\Config\ConfigManager; use Shaarli\History; use Shaarli\Plugin\PluginManager; use Shaarli\TestCase; +use Shaarli\Tests\Utils\FakeBookmarkService; +use Shaarli\Tests\Utils\ReferenceLinkDB; /** * Class BookmarkFilterTest. @@ -46,10 +47,10 @@ class BookmarkFilterTest extends TestCase $conf = new ConfigManager('tests/utils/config/configJson'); $conf->set('resource.datastore', self::$testDatastore); static::$pluginManager = new PluginManager($conf); - self::$refDB = new \ReferenceLinkDB(); + self::$refDB = new ReferenceLinkDB(); self::$refDB->write(self::$testDatastore); $history = new History('sandbox/history.php'); - self::$bookmarkService = new \FakeBookmarkService($conf, static::$pluginManager, $history, $mutex, true); + self::$bookmarkService = new FakeBookmarkService($conf, static::$pluginManager, $history, $mutex, true); self::$linkFilter = new BookmarkFilter(self::$bookmarkService->getBookmarks(), $conf, static::$pluginManager); } diff --git a/tests/bookmark/BookmarkInitializerTest.php b/tests/bookmark/BookmarkInitializerTest.php index 66fa0646..619cf83c 100644 --- a/tests/bookmark/BookmarkInitializerTest.php +++ b/tests/bookmark/BookmarkInitializerTest.php @@ -7,6 +7,7 @@ use Shaarli\Config\ConfigManager; use Shaarli\History; use Shaarli\Plugin\PluginManager; use Shaarli\TestCase; +use Shaarli\Tests\Utils\ReferenceLinkDB; /** * Class BookmarkInitializerTest @@ -73,7 +74,7 @@ class BookmarkInitializerTest extends TestCase */ public function testInitializeNotEmptyDataStore(): void { - $refDB = new \ReferenceLinkDB(); + $refDB = new ReferenceLinkDB(); $refDB->write(self::$testDatastore); $this->bookmarkService = new BookmarkFileService( $this->conf, diff --git a/tests/bookmark/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php index 0d9930ac..873e6549 100644 --- a/tests/bookmark/LinkUtilsTest.php +++ b/tests/bookmark/LinkUtilsTest.php @@ -4,8 +4,6 @@ namespace Shaarli\Bookmark; use Shaarli\TestCase; -require_once 'tests/utils/CurlUtils.php'; - /** * Class LinkUtilsTest. */ @@ -701,7 +699,10 @@ class LinkUtilsTest extends TestCase static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter(['tag1', 'tag2', 'tag3'], $separator)); static::assertSame(['tag1,', 'tag2@', 'tag3'], tags_filter(['tag1,', 'tag2@', 'tag3'], $separator)); static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter([' tag1 ', 'tag2', 'tag3 '], $separator)); - static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter([' tag1 ', ' ', 'tag2', ' ', 'tag3 '], $separator)); + static::assertSame( + ['tag1', 'tag2', 'tag3'], + tags_filter([' tag1 ', ' ', 'tag2', ' ', 'tag3 '], $separator) + ); static::assertSame(['tag1'], tags_filter([' tag1 '], $separator)); static::assertSame([], tags_filter([' '], $separator)); static::assertSame([], tags_filter([], $separator)); @@ -721,7 +722,10 @@ class LinkUtilsTest extends TestCase ['tag1', 'tag2, and other', 'tag3'], tags_filter(['@@@@ tag1@@@', ' @tag2, and other @', 'tag3@@@@'], $separator) ); - static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter(['@@@tag1@@@', '@', 'tag2', '@@@', 'tag3@@@'], $separator)); + static::assertSame( + ['tag1', 'tag2', 'tag3'], + tags_filter(['@@@tag1@@@', '@', 'tag2', '@@@', 'tag3@@@'], $separator) + ); static::assertSame(['tag1'], tags_filter(['@@@@tag1@@@@'], $separator)); static::assertSame([], tags_filter(['@@@'], $separator)); static::assertSame([], tags_filter([], $separator)); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3508a7b1..9d05b3d5 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,6 +2,8 @@ require_once 'vendor/autoload.php'; +use Shaarli\Tests\Utils\ReferenceSessionIdHashes; + $conf = new \Shaarli\Config\ConfigManager('tests/utils/config/configJson'); new \Shaarli\Languages('en', $conf); @@ -13,23 +15,26 @@ if (!function_exists('is_iterable')) { } } -// TODO: remove this after fixing UT +// raw functions +require_once 'application/config/ConfigPlugin.php'; require_once 'application/bookmark/LinkUtils.php'; -require_once 'application/Utils.php'; require_once 'application/http/UrlUtils.php'; require_once 'application/http/HttpUtils.php'; +require_once 'application/Utils.php'; +require_once 'application/TimeZone.php'; +require_once 'tests/utils/CurlUtils.php'; +require_once 'tests/utils/RainTPL.php'; + +// TODO: remove this after fixing UT require_once 'tests/TestCase.php'; require_once 'tests/container/ShaarliTestContainer.php'; require_once 'tests/front/controller/visitor/FrontControllerMockHelper.php'; require_once 'tests/front/controller/admin/FrontAdminControllerMockHelper.php'; -require_once 'tests/updater/DummyUpdater.php'; -require_once 'tests/utils/FakeBookmarkService.php'; require_once 'tests/utils/FakeConfigManager.php'; require_once 'tests/utils/ReferenceHistory.php'; require_once 'tests/utils/ReferenceLinkDB.php'; -require_once 'tests/utils/ReferenceSessionIdHashes.php'; -\ReferenceSessionIdHashes::genAllHashes(); +ReferenceSessionIdHashes::genAllHashes(); if (!defined('SHAARLI_MUTEX_FILE')) { define('SHAARLI_MUTEX_FILE', __FILE__); diff --git a/tests/config/ConfigPluginTest.php b/tests/config/ConfigPluginTest.php index 234ae191..850b3546 100644 --- a/tests/config/ConfigPluginTest.php +++ b/tests/config/ConfigPluginTest.php @@ -4,13 +4,12 @@ namespace Shaarli\Config; use Shaarli\Config\Exception\PluginConfigOrderException; use Shaarli\Plugin\PluginManager; - -require_once 'application/config/ConfigPlugin.php'; +use Shaarli\TestCase; /** * Unitary tests for Shaarli config related functions */ -class ConfigPluginTest extends \Shaarli\TestCase +class ConfigPluginTest extends TestCase { /** * Test save_plugin_config with valid data. @@ -54,7 +53,7 @@ class ConfigPluginTest extends \Shaarli\TestCase */ public function testSavePluginConfigInvalid() { - $this->expectException(\Shaarli\Config\Exception\PluginConfigOrderException::class); + $this->expectException(PluginConfigOrderException::class); $data = [ 'plugin2' => 0, diff --git a/tests/feed/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php index 277e5d59..bd6a9cd8 100644 --- a/tests/feed/FeedBuilderTest.php +++ b/tests/feed/FeedBuilderTest.php @@ -4,7 +4,6 @@ namespace Shaarli\Feed; use DateTime; use malkusch\lock\mutex\NoMutex; -use ReferenceLinkDB; use Shaarli\Bookmark\Bookmark; use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Bookmark\LinkDB; @@ -13,6 +12,7 @@ use Shaarli\Formatter\FormatterFactory; use Shaarli\History; use Shaarli\Plugin\PluginManager; use Shaarli\TestCase; +use Shaarli\Tests\Utils\ReferenceLinkDB; /** * FeedBuilderTest class. @@ -52,7 +52,7 @@ class FeedBuilderTest extends TestCase $mutex = new NoMutex(); $conf = new ConfigManager('tests/utils/config/configJson'); $conf->set('resource.datastore', self::$testDatastore); - $refLinkDB = new \ReferenceLinkDB(); + $refLinkDB = new ReferenceLinkDB(); $refLinkDB->write(self::$testDatastore); $history = new History('sandbox/history.php'); $factory = new FormatterFactory($conf, true); @@ -100,7 +100,10 @@ class FeedBuilderTest extends TestCase // Test first not pinned link (note link) $link = $data['links'][array_keys($data['links'])[0]]; $this->assertEquals(41, $link['id']); - $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); + $this->assertEquals( + DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), + $link['created'] + ); $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']); $this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']); $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']); @@ -164,7 +167,10 @@ class FeedBuilderTest extends TestCase $this->assertEquals(1, count($data['links'])); $link = array_shift($data['links']); $this->assertEquals(41, $link['id']); - $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); + $this->assertEquals( + DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), + $link['created'] + ); } /** @@ -186,7 +192,10 @@ class FeedBuilderTest extends TestCase $this->assertEquals(3, count($data['links'])); $link = $data['links'][array_keys($data['links'])[0]]; $this->assertEquals(41, $link['id']); - $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); + $this->assertEquals( + DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), + $link['created'] + ); } /** @@ -208,7 +217,10 @@ class FeedBuilderTest extends TestCase // First link is a permalink $link = $data['links'][array_keys($data['links'])[0]]; $this->assertEquals(41, $link['id']); - $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); + $this->assertEquals( + DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), + $link['created'] + ); $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']); $this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']); $this->assertContainsPolyfill('Direct link', $link['description']); @@ -216,7 +228,10 @@ class FeedBuilderTest extends TestCase // Second link is a direct link $link = $data['links'][array_keys($data['links'])[1]]; $this->assertEquals(8, $link['id']); - $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), $link['created']); + $this->assertEquals( + DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), + $link['created'] + ); $this->assertEquals('http://host.tld/shaare/RttfEw', $link['guid']); $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']); $this->assertContainsPolyfill('Direct link', $link['description']); diff --git a/tests/front/controller/admin/PluginsControllerTest.php b/tests/front/controller/admin/PluginsControllerTest.php index e067de43..fbec3197 100644 --- a/tests/front/controller/admin/PluginsControllerTest.php +++ b/tests/front/controller/admin/PluginsControllerTest.php @@ -16,7 +16,7 @@ class PluginsControllerTest extends TestCase { use FrontAdminControllerMockHelper; - const PLUGIN_NAMES = ['plugin1', 'plugin2', 'plugin3', 'plugin4']; + protected const PLUGIN_NAMES = ['plugin1', 'plugin2', 'plugin3', 'plugin4']; /** @var PluginsController */ protected $controller; diff --git a/tests/front/controller/visitor/InstallControllerTest.php b/tests/front/controller/visitor/InstallControllerTest.php index 2105ed77..ea29592c 100644 --- a/tests/front/controller/visitor/InstallControllerTest.php +++ b/tests/front/controller/visitor/InstallControllerTest.php @@ -15,7 +15,7 @@ class InstallControllerTest extends TestCase { use FrontControllerMockHelper; - const MOCK_FILE = '.tmp'; + protected const MOCK_FILE = '.tmp'; /** @var InstallController */ protected $controller; diff --git a/tests/helper/ApplicationUtilsTest.php b/tests/helper/ApplicationUtilsTest.php index 3d431b9e..1b4f8204 100644 --- a/tests/helper/ApplicationUtilsTest.php +++ b/tests/helper/ApplicationUtilsTest.php @@ -3,9 +3,7 @@ namespace Shaarli\Helper; use Shaarli\Config\ConfigManager; -use Shaarli\FakeApplicationUtils; - -require_once 'tests/utils/FakeApplicationUtils.php'; +use Shaarli\Tests\Utils\FakeApplicationUtils; /** * Unitary tests for Shaarli utilities diff --git a/tests/helper/DailyPageHelperTest.php b/tests/helper/DailyPageHelperTest.php index d47fcc45..4a4b95b2 100644 --- a/tests/helper/DailyPageHelperTest.php +++ b/tests/helper/DailyPageHelperTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Shaarli\Helper; +use DateTime; use DateTimeImmutable; use DateTimeInterface; use Shaarli\Bookmark\Bookmark; @@ -209,31 +210,31 @@ class DailyPageHelperTest extends TestCase public function getRequestedDateTimes(): array { return [ - [DailyPageHelper::DAY, '20201013', null, new \DateTime('2020-10-13')], + [DailyPageHelper::DAY, '20201013', null, new DateTime('2020-10-13')], [ DailyPageHelper::DAY, '', - (new Bookmark())->setCreated($date = new \DateTime('2020-10-13 12:05:31')), + (new Bookmark())->setCreated($date = new DateTime('2020-10-13 12:05:31')), $date, ], - [DailyPageHelper::DAY, '', null, new \DateTime()], - [DailyPageHelper::WEEK, '202030', null, new \DateTime('2020-07-20')], + [DailyPageHelper::DAY, '', null, new DateTime()], + [DailyPageHelper::WEEK, '202030', null, new DateTime('2020-07-20')], [ DailyPageHelper::WEEK, '', - (new Bookmark())->setCreated($date = new \DateTime('2020-10-13 12:05:31')), - new \DateTime('2020-10-13'), + (new Bookmark())->setCreated($date = new DateTime('2020-10-13 12:05:31')), + new DateTime('2020-10-13'), ], - [DailyPageHelper::WEEK, '', null, new \DateTime(), 'Ym'], - [DailyPageHelper::MONTH, '202008', null, new \DateTime('2020-08-01'), 'Ym'], + [DailyPageHelper::WEEK, '', null, new DateTime(), 'Ym'], + [DailyPageHelper::MONTH, '202008', null, new DateTime('2020-08-01'), 'Ym'], [ DailyPageHelper::MONTH, '', - (new Bookmark())->setCreated($date = new \DateTime('2020-10-13 12:05:31')), - new \DateTime('2020-10-13'), + (new Bookmark())->setCreated($date = new DateTime('2020-10-13 12:05:31')), + new DateTime('2020-10-13'), 'Ym' ], - [DailyPageHelper::MONTH, '', null, new \DateTime(), 'Ym'], + [DailyPageHelper::MONTH, '', null, new DateTime(), 'Ym'], ]; } @@ -255,9 +256,9 @@ class DailyPageHelperTest extends TestCase public function getStartDatesByType(): array { return [ - [DailyPageHelper::DAY, new DateTimeImmutable('2020-10-09 04:05:06'), new \DateTime('2020-10-09 00:00:00')], - [DailyPageHelper::WEEK, new DateTimeImmutable('2020-10-09 04:05:06'), new \DateTime('2020-10-05 00:00:00')], - [DailyPageHelper::MONTH, new DateTimeImmutable('2020-10-09 04:05:06'), new \DateTime('2020-10-01 00:00:00')], + [DailyPageHelper::DAY, new DateTimeImmutable('2020-10-09 04:05:06'), new DateTime('2020-10-09 00:00:00')], + [DailyPageHelper::WEEK, new DateTimeImmutable('2020-10-09 04:05:06'), new DateTime('2020-10-05 00:00:00')], + [DailyPageHelper::MONTH, new DateTimeImmutable('2020-10-09 04:05:06'), new DateTime('2020-10-01 00:00:00')], ]; } @@ -267,9 +268,9 @@ class DailyPageHelperTest extends TestCase public function getEndDatesByType(): array { return [ - [DailyPageHelper::DAY, new DateTimeImmutable('2020-10-09 04:05:06'), new \DateTime('2020-10-09 23:59:59')], - [DailyPageHelper::WEEK, new DateTimeImmutable('2020-10-09 04:05:06'), new \DateTime('2020-10-11 23:59:59')], - [DailyPageHelper::MONTH, new DateTimeImmutable('2020-10-09 04:05:06'), new \DateTime('2020-10-31 23:59:59')], + [DailyPageHelper::DAY, new DateTimeImmutable('2020-10-09 04:05:06'), new DateTime('2020-10-09 23:59:59')], + [DailyPageHelper::WEEK, new DateTimeImmutable('2020-10-09 04:05:06'), new DateTime('2020-10-11 23:59:59')], + [DailyPageHelper::MONTH, new DateTimeImmutable('2020-10-09 04:05:06'), new DateTime('2020-10-31 23:59:59')], ]; } @@ -322,20 +323,20 @@ class DailyPageHelperTest extends TestCase [ DailyPageHelper::DAY, new DateTimeImmutable('2020-10-09 04:05:06'), - new \DateTime('2020-10-09 00:00:00'), - new \DateTime('2020-10-09 23:59:59'), + new DateTime('2020-10-09 00:00:00'), + new DateTime('2020-10-09 23:59:59'), ], [ DailyPageHelper::WEEK, new DateTimeImmutable('2020-10-09 04:05:06'), - new \DateTime('2020-10-05 00:00:00'), - new \DateTime('2020-10-11 23:59:59'), + new DateTime('2020-10-05 00:00:00'), + new DateTime('2020-10-11 23:59:59'), ], [ DailyPageHelper::MONTH, new DateTimeImmutable('2020-10-09 04:05:06'), - new \DateTime('2020-10-01 00:00:00'), - new \DateTime('2020-10-31 23:59:59'), + new DateTime('2020-10-01 00:00:00'), + new DateTime('2020-10-31 23:59:59'), ], ]; } diff --git a/tests/http/HttpUtils/ClientIpIdTest.php b/tests/http/HttpUtils/ClientIpIdTest.php index 329ca055..acb2e9d4 100644 --- a/tests/http/HttpUtils/ClientIpIdTest.php +++ b/tests/http/HttpUtils/ClientIpIdTest.php @@ -6,8 +6,6 @@ namespace Shaarli\Http; -require_once 'application/http/HttpUtils.php'; - /** * Unitary tests for client_ip_id() */ diff --git a/tests/http/HttpUtils/GetHttpUrlTest.php b/tests/http/HttpUtils/GetHttpUrlTest.php index f6d25e86..3e0b0322 100644 --- a/tests/http/HttpUtils/GetHttpUrlTest.php +++ b/tests/http/HttpUtils/GetHttpUrlTest.php @@ -6,8 +6,6 @@ namespace Shaarli\Http; -require_once 'application/http/HttpUtils.php'; - /** * Unitary tests for get_http_response() */ diff --git a/tests/http/HttpUtils/GetIpAdressFromProxyTest.php b/tests/http/HttpUtils/GetIpAdressFromProxyTest.php index ed1fbe92..0d74b423 100644 --- a/tests/http/HttpUtils/GetIpAdressFromProxyTest.php +++ b/tests/http/HttpUtils/GetIpAdressFromProxyTest.php @@ -2,8 +2,6 @@ namespace Shaarli\Http; -require_once 'application/http/HttpUtils.php'; - /** * Unitary tests for getIpAddressFromProxy() */ diff --git a/tests/http/HttpUtils/IndexUrlTest.php b/tests/http/HttpUtils/IndexUrlTest.php index 1695eed5..94b8ff8a 100644 --- a/tests/http/HttpUtils/IndexUrlTest.php +++ b/tests/http/HttpUtils/IndexUrlTest.php @@ -8,8 +8,6 @@ namespace Shaarli\Http; use Shaarli\TestCase; -require_once 'application/http/HttpUtils.php'; - /** * Unitary tests for index_url() */ diff --git a/tests/http/HttpUtils/IsHttpsTest.php b/tests/http/HttpUtils/IsHttpsTest.php index 8b3fd93d..f7c55587 100644 --- a/tests/http/HttpUtils/IsHttpsTest.php +++ b/tests/http/HttpUtils/IsHttpsTest.php @@ -2,8 +2,6 @@ namespace Shaarli\Http; -require_once 'application/http/HttpUtils.php'; - /** * Class IsHttpsTest * diff --git a/tests/http/HttpUtils/PageUrlTest.php b/tests/http/HttpUtils/PageUrlTest.php index 46dc3585..bf882e5b 100644 --- a/tests/http/HttpUtils/PageUrlTest.php +++ b/tests/http/HttpUtils/PageUrlTest.php @@ -6,8 +6,6 @@ namespace Shaarli\Http; -require_once 'application/http/HttpUtils.php'; - /** * Unitary tests for page_url() */ diff --git a/tests/http/HttpUtils/ServerUrlTest.php b/tests/http/HttpUtils/ServerUrlTest.php index 0f034fa3..5a4f9252 100644 --- a/tests/http/HttpUtils/ServerUrlTest.php +++ b/tests/http/HttpUtils/ServerUrlTest.php @@ -6,8 +6,6 @@ namespace Shaarli\Http; -require_once 'application/http/HttpUtils.php'; - /** * Unitary tests for server_url() */ diff --git a/tests/http/UrlUtils/CleanupUrlTest.php b/tests/http/UrlUtils/CleanupUrlTest.php index 492c1edd..a1002ccc 100644 --- a/tests/http/UrlUtils/CleanupUrlTest.php +++ b/tests/http/UrlUtils/CleanupUrlTest.php @@ -6,8 +6,6 @@ namespace Shaarli\Http; -require_once 'application/http/UrlUtils.php'; - class CleanupUrlTest extends \Shaarli\TestCase { /** diff --git a/tests/http/UrlUtils/GetUrlSchemeTest.php b/tests/http/UrlUtils/GetUrlSchemeTest.php index d0467320..a6eeff00 100644 --- a/tests/http/UrlUtils/GetUrlSchemeTest.php +++ b/tests/http/UrlUtils/GetUrlSchemeTest.php @@ -6,9 +6,9 @@ namespace Shaarli\Http; -require_once 'application/http/UrlUtils.php'; +use Shaarli\TestCase; -class GetUrlSchemeTest extends \Shaarli\TestCase +class GetUrlSchemeTest extends TestCase { /** * Get empty scheme string for empty UrlUtils diff --git a/tests/http/UrlUtils/UnparseUrlTest.php b/tests/http/UrlUtils/UnparseUrlTest.php index 82881250..f01765a0 100644 --- a/tests/http/UrlUtils/UnparseUrlTest.php +++ b/tests/http/UrlUtils/UnparseUrlTest.php @@ -6,12 +6,12 @@ namespace Shaarli\Http; -require_once 'application/http/UrlUtils.php'; +use Shaarli\TestCase; /** * Unitary tests for unparse_url() */ -class UnparseUrlTest extends \Shaarli\TestCase +class UnparseUrlTest extends TestCase { /** * Thanks for building nothing diff --git a/tests/http/UrlUtils/WhitelistProtocolsTest.php b/tests/http/UrlUtils/WhitelistProtocolsTest.php index a62ce877..673af32b 100644 --- a/tests/http/UrlUtils/WhitelistProtocolsTest.php +++ b/tests/http/UrlUtils/WhitelistProtocolsTest.php @@ -2,14 +2,14 @@ namespace Shaarli\Http; -require_once 'application/http/UrlUtils.php'; +use Shaarli\TestCase; /** * Class WhitelistProtocolsTest * * Test whitelist_protocols() function of UrlUtils. */ -class WhitelistProtocolsTest extends \Shaarli\TestCase +class WhitelistProtocolsTest extends TestCase { /** * Test whitelist_protocols() on a note (relative URL). diff --git a/tests/languages/de/UtilsDeTest.php b/tests/languages/de/UtilsDeTest.php index 588c9fd6..9713009d 100644 --- a/tests/languages/de/UtilsDeTest.php +++ b/tests/languages/de/UtilsDeTest.php @@ -1,7 +1,8 @@ write(self::$testDatastore); $linkDB = new LegacyLinkDB(self::$testDatastore, true, false); @@ -369,7 +367,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; 'private' => true, ], ]; - $refDB = new \ReferenceLinkDB(true); + $refDB = new ReferenceLinkDB(true); $refDB->setLinks($links); $refDB->write(self::$testDatastore); $linkDB = new LegacyLinkDB(self::$testDatastore, true, false); @@ -438,7 +436,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; */ public function testDatastoreIdsNothingToDo() { - $refDB = new \ReferenceLinkDB(true); + $refDB = new ReferenceLinkDB(true); $refDB->write(self::$testDatastore); $linkDB = new LegacyLinkDB(self::$testDatastore, true, false); @@ -782,7 +780,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; 1 => ['id' => 1] + $blank, 2 => ['id' => 2] + $blank, ]; - $refDB = new \ReferenceLinkDB(true); + $refDB = new ReferenceLinkDB(true); $refDB->setLinks($links); $refDB->write(self::$testDatastore); $linkDB = new LegacyLinkDB(self::$testDatastore, true, false); @@ -813,7 +811,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; 1 => ['id' => 1, 'sticky' => true] + $blank, 2 => ['id' => 2] + $blank, ]; - $refDB = new \ReferenceLinkDB(true); + $refDB = new ReferenceLinkDB(true); $refDB->setLinks($links); $refDB->write(self::$testDatastore); $linkDB = new LegacyLinkDB(self::$testDatastore, true, false); diff --git a/tests/netscape/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php index b8a88cd8..ce054286 100644 --- a/tests/netscape/BookmarkExportTest.php +++ b/tests/netscape/BookmarkExportTest.php @@ -10,8 +10,7 @@ use Shaarli\Formatter\FormatterFactory; use Shaarli\History; use Shaarli\Plugin\PluginManager; use Shaarli\TestCase; - -require_once 'tests/utils/ReferenceLinkDB.php'; +use Shaarli\Tests\Utils\ReferenceLinkDB; /** * Netscape bookmark export @@ -29,7 +28,7 @@ class BookmarkExportTest extends TestCase protected static $conf; /** - * @var \ReferenceLinkDB instance. + * @var ReferenceLinkDB instance. */ protected static $refDb = null; @@ -64,7 +63,7 @@ class BookmarkExportTest extends TestCase $mutex = new NoMutex(); static::$conf = new ConfigManager('tests/utils/config/configJson'); static::$conf->set('resource.datastore', static::$testDatastore); - static::$refDb = new \ReferenceLinkDB(); + static::$refDb = new ReferenceLinkDB(); static::$refDb->write(static::$testDatastore); static::$history = new History('sandbox/history.php'); static::$pluginManager = new PluginManager(static::$conf); diff --git a/tests/plugins/PluginArchiveorgTest.php b/tests/plugins/PluginArchiveorgTest.php index 74064838..909be088 100644 --- a/tests/plugins/PluginArchiveorgTest.php +++ b/tests/plugins/PluginArchiveorgTest.php @@ -2,10 +2,6 @@ namespace Shaarli\Plugin\Archiveorg; -/** - * PluginArchiveorgTest.php - */ - use Shaarli\Plugin\PluginManager; use Shaarli\TestCase; diff --git a/tests/plugins/PluginIssoTest.php b/tests/plugins/PluginIssoTest.php index 07b00c73..119a459e 100644 --- a/tests/plugins/PluginIssoTest.php +++ b/tests/plugins/PluginIssoTest.php @@ -117,8 +117,14 @@ class PluginIssoTest extends TestCase $processed = hook_isso_render_linklist($data, $conf); // link_plugin should be added for the icon - $this->assertContainsPolyfill('', $processed['links'][0]['link_plugin'][0]); - $this->assertContainsPolyfill('', $processed['links'][1]['link_plugin'][0]); + $this->assertContainsPolyfill( + '', + $processed['links'][0]['link_plugin'][0] + ); + $this->assertContainsPolyfill( + '', + $processed['links'][1]['link_plugin'][0] + ); } /** @@ -147,7 +153,10 @@ class PluginIssoTest extends TestCase $processed = hook_isso_render_linklist($data, $conf); // link_plugin should be added for the icon - $this->assertContainsPolyfill('', $processed['links'][0]['link_plugin'][0]); + $this->assertContainsPolyfill( + '', + $processed['links'][0]['link_plugin'][0] + ); } /** diff --git a/tests/plugins/PluginPlayvideosTest.php b/tests/plugins/PluginPlayvideosTest.php index de9189ae..0f267462 100644 --- a/tests/plugins/PluginPlayvideosTest.php +++ b/tests/plugins/PluginPlayvideosTest.php @@ -2,10 +2,6 @@ namespace Shaarli\Plugin\Playvideos; -/** - * PluginPlayvideosTest.php - */ - use Shaarli\Plugin\PluginManager; use Shaarli\Render\TemplatePage; diff --git a/tests/plugins/PluginQrcodeTest.php b/tests/plugins/PluginQrcodeTest.php index 65f49bcf..ff4b9182 100644 --- a/tests/plugins/PluginQrcodeTest.php +++ b/tests/plugins/PluginQrcodeTest.php @@ -2,10 +2,6 @@ namespace Shaarli\Plugin\Qrcode; -/** - * PluginQrcodeTest.php - */ - use Shaarli\Plugin\PluginManager; use Shaarli\Render\TemplatePage; diff --git a/tests/security/SessionManagerTest.php b/tests/security/SessionManagerTest.php index 6830d714..7cc6e1a4 100644 --- a/tests/security/SessionManagerTest.php +++ b/tests/security/SessionManagerTest.php @@ -4,6 +4,7 @@ namespace Shaarli\Security; use Shaarli\FakeConfigManager; use Shaarli\TestCase; +use Shaarli\Tests\Utils\ReferenceSessionIdHashes; /** * Test coverage for SessionManager @@ -27,7 +28,7 @@ class SessionManagerTest extends TestCase */ public static function setUpBeforeClass(): void { - self::$sidHashes = \ReferenceSessionIdHashes::getHashes(); + self::$sidHashes = ReferenceSessionIdHashes::getHashes(); } /** diff --git a/tests/updater/DummyUpdater.php b/tests/updater/DummyUpdater.php index 4b2c7e0c..93e63c92 100644 --- a/tests/updater/DummyUpdater.php +++ b/tests/updater/DummyUpdater.php @@ -1,6 +1,6 @@ refDB = new \ReferenceLinkDB(); + $this->refDB = new ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); copy('tests/utils/config/configJson.json.php', self::$configFile . '.json.php'); diff --git a/tests/utils/FakeApplicationUtils.php b/tests/utils/FakeApplicationUtils.php index d5289ede..a85b88e2 100644 --- a/tests/utils/FakeApplicationUtils.php +++ b/tests/utils/FakeApplicationUtils.php @@ -1,6 +1,6 @@ _privateCount++; + $this->privateCount++; return; } - $this->_publicCount++; + $this->publicCount++; } /** @@ -233,7 +236,7 @@ class ReferenceLinkDB */ public function countLinks() { - return $this->_publicCount + $this->_privateCount; + return $this->publicCount + $this->privateCount; } /** @@ -241,7 +244,7 @@ class ReferenceLinkDB */ public function countPublicLinks() { - return $this->_publicCount; + return $this->publicCount; } /** @@ -249,7 +252,7 @@ class ReferenceLinkDB */ public function countPrivateLinks() { - return $this->_privateCount; + return $this->privateCount; } /** diff --git a/tests/utils/ReferenceSessionIdHashes.php b/tests/utils/ReferenceSessionIdHashes.php index 6543b7a5..d0b2ddf7 100644 --- a/tests/utils/ReferenceSessionIdHashes.php +++ b/tests/utils/ReferenceSessionIdHashes.php @@ -1,5 +1,7 @@