From a5a9cf23acd1248585173aa32757d9720b5f2d62 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 29 Sep 2020 14:41:40 +0200 Subject: Compatibility with PHPUnit 9 --- tests/ApplicationUtilsTest.php | 2 +- tests/FileUtilsTest.php | 2 +- tests/HistoryTest.php | 3 +- tests/LanguagesTest.php | 2 +- tests/PluginManagerTest.php | 2 +- tests/TestCase.php | 77 ++++++++++++++++++++++ tests/ThumbnailerTest.php | 1 - tests/TimeZoneTest.php | 2 +- tests/UtilsTest.php | 2 +- tests/api/ApiMiddlewareTest.php | 14 ++-- tests/api/ApiUtilsTest.php | 2 +- tests/api/controllers/history/HistoryTest.php | 2 +- tests/api/controllers/info/InfoTest.php | 2 +- tests/api/controllers/links/DeleteLinkTest.php | 2 +- tests/api/controllers/links/GetLinkIdTest.php | 2 +- tests/api/controllers/links/GetLinksTest.php | 2 +- tests/api/controllers/links/PostLinkTest.php | 2 +- tests/api/controllers/links/PutLinkTest.php | 2 +- tests/api/controllers/tags/DeleteTagTest.php | 2 +- tests/api/controllers/tags/GetTagNameTest.php | 2 +- tests/api/controllers/tags/GetTagsTest.php | 2 +- tests/api/controllers/tags/PutTagTest.php | 2 +- tests/bookmark/BookmarkArrayTest.php | 5 +- tests/bookmark/BookmarkFileServiceTest.php | 4 +- tests/bookmark/BookmarkFilterTest.php | 2 +- tests/bookmark/BookmarkInitializerTest.php | 2 +- tests/bookmark/BookmarkTest.php | 12 ++-- tests/bookmark/LinkUtilsTest.php | 22 +++---- tests/bootstrap.php | 1 + tests/config/ConfigJsonTest.php | 2 +- tests/config/ConfigManagerTest.php | 2 +- tests/config/ConfigPhpTest.php | 2 +- tests/config/ConfigPluginTest.php | 2 +- tests/container/ContainerBuilderTest.php | 2 +- tests/feed/CachedPageTest.php | 2 +- tests/feed/FeedBuilderTest.php | 18 ++--- tests/formatter/BookmarkDefaultFormatterTest.php | 2 +- tests/formatter/BookmarkMarkdownFormatterTest.php | 2 +- tests/formatter/BookmarkRawFormatterTest.php | 2 +- tests/formatter/FormatterFactoryTest.php | 2 +- tests/front/ShaarliAdminMiddlewareTest.php | 2 +- tests/front/ShaarliMiddlewareTest.php | 2 +- .../controller/admin/ConfigureControllerTest.php | 2 +- .../controller/admin/ExportControllerTest.php | 2 +- .../controller/admin/ImportControllerTest.php | 2 +- .../controller/admin/LogoutControllerTest.php | 3 +- .../ManageShaareControllerTest/AddShaareTest.php | 2 +- .../ChangeVisibilityBookmarkTest.php | 2 +- .../DeleteBookmarkTest.php | 2 +- .../DisplayCreateFormTest.php | 12 ++-- .../DisplayEditFormTest.php | 2 +- .../ManageShaareControllerTest/PinBookmarkTest.php | 2 +- .../SaveBookmarkTest.php | 40 +++++------ .../controller/admin/ManageTagControllerTest.php | 2 +- .../controller/admin/PasswordControllerTest.php | 2 +- .../controller/admin/PluginsControllerTest.php | 2 +- .../admin/SessionFilterControllerTest.php | 2 +- .../admin/ShaarliAdminControllerTest.php | 2 +- .../controller/admin/ThumbnailsControllerTest.php | 2 +- .../front/controller/admin/TokenControllerTest.php | 2 +- .../front/controller/admin/ToolsControllerTest.php | 2 +- .../visitor/BookmarkListControllerTest.php | 2 +- .../controller/visitor/DailyControllerTest.php | 48 +++++++------- .../controller/visitor/ErrorControllerTest.php | 2 +- .../visitor/ErrorNotFoundControllerTest.php | 2 +- .../controller/visitor/FeedControllerTest.php | 38 ++++++----- .../visitor/FrontControllerMockHelper.php | 3 +- .../controller/visitor/InstallControllerTest.php | 2 +- .../controller/visitor/LoginControllerTest.php | 2 +- .../visitor/OpenSearchControllerTest.php | 2 +- .../visitor/PictureWallControllerTest.php | 18 ++--- .../visitor/PublicSessionFilterControllerTest.php | 2 +- .../visitor/ShaarliVisitorControllerTest.php | 2 +- .../controller/visitor/TagCloudControllerTest.php | 74 ++++++++++++--------- .../front/controller/visitor/TagControllerTest.php | 2 +- tests/http/HttpUtils/ClientIpIdTest.php | 2 +- tests/http/HttpUtils/GetHttpUrlTest.php | 2 +- tests/http/HttpUtils/GetIpAdressFromProxyTest.php | 2 +- tests/http/HttpUtils/IndexUrlTest.php | 2 +- tests/http/HttpUtils/IndexUrlTestWithConstant.php | 2 +- tests/http/HttpUtils/IsHttpsTest.php | 2 +- tests/http/HttpUtils/PageUrlTest.php | 2 +- tests/http/HttpUtils/ServerUrlTest.php | 2 +- tests/http/UrlTest.php | 2 +- tests/http/UrlUtils/CleanupUrlTest.php | 2 +- tests/http/UrlUtils/GetUrlSchemeTest.php | 2 +- tests/http/UrlUtils/UnparseUrlTest.php | 2 +- tests/http/UrlUtils/WhitelistProtocolsTest.php | 2 +- tests/languages/fr/LanguagesFrTest.php | 2 +- tests/legacy/LegacyControllerTest.php | 2 +- tests/legacy/LegacyLinkDBTest.php | 12 ++-- tests/legacy/LegacyLinkFilterTest.php | 2 +- tests/legacy/LegacyUpdaterTest.php | 4 +- tests/netscape/BookmarkExportTest.php | 2 +- tests/netscape/BookmarkImportTest.php | 2 +- tests/plugins/PluginAddlinkTest.php | 2 +- tests/plugins/PluginArchiveorgTest.php | 2 +- tests/plugins/PluginDefaultColorsTest.php | 2 +- tests/plugins/PluginIssoTest.php | 8 +-- tests/plugins/PluginPlayvideosTest.php | 2 +- tests/plugins/PluginPubsubhubbubTest.php | 2 +- tests/plugins/PluginQrcodeTest.php | 2 +- tests/plugins/PluginWallabagTest.php | 2 +- tests/plugins/WallabagInstanceTest.php | 2 +- tests/render/PageCacheManagerTest.php | 2 +- tests/render/ThemeUtilsTest.php | 2 +- tests/security/BanManagerTest.php | 2 +- tests/security/LoginManagerTest.php | 2 +- tests/security/SessionManagerTest.php | 2 +- tests/updater/UpdaterTest.php | 2 +- 110 files changed, 346 insertions(+), 249 deletions(-) create mode 100644 tests/TestCase.php (limited to 'tests') diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php index 421d2dd9..7ad1d34c 100644 --- a/tests/ApplicationUtilsTest.php +++ b/tests/ApplicationUtilsTest.php @@ -8,7 +8,7 @@ require_once 'tests/utils/FakeApplicationUtils.php'; /** * Unitary tests for Shaarli utilities */ -class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase +class ApplicationUtilsTest extends \Shaarli\TestCase { protected static $testUpdateFile = 'sandbox/update.txt'; protected static $testVersion = '0.5.0'; diff --git a/tests/FileUtilsTest.php b/tests/FileUtilsTest.php index 6e8f44f2..9163bdf1 100644 --- a/tests/FileUtilsTest.php +++ b/tests/FileUtilsTest.php @@ -9,7 +9,7 @@ use Exception; * * Test file utility class. */ -class FileUtilsTest extends \PHPUnit\Framework\TestCase +class FileUtilsTest extends \Shaarli\TestCase { /** * @var string Test file path. diff --git a/tests/HistoryTest.php b/tests/HistoryTest.php index fb633e79..6dc0e5b7 100644 --- a/tests/HistoryTest.php +++ b/tests/HistoryTest.php @@ -3,10 +3,9 @@ namespace Shaarli; use DateTime; -use Exception; use Shaarli\Bookmark\Bookmark; -class HistoryTest extends \PHPUnit\Framework\TestCase +class HistoryTest extends \Shaarli\TestCase { /** * @var string History file path diff --git a/tests/LanguagesTest.php b/tests/LanguagesTest.php index 914179c8..ce24c160 100644 --- a/tests/LanguagesTest.php +++ b/tests/LanguagesTest.php @@ -7,7 +7,7 @@ use Shaarli\Config\ConfigManager; /** * Class LanguagesTest. */ -class LanguagesTest extends \PHPUnit\Framework\TestCase +class LanguagesTest extends \Shaarli\TestCase { /** * @var string Config file path (without extension). diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php index 3018999c..38cd5eba 100644 --- a/tests/PluginManagerTest.php +++ b/tests/PluginManagerTest.php @@ -6,7 +6,7 @@ use Shaarli\Config\ConfigManager; /** * Unit tests for Plugins */ -class PluginManagerTest extends \PHPUnit\Framework\TestCase +class PluginManagerTest extends \Shaarli\TestCase { /** * Path to tests plugin. diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 00000000..781e7aa3 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,77 @@ +expectExceptionMessageMatches($regularExpression); + } else { + parent::expectExceptionMessageRegExp($regularExpression); + } + } + + /** + * assertContains is now used for iterable, strings should use assertStringContainsString + */ + public function assertContainsPolyfill($expected, $actual, string $message = ''): void + { + if (is_string($actual) && method_exists($this, 'assertStringContainsString')) { + static::assertStringContainsString($expected, $actual, $message); + } else { + static::assertContains($expected, $actual, $message); + } + } + + /** + * assertNotContains is now used for iterable, strings should use assertStringNotContainsString + */ + public function assertNotContainsPolyfill($expected, $actual, string $message = ''): void + { + if (is_string($actual) && method_exists($this, 'assertStringNotContainsString')) { + static::assertStringNotContainsString($expected, $actual, $message); + } else { + static::assertNotContains($expected, $actual, $message); + } + } + + /** + * assertFileNotExists has been renamed in assertFileDoesNotExist + */ + public static function assertFileNotExists(string $filename, string $message = ''): void + { + if (method_exists(TestCase::class, 'assertFileDoesNotExist')) { + static::assertFileDoesNotExist($filename, $message); + } else { + parent::assertFileNotExists($filename, $message); + } + } + + /** + * assertRegExp has been renamed in assertMatchesRegularExpression + */ + public static function assertRegExp(string $pattern, string $string, string $message = ''): void + { + if (method_exists(TestCase::class, 'assertMatchesRegularExpression')) { + static::assertMatchesRegularExpression($pattern, $string, $message); + } else { + parent::assertRegExp($pattern, $string, $message); + } + } + + public function isInTestsContext(): bool + { + return true; + } +} diff --git a/tests/ThumbnailerTest.php b/tests/ThumbnailerTest.php index 5b6d6a4d..70519aca 100644 --- a/tests/ThumbnailerTest.php +++ b/tests/ThumbnailerTest.php @@ -2,7 +2,6 @@ namespace Shaarli; -use PHPUnit\Framework\TestCase; use Shaarli\Config\ConfigManager; use WebThumbnailer\Application\ConfigManager as WTConfigManager; diff --git a/tests/TimeZoneTest.php b/tests/TimeZoneTest.php index d3d9aeeb..77862855 100644 --- a/tests/TimeZoneTest.php +++ b/tests/TimeZoneTest.php @@ -8,7 +8,7 @@ require_once 'application/TimeZone.php'; /** * Unitary tests for timezone utilities */ -class TimeZoneTest extends PHPUnit\Framework\TestCase +class TimeZoneTest extends \Shaarli\TestCase { /** * @var array of timezones diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index 93b77539..6e787d7f 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -10,7 +10,7 @@ require_once 'application/Languages.php'; /** * Unitary tests for Shaarli utilities */ -class UtilsTest extends PHPUnit\Framework\TestCase +class UtilsTest extends \Shaarli\TestCase { // Log file protected static $testLogFile = 'tests.log'; diff --git a/tests/api/ApiMiddlewareTest.php b/tests/api/ApiMiddlewareTest.php index b157e4a7..7386e435 100644 --- a/tests/api/ApiMiddlewareTest.php +++ b/tests/api/ApiMiddlewareTest.php @@ -18,7 +18,7 @@ use Slim\Http\Response; * * @package Api */ -class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase +class ApiMiddlewareTest extends \Shaarli\TestCase { /** * @var string datastore to test write operations @@ -26,7 +26,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase protected static $testDatastore = 'sandbox/datastore.php'; /** - * @var \ConfigManager instance + * @var ConfigManager instance */ protected $conf; @@ -109,7 +109,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase $this->assertEquals(401, $response->getStatusCode()); $body = json_decode((string) $response->getBody()); $this->assertEquals('Not authorized: API is disabled', $body->message); - $this->assertContains('ApiAuthorizationException', $body->stacktrace); + $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace); } /** @@ -132,7 +132,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase $this->assertEquals(401, $response->getStatusCode()); $body = json_decode((string) $response->getBody()); $this->assertEquals('Not authorized: JWT token not provided', $body->message); - $this->assertContains('ApiAuthorizationException', $body->stacktrace); + $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace); } /** @@ -157,7 +157,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase $this->assertEquals(401, $response->getStatusCode()); $body = json_decode((string) $response->getBody()); $this->assertEquals('Not authorized: Token secret must be set in Shaarli\'s administration', $body->message); - $this->assertContains('ApiAuthorizationException', $body->stacktrace); + $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace); } /** @@ -180,7 +180,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase $this->assertEquals(401, $response->getStatusCode()); $body = json_decode((string) $response->getBody()); $this->assertEquals('Not authorized: Invalid JWT header', $body->message); - $this->assertContains('ApiAuthorizationException', $body->stacktrace); + $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace); } /** @@ -206,6 +206,6 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase $this->assertEquals(401, $response->getStatusCode()); $body = json_decode((string) $response->getBody()); $this->assertEquals('Not authorized: Malformed JWT token', $body->message); - $this->assertContains('ApiAuthorizationException', $body->stacktrace); + $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace); } } diff --git a/tests/api/ApiUtilsTest.php b/tests/api/ApiUtilsTest.php index 96787014..7a143859 100644 --- a/tests/api/ApiUtilsTest.php +++ b/tests/api/ApiUtilsTest.php @@ -8,7 +8,7 @@ use Shaarli\Http\Base64Url; /** * Class ApiUtilsTest */ -class ApiUtilsTest extends \PHPUnit\Framework\TestCase +class ApiUtilsTest extends \Shaarli\TestCase { /** * Force the timezone for ISO datetimes. diff --git a/tests/api/controllers/history/HistoryTest.php b/tests/api/controllers/history/HistoryTest.php index 40f26b12..84f8716e 100644 --- a/tests/api/controllers/history/HistoryTest.php +++ b/tests/api/controllers/history/HistoryTest.php @@ -11,7 +11,7 @@ use Slim\Http\Response; require_once 'tests/utils/ReferenceHistory.php'; -class HistoryTest extends \PHPUnit\Framework\TestCase +class HistoryTest extends \Shaarli\TestCase { /** * @var string datastore to test write operations diff --git a/tests/api/controllers/info/InfoTest.php b/tests/api/controllers/info/InfoTest.php index cc50d2e3..1598e1e8 100644 --- a/tests/api/controllers/info/InfoTest.php +++ b/tests/api/controllers/info/InfoTest.php @@ -1,10 +1,10 @@ publicLinkDB->findByUrl('http://mediagoblin.org/'); $this->assertNotEquals(false, $link); - $this->assertContains( + $this->assertContainsPolyfill( 'A free software media publishing platform', $link->getDescription() ); diff --git a/tests/bookmark/BookmarkFilterTest.php b/tests/bookmark/BookmarkFilterTest.php index 752631a5..2f15cb3c 100644 --- a/tests/bookmark/BookmarkFilterTest.php +++ b/tests/bookmark/BookmarkFilterTest.php @@ -3,10 +3,10 @@ namespace Shaarli\Bookmark; use Exception; -use PHPUnit\Framework\TestCase; use ReferenceLinkDB; use Shaarli\Config\ConfigManager; use Shaarli\History; +use Shaarli\TestCase; /** * Class BookmarkFilterTest. diff --git a/tests/bookmark/BookmarkInitializerTest.php b/tests/bookmark/BookmarkInitializerTest.php index 454269bb..25704004 100644 --- a/tests/bookmark/BookmarkInitializerTest.php +++ b/tests/bookmark/BookmarkInitializerTest.php @@ -2,9 +2,9 @@ namespace Shaarli\Bookmark; -use PHPUnit\Framework\TestCase; use Shaarli\Config\ConfigManager; use Shaarli\History; +use Shaarli\TestCase; /** * Class BookmarkInitializerTest diff --git a/tests/bookmark/BookmarkTest.php b/tests/bookmark/BookmarkTest.php index 4b6a3c07..afec2440 100644 --- a/tests/bookmark/BookmarkTest.php +++ b/tests/bookmark/BookmarkTest.php @@ -2,8 +2,8 @@ namespace Shaarli\Bookmark; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Exception\InvalidBookmarkException; +use Shaarli\TestCase; /** * Class BookmarkTest @@ -150,7 +150,7 @@ class BookmarkTest extends TestCase $exception = $e; } $this->assertNotNull($exception); - $this->assertContains('- ID: '. PHP_EOL, $exception->getMessage()); + $this->assertContainsPolyfill('- ID: '. PHP_EOL, $exception->getMessage()); } /** @@ -169,7 +169,7 @@ class BookmarkTest extends TestCase $exception = $e; } $this->assertNotNull($exception); - $this->assertContains('- ID: str'. PHP_EOL, $exception->getMessage()); + $this->assertContainsPolyfill('- ID: str'. PHP_EOL, $exception->getMessage()); } /** @@ -188,7 +188,7 @@ class BookmarkTest extends TestCase $exception = $e; } $this->assertNotNull($exception); - $this->assertContains('- ShortUrl: '. PHP_EOL, $exception->getMessage()); + $this->assertContainsPolyfill('- ShortUrl: '. PHP_EOL, $exception->getMessage()); } /** @@ -207,7 +207,7 @@ class BookmarkTest extends TestCase $exception = $e; } $this->assertNotNull($exception); - $this->assertContains('- Created: '. PHP_EOL, $exception->getMessage()); + $this->assertContainsPolyfill('- Created: '. PHP_EOL, $exception->getMessage()); } /** @@ -226,7 +226,7 @@ class BookmarkTest extends TestCase $exception = $e; } $this->assertNotNull($exception); - $this->assertContains('- Created: Not a DateTime object'. PHP_EOL, $exception->getMessage()); + $this->assertContainsPolyfill('- Created: Not a DateTime object'. PHP_EOL, $exception->getMessage()); } /** diff --git a/tests/bookmark/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php index 7d4a7b89..a7087953 100644 --- a/tests/bookmark/LinkUtilsTest.php +++ b/tests/bookmark/LinkUtilsTest.php @@ -2,7 +2,7 @@ namespace Shaarli\Bookmark; -use PHPUnit\Framework\TestCase; +use Shaarli\TestCase; require_once 'tests/utils/CurlUtils.php'; @@ -437,13 +437,13 @@ class LinkUtilsTest extends TestCase カタカナ #カタカナ」カタカナ\n'; $autolinkedDescription = hashtag_autolink($rawDescription, $index); - $this->assertContains($this->getHashtagLink('hashtag', $index), $autolinkedDescription); - $this->assertNotContains(' #hashtag', $autolinkedDescription); - $this->assertNotContains('>#nothashtag', $autolinkedDescription); - $this->assertContains($this->getHashtagLink('ашок', $index), $autolinkedDescription); - $this->assertContains($this->getHashtagLink('カタカナ', $index), $autolinkedDescription); - $this->assertContains($this->getHashtagLink('hashtag_hashtag', $index), $autolinkedDescription); - $this->assertNotContains($this->getHashtagLink('hashtag-nothashtag', $index), $autolinkedDescription); + $this->assertContainsPolyfill($this->getHashtagLink('hashtag', $index), $autolinkedDescription); + $this->assertNotContainsPolyfill(' #hashtag', $autolinkedDescription); + $this->assertNotContainsPolyfill('>#nothashtag', $autolinkedDescription); + $this->assertContainsPolyfill($this->getHashtagLink('ашок', $index), $autolinkedDescription); + $this->assertContainsPolyfill($this->getHashtagLink('カタカナ', $index), $autolinkedDescription); + $this->assertContainsPolyfill($this->getHashtagLink('hashtag_hashtag', $index), $autolinkedDescription); + $this->assertNotContainsPolyfill($this->getHashtagLink('hashtag-nothashtag', $index), $autolinkedDescription); } /** @@ -454,9 +454,9 @@ class LinkUtilsTest extends TestCase $rawDescription = 'blabla #hashtag x#nothashtag'; $autolinkedDescription = hashtag_autolink($rawDescription); - $this->assertContains($this->getHashtagLink('hashtag'), $autolinkedDescription); - $this->assertNotContains(' #hashtag', $autolinkedDescription); - $this->assertNotContains('>#nothashtag', $autolinkedDescription); + $this->assertContainsPolyfill($this->getHashtagLink('hashtag'), $autolinkedDescription); + $this->assertNotContainsPolyfill(' #hashtag', $autolinkedDescription); + $this->assertNotContainsPolyfill('>#nothashtag', $autolinkedDescription); } /** diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d4ddedd5..2d675c9a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -18,6 +18,7 @@ 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 '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'; diff --git a/tests/config/ConfigJsonTest.php b/tests/config/ConfigJsonTest.php index f884b0c6..4f508925 100644 --- a/tests/config/ConfigJsonTest.php +++ b/tests/config/ConfigJsonTest.php @@ -4,7 +4,7 @@ namespace Shaarli\Config; /** * Class ConfigJsonTest */ -class ConfigJsonTest extends \PHPUnit\Framework\TestCase +class ConfigJsonTest extends \Shaarli\TestCase { /** * @var ConfigJson diff --git a/tests/config/ConfigManagerTest.php b/tests/config/ConfigManagerTest.php index 802e6524..65d8ba2c 100644 --- a/tests/config/ConfigManagerTest.php +++ b/tests/config/ConfigManagerTest.php @@ -7,7 +7,7 @@ namespace Shaarli\Config; * Note: it only test the manager with ConfigJson, * ConfigPhp is only a workaround to handle the transition to JSON type. */ -class ConfigManagerTest extends \PHPUnit\Framework\TestCase +class ConfigManagerTest extends \Shaarli\TestCase { /** * @var ConfigManager diff --git a/tests/config/ConfigPhpTest.php b/tests/config/ConfigPhpTest.php index a9aa80f5..7bf9fe64 100644 --- a/tests/config/ConfigPhpTest.php +++ b/tests/config/ConfigPhpTest.php @@ -8,7 +8,7 @@ namespace Shaarli\Config; * which are kept between tests. * @runTestsInSeparateProcesses */ -class ConfigPhpTest extends \PHPUnit\Framework\TestCase +class ConfigPhpTest extends \Shaarli\TestCase { /** * @var ConfigPhp diff --git a/tests/config/ConfigPluginTest.php b/tests/config/ConfigPluginTest.php index 3a45f623..fa72d8c4 100644 --- a/tests/config/ConfigPluginTest.php +++ b/tests/config/ConfigPluginTest.php @@ -9,7 +9,7 @@ require_once 'application/config/ConfigPlugin.php'; /** * Unitary tests for Shaarli config related functions */ -class ConfigPluginTest extends \PHPUnit\Framework\TestCase +class ConfigPluginTest extends \Shaarli\TestCase { /** * Test save_plugin_config with valid data. diff --git a/tests/container/ContainerBuilderTest.php b/tests/container/ContainerBuilderTest.php index 2047a63a..5d52daef 100644 --- a/tests/container/ContainerBuilderTest.php +++ b/tests/container/ContainerBuilderTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shaarli\Container; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\BookmarkServiceInterface; use Shaarli\Config\ConfigManager; use Shaarli\Feed\FeedBuilder; @@ -20,6 +19,7 @@ use Shaarli\Render\PageCacheManager; use Shaarli\Security\CookieManager; use Shaarli\Security\LoginManager; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Shaarli\Thumbnailer; use Shaarli\Updater\Updater; use Slim\Http\Environment; diff --git a/tests/feed/CachedPageTest.php b/tests/feed/CachedPageTest.php index 25d640d3..904db9dc 100644 --- a/tests/feed/CachedPageTest.php +++ b/tests/feed/CachedPageTest.php @@ -7,7 +7,7 @@ namespace Shaarli\Feed; /** * Unitary tests for cached pages */ -class CachedPageTest extends \PHPUnit\Framework\TestCase +class CachedPageTest extends \Shaarli\TestCase { // test cache directory protected static $testCacheDir = 'sandbox/pagecache'; diff --git a/tests/feed/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php index 5dfe73aa..c29e8ef3 100644 --- a/tests/feed/FeedBuilderTest.php +++ b/tests/feed/FeedBuilderTest.php @@ -3,7 +3,6 @@ namespace Shaarli\Feed; use DateTime; -use PHPUnit\Framework\TestCase; use ReferenceLinkDB; use Shaarli\Bookmark\Bookmark; use Shaarli\Bookmark\BookmarkFileService; @@ -11,6 +10,7 @@ use Shaarli\Bookmark\LinkDB; use Shaarli\Config\ConfigManager; use Shaarli\Formatter\FormatterFactory; use Shaarli\History; +use Shaarli\TestCase; /** * FeedBuilderTest class. @@ -97,9 +97,9 @@ class FeedBuilderTest extends TestCase $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']); $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']); $this->assertEquals($pub, $up); - $this->assertContains('Stallman has a beard', $link['description']); - $this->assertContains('Permalink', $link['description']); - $this->assertContains('http://host.tld/shaare/WDWyig', $link['description']); + $this->assertContainsPolyfill('Stallman has a beard', $link['description']); + $this->assertContainsPolyfill('Permalink', $link['description']); + $this->assertContainsPolyfill('http://host.tld/shaare/WDWyig', $link['description']); $this->assertEquals(1, count($link['taglist'])); $this->assertEquals('sTuff', $link['taglist'][0]); @@ -201,16 +201,16 @@ class FeedBuilderTest extends TestCase $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->assertContains('Direct link', $link['description']); - $this->assertContains('http://host.tld/shaare/WDWyig', $link['description']); + $this->assertContainsPolyfill('Direct link', $link['description']); + $this->assertContainsPolyfill('http://host.tld/shaare/WDWyig', $link['description']); // 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('http://host.tld/shaare/RttfEw', $link['guid']); $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']); - $this->assertContains('Direct link', $link['description']); - $this->assertContains('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['description']); + $this->assertContainsPolyfill('Direct link', $link['description']); + $this->assertContainsPolyfill('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['description']); } /** @@ -274,6 +274,6 @@ class FeedBuilderTest extends TestCase $link = $data['links'][array_keys($data['links'])[0]]; $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['guid']); $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['url']); - $this->assertContains('http://host.tld:8080/~user/shaarli/./add-tag/hashtag', $link['description']); + $this->assertContainsPolyfill('http://host.tld:8080/~user/shaarli/./add-tag/hashtag', $link['description']); } } diff --git a/tests/formatter/BookmarkDefaultFormatterTest.php b/tests/formatter/BookmarkDefaultFormatterTest.php index 9ea86c14..9534436e 100644 --- a/tests/formatter/BookmarkDefaultFormatterTest.php +++ b/tests/formatter/BookmarkDefaultFormatterTest.php @@ -3,9 +3,9 @@ namespace Shaarli\Formatter; use DateTime; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; use Shaarli\Config\ConfigManager; +use Shaarli\TestCase; /** * Class BookmarkDefaultFormatterTest diff --git a/tests/formatter/BookmarkMarkdownFormatterTest.php b/tests/formatter/BookmarkMarkdownFormatterTest.php index a7729416..ab6b4080 100644 --- a/tests/formatter/BookmarkMarkdownFormatterTest.php +++ b/tests/formatter/BookmarkMarkdownFormatterTest.php @@ -3,9 +3,9 @@ namespace Shaarli\Formatter; use DateTime; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; use Shaarli\Config\ConfigManager; +use Shaarli\TestCase; /** * Class BookmarkMarkdownFormatterTest diff --git a/tests/formatter/BookmarkRawFormatterTest.php b/tests/formatter/BookmarkRawFormatterTest.php index 76cf1172..c76bb7b9 100644 --- a/tests/formatter/BookmarkRawFormatterTest.php +++ b/tests/formatter/BookmarkRawFormatterTest.php @@ -3,9 +3,9 @@ namespace Shaarli\Formatter; use DateTime; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; use Shaarli\Config\ConfigManager; +use Shaarli\TestCase; /** * Class BookmarkRawFormatterTest diff --git a/tests/formatter/FormatterFactoryTest.php b/tests/formatter/FormatterFactoryTest.php index 6aab6a61..ae476cb5 100644 --- a/tests/formatter/FormatterFactoryTest.php +++ b/tests/formatter/FormatterFactoryTest.php @@ -2,8 +2,8 @@ namespace Shaarli\Formatter; -use PHPUnit\Framework\TestCase; use Shaarli\Config\ConfigManager; +use Shaarli\TestCase; /** * Class FormatterFactoryTest diff --git a/tests/front/ShaarliAdminMiddlewareTest.php b/tests/front/ShaarliAdminMiddlewareTest.php index 7451330b..44025f11 100644 --- a/tests/front/ShaarliAdminMiddlewareTest.php +++ b/tests/front/ShaarliAdminMiddlewareTest.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace Shaarli\Front; -use PHPUnit\Framework\TestCase; use Shaarli\Config\ConfigManager; use Shaarli\Container\ShaarliContainer; use Shaarli\Security\LoginManager; +use Shaarli\TestCase; use Shaarli\Updater\Updater; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/ShaarliMiddlewareTest.php b/tests/front/ShaarliMiddlewareTest.php index 05aa34a9..655c5bba 100644 --- a/tests/front/ShaarliMiddlewareTest.php +++ b/tests/front/ShaarliMiddlewareTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shaarli\Front; -use PHPUnit\Framework\TestCase; use Shaarli\Config\ConfigManager; use Shaarli\Container\ShaarliContainer; use Shaarli\Front\Exception\LoginBannedException; @@ -12,6 +11,7 @@ use Shaarli\Front\Exception\UnauthorizedException; use Shaarli\Render\PageBuilder; use Shaarli\Render\PageCacheManager; use Shaarli\Security\LoginManager; +use Shaarli\TestCase; use Shaarli\Updater\Updater; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/admin/ConfigureControllerTest.php b/tests/front/controller/admin/ConfigureControllerTest.php index 612f20f1..aca6cff3 100644 --- a/tests/front/controller/admin/ConfigureControllerTest.php +++ b/tests/front/controller/admin/ConfigureControllerTest.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin; -use PHPUnit\Framework\TestCase; use Shaarli\Config\ConfigManager; use Shaarli\Front\Exception\WrongTokenException; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Shaarli\Thumbnailer; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/admin/ExportControllerTest.php b/tests/front/controller/admin/ExportControllerTest.php index 12d26f4a..0e6f2762 100644 --- a/tests/front/controller/admin/ExportControllerTest.php +++ b/tests/front/controller/admin/ExportControllerTest.php @@ -4,12 +4,12 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; use Shaarli\Formatter\BookmarkFormatter; use Shaarli\Formatter\BookmarkRawFormatter; use Shaarli\Netscape\NetscapeBookmarkUtils; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/admin/ImportControllerTest.php b/tests/front/controller/admin/ImportControllerTest.php index eb31fad0..c266caa5 100644 --- a/tests/front/controller/admin/ImportControllerTest.php +++ b/tests/front/controller/admin/ImportControllerTest.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin; -use PHPUnit\Framework\TestCase; use Psr\Http\Message\UploadedFileInterface; use Shaarli\Netscape\NetscapeBookmarkUtils; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; use Slim\Http\UploadedFile; diff --git a/tests/front/controller/admin/LogoutControllerTest.php b/tests/front/controller/admin/LogoutControllerTest.php index 45e84dc0..94e53019 100644 --- a/tests/front/controller/admin/LogoutControllerTest.php +++ b/tests/front/controller/admin/LogoutControllerTest.php @@ -4,10 +4,9 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin; -use PHPUnit\Framework\TestCase; use Shaarli\Security\CookieManager; -use Shaarli\Security\LoginManager; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/admin/ManageShaareControllerTest/AddShaareTest.php b/tests/front/controller/admin/ManageShaareControllerTest/AddShaareTest.php index 7d5b752a..0f27ec2f 100644 --- a/tests/front/controller/admin/ManageShaareControllerTest/AddShaareTest.php +++ b/tests/front/controller/admin/ManageShaareControllerTest/AddShaareTest.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest; -use PHPUnit\Framework\TestCase; use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper; use Shaarli\Front\Controller\Admin\ManageShaareController; use Shaarli\Http\HttpAccess; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/admin/ManageShaareControllerTest/ChangeVisibilityBookmarkTest.php b/tests/front/controller/admin/ManageShaareControllerTest/ChangeVisibilityBookmarkTest.php index 5a615791..096d0774 100644 --- a/tests/front/controller/admin/ManageShaareControllerTest/ChangeVisibilityBookmarkTest.php +++ b/tests/front/controller/admin/ManageShaareControllerTest/ChangeVisibilityBookmarkTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; use Shaarli\Bookmark\Exception\BookmarkNotFoundException; use Shaarli\Formatter\BookmarkFormatter; @@ -14,6 +13,7 @@ use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper; use Shaarli\Front\Controller\Admin\ManageShaareController; use Shaarli\Http\HttpAccess; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/admin/ManageShaareControllerTest/DeleteBookmarkTest.php b/tests/front/controller/admin/ManageShaareControllerTest/DeleteBookmarkTest.php index dee622bb..ba774e21 100644 --- a/tests/front/controller/admin/ManageShaareControllerTest/DeleteBookmarkTest.php +++ b/tests/front/controller/admin/ManageShaareControllerTest/DeleteBookmarkTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; use Shaarli\Bookmark\Exception\BookmarkNotFoundException; use Shaarli\Formatter\BookmarkFormatter; @@ -13,6 +12,7 @@ use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper; use Shaarli\Front\Controller\Admin\ManageShaareController; use Shaarli\Http\HttpAccess; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/admin/ManageShaareControllerTest/DisplayCreateFormTest.php b/tests/front/controller/admin/ManageShaareControllerTest/DisplayCreateFormTest.php index 777583d5..2eb95251 100644 --- a/tests/front/controller/admin/ManageShaareControllerTest/DisplayCreateFormTest.php +++ b/tests/front/controller/admin/ManageShaareControllerTest/DisplayCreateFormTest.php @@ -4,12 +4,12 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; use Shaarli\Config\ConfigManager; use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper; use Shaarli\Front\Controller\Admin\ManageShaareController; use Shaarli\Http\HttpAccess; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; @@ -96,12 +96,14 @@ class DisplayCreateFormTest extends TestCase // Make sure that PluginManager hook is triggered $this->container->pluginManager - ->expects(static::at(0)) + ->expects(static::atLeastOnce()) ->method('executeHooks') + ->withConsecutive(['render_editlink'], ['render_includes']) ->willReturnCallback(function (string $hook, array $data) use ($remoteTitle, $remoteDesc): array { - static::assertSame('render_editlink', $hook); - static::assertSame($remoteTitle, $data['link']['title']); - static::assertSame($remoteDesc, $data['link']['description']); + if ('render_editlink' === $hook) { + static::assertSame($remoteTitle, $data['link']['title']); + static::assertSame($remoteDesc, $data['link']['description']); + } return $data; }) diff --git a/tests/front/controller/admin/ManageShaareControllerTest/DisplayEditFormTest.php b/tests/front/controller/admin/ManageShaareControllerTest/DisplayEditFormTest.php index 1a1cdcf3..2dc3f41c 100644 --- a/tests/front/controller/admin/ManageShaareControllerTest/DisplayEditFormTest.php +++ b/tests/front/controller/admin/ManageShaareControllerTest/DisplayEditFormTest.php @@ -4,13 +4,13 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; use Shaarli\Bookmark\Exception\BookmarkNotFoundException; use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper; use Shaarli\Front\Controller\Admin\ManageShaareController; use Shaarli\Http\HttpAccess; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/admin/ManageShaareControllerTest/PinBookmarkTest.php b/tests/front/controller/admin/ManageShaareControllerTest/PinBookmarkTest.php index 1607b475..50ce7df1 100644 --- a/tests/front/controller/admin/ManageShaareControllerTest/PinBookmarkTest.php +++ b/tests/front/controller/admin/ManageShaareControllerTest/PinBookmarkTest.php @@ -4,13 +4,13 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; use Shaarli\Bookmark\Exception\BookmarkNotFoundException; use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper; use Shaarli\Front\Controller\Admin\ManageShaareController; use Shaarli\Http\HttpAccess; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php b/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php index 58eaaa9b..3999b44e 100644 --- a/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php +++ b/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; use Shaarli\Config\ConfigManager; use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper; @@ -12,6 +11,7 @@ use Shaarli\Front\Controller\Admin\ManageShaareController; use Shaarli\Front\Exception\WrongTokenException; use Shaarli\Http\HttpAccess; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Shaarli\Thumbnailer; use Slim\Http\Request; use Slim\Http\Response; @@ -88,17 +88,18 @@ class SaveBookmarkTest extends TestCase // Make sure that PluginManager hook is triggered $this->container->pluginManager - ->expects(static::at(0)) + ->expects(static::atLeastOnce()) ->method('executeHooks') + ->withConsecutive(['save_link']) ->willReturnCallback(function (string $hook, array $data) use ($parameters, $id): array { - static::assertSame('save_link', $hook); - - static::assertSame($id, $data['id']); - static::assertSame($parameters['lf_url'], $data['url']); - static::assertSame($parameters['lf_title'], $data['title']); - static::assertSame($parameters['lf_description'], $data['description']); - static::assertSame($parameters['lf_tags'], $data['tags']); - static::assertTrue($data['private']); + if ('save_link' === $hook) { + static::assertSame($id, $data['id']); + static::assertSame($parameters['lf_url'], $data['url']); + static::assertSame($parameters['lf_title'], $data['title']); + static::assertSame($parameters['lf_description'], $data['description']); + static::assertSame($parameters['lf_tags'], $data['tags']); + static::assertTrue($data['private']); + } return $data; }) @@ -174,17 +175,18 @@ class SaveBookmarkTest extends TestCase // Make sure that PluginManager hook is triggered $this->container->pluginManager - ->expects(static::at(0)) + ->expects(static::atLeastOnce()) ->method('executeHooks') + ->withConsecutive(['save_link']) ->willReturnCallback(function (string $hook, array $data) use ($parameters, $id): array { - static::assertSame('save_link', $hook); - - static::assertSame($id, $data['id']); - static::assertSame($parameters['lf_url'], $data['url']); - static::assertSame($parameters['lf_title'], $data['title']); - static::assertSame($parameters['lf_description'], $data['description']); - static::assertSame($parameters['lf_tags'], $data['tags']); - static::assertTrue($data['private']); + if ('save_link' === $hook) { + static::assertSame($id, $data['id']); + static::assertSame($parameters['lf_url'], $data['url']); + static::assertSame($parameters['lf_title'], $data['title']); + static::assertSame($parameters['lf_description'], $data['description']); + static::assertSame($parameters['lf_tags'], $data['tags']); + static::assertTrue($data['private']); + } return $data; }) diff --git a/tests/front/controller/admin/ManageTagControllerTest.php b/tests/front/controller/admin/ManageTagControllerTest.php index 09ba0b4b..8a0ff7a9 100644 --- a/tests/front/controller/admin/ManageTagControllerTest.php +++ b/tests/front/controller/admin/ManageTagControllerTest.php @@ -4,11 +4,11 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; use Shaarli\Bookmark\BookmarkFilter; use Shaarli\Front\Exception\WrongTokenException; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/admin/PasswordControllerTest.php b/tests/front/controller/admin/PasswordControllerTest.php index 9a01089e..58f47b49 100644 --- a/tests/front/controller/admin/PasswordControllerTest.php +++ b/tests/front/controller/admin/PasswordControllerTest.php @@ -4,11 +4,11 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin; -use PHPUnit\Framework\TestCase; use Shaarli\Config\ConfigManager; use Shaarli\Front\Exception\OpenShaarliPasswordException; use Shaarli\Front\Exception\WrongTokenException; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/admin/PluginsControllerTest.php b/tests/front/controller/admin/PluginsControllerTest.php index 9526474c..974d614d 100644 --- a/tests/front/controller/admin/PluginsControllerTest.php +++ b/tests/front/controller/admin/PluginsControllerTest.php @@ -4,11 +4,11 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin; -use PHPUnit\Framework\TestCase; use Shaarli\Config\ConfigManager; use Shaarli\Front\Exception\WrongTokenException; use Shaarli\Plugin\PluginManager; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/admin/SessionFilterControllerTest.php b/tests/front/controller/admin/SessionFilterControllerTest.php index c4253167..712a625b 100644 --- a/tests/front/controller/admin/SessionFilterControllerTest.php +++ b/tests/front/controller/admin/SessionFilterControllerTest.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin; -use PHPUnit\Framework\TestCase; use Shaarli\Security\LoginManager; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/admin/ShaarliAdminControllerTest.php b/tests/front/controller/admin/ShaarliAdminControllerTest.php index fff427cb..486d5d2d 100644 --- a/tests/front/controller/admin/ShaarliAdminControllerTest.php +++ b/tests/front/controller/admin/ShaarliAdminControllerTest.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin; -use PHPUnit\Framework\TestCase; use Shaarli\Front\Exception\WrongTokenException; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Slim\Http\Request; /** diff --git a/tests/front/controller/admin/ThumbnailsControllerTest.php b/tests/front/controller/admin/ThumbnailsControllerTest.php index 0c0c8a83..f4a8acff 100644 --- a/tests/front/controller/admin/ThumbnailsControllerTest.php +++ b/tests/front/controller/admin/ThumbnailsControllerTest.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; use Shaarli\Bookmark\Exception\BookmarkNotFoundException; +use Shaarli\TestCase; use Shaarli\Thumbnailer; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/admin/TokenControllerTest.php b/tests/front/controller/admin/TokenControllerTest.php index 04b0c0fa..d2f0907f 100644 --- a/tests/front/controller/admin/TokenControllerTest.php +++ b/tests/front/controller/admin/TokenControllerTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin; -use PHPUnit\Framework\TestCase; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/admin/ToolsControllerTest.php b/tests/front/controller/admin/ToolsControllerTest.php index 39144d2f..e82f8b14 100644 --- a/tests/front/controller/admin/ToolsControllerTest.php +++ b/tests/front/controller/admin/ToolsControllerTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin; -use PHPUnit\Framework\TestCase; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/visitor/BookmarkListControllerTest.php b/tests/front/controller/visitor/BookmarkListControllerTest.php index 5daaa2c4..0c95df97 100644 --- a/tests/front/controller/visitor/BookmarkListControllerTest.php +++ b/tests/front/controller/visitor/BookmarkListControllerTest.php @@ -4,11 +4,11 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Visitor; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; use Shaarli\Bookmark\Exception\BookmarkNotFoundException; use Shaarli\Config\ConfigManager; use Shaarli\Security\LoginManager; +use Shaarli\TestCase; use Shaarli\Thumbnailer; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/visitor/DailyControllerTest.php b/tests/front/controller/visitor/DailyControllerTest.php index cb5b96f3..fc78bc13 100644 --- a/tests/front/controller/visitor/DailyControllerTest.php +++ b/tests/front/controller/visitor/DailyControllerTest.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Visitor; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; use Shaarli\Feed\CachedPage; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; @@ -78,19 +78,20 @@ class DailyControllerTest extends TestCase // Make sure that PluginManager hook is triggered $this->container->pluginManager - ->expects(static::at(0)) + ->expects(static::atLeastOnce()) ->method('executeHooks') + ->withConsecutive(['render_daily']) ->willReturnCallback(function (string $hook, array $data, array $param) use ($currentDay): array { - static::assertSame('render_daily', $hook); + if ('render_daily' === $hook) { + static::assertArrayHasKey('linksToDisplay', $data); + static::assertCount(3, $data['linksToDisplay']); + static::assertSame(1, $data['linksToDisplay'][0]['id']); + static::assertSame($currentDay->getTimestamp(), $data['day']); + static::assertSame('20200510', $data['previousday']); + static::assertSame('20200516', $data['nextday']); - static::assertArrayHasKey('linksToDisplay', $data); - static::assertCount(3, $data['linksToDisplay']); - static::assertSame(1, $data['linksToDisplay'][0]['id']); - static::assertSame($currentDay->getTimestamp(), $data['day']); - static::assertSame('20200510', $data['previousday']); - static::assertSame('20200516', $data['nextday']); - - static::assertArrayHasKey('loggedin', $param); + static::assertArrayHasKey('loggedin', $param); + } return $data; }) @@ -203,19 +204,20 @@ class DailyControllerTest extends TestCase // Make sure that PluginManager hook is triggered $this->container->pluginManager - ->expects(static::at(0)) + ->expects(static::atLeastOnce()) ->method('executeHooks') + ->withConsecutive(['render_daily']) ->willReturnCallback(function (string $hook, array $data, array $param) use ($currentDay): array { - static::assertSame('render_daily', $hook); - - static::assertArrayHasKey('linksToDisplay', $data); - static::assertCount(1, $data['linksToDisplay']); - static::assertSame(1, $data['linksToDisplay'][0]['id']); - static::assertSame($currentDay->getTimestamp(), $data['day']); - static::assertEmpty($data['previousday']); - static::assertEmpty($data['nextday']); + if ('render_daily' === $hook) { + static::assertArrayHasKey('linksToDisplay', $data); + static::assertCount(1, $data['linksToDisplay']); + static::assertSame(1, $data['linksToDisplay'][0]['id']); + static::assertSame($currentDay->getTimestamp(), $data['day']); + static::assertEmpty($data['previousday']); + static::assertEmpty($data['nextday']); - static::assertArrayHasKey('loggedin', $param); + static::assertArrayHasKey('loggedin', $param); + } return $data; }); @@ -281,7 +283,7 @@ class DailyControllerTest extends TestCase // Make sure that PluginManager hook is triggered $this->container->pluginManager - ->expects(static::at(0)) + ->expects(static::atLeastOnce()) ->method('executeHooks') ->willReturnCallback(function (string $hook, array $data, array $param): array { return $data; @@ -333,7 +335,7 @@ class DailyControllerTest extends TestCase // Make sure that PluginManager hook is triggered $this->container->pluginManager - ->expects(static::at(0)) + ->expects(static::atLeastOnce()) ->method('executeHooks') ->willReturnCallback(function (string $hook, array $data, array $param): array { return $data; diff --git a/tests/front/controller/visitor/ErrorControllerTest.php b/tests/front/controller/visitor/ErrorControllerTest.php index e497bfef..75408cf4 100644 --- a/tests/front/controller/visitor/ErrorControllerTest.php +++ b/tests/front/controller/visitor/ErrorControllerTest.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Visitor; -use PHPUnit\Framework\TestCase; use Shaarli\Front\Exception\ShaarliFrontException; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/visitor/ErrorNotFoundControllerTest.php b/tests/front/controller/visitor/ErrorNotFoundControllerTest.php index 625467b1..a1cbbecf 100644 --- a/tests/front/controller/visitor/ErrorNotFoundControllerTest.php +++ b/tests/front/controller/visitor/ErrorNotFoundControllerTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Visitor; -use PHPUnit\Framework\TestCase; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; use Slim\Http\Uri; diff --git a/tests/front/controller/visitor/FeedControllerTest.php b/tests/front/controller/visitor/FeedControllerTest.php index 0a6b577f..4ae7c925 100644 --- a/tests/front/controller/visitor/FeedControllerTest.php +++ b/tests/front/controller/visitor/FeedControllerTest.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Visitor; -use PHPUnit\Framework\TestCase; use Shaarli\Feed\FeedBuilder; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; @@ -45,14 +45,16 @@ class FeedControllerTest extends TestCase // Make sure that PluginManager hook is triggered $this->container->pluginManager - ->expects(static::at(0)) + ->expects(static::atLeastOnce()) ->method('executeHooks') + ->withConsecutive(['render_feed']) ->willReturnCallback(function (string $hook, array $data, array $param): void { - static::assertSame('render_feed', $hook); - static::assertSame('data', $data['content']); + if ('render_feed' === $hook) { + static::assertSame('data', $data['content']); - static::assertArrayHasKey('loggedin', $param); - static::assertSame('feed.rss', $param['target']); + static::assertArrayHasKey('loggedin', $param); + static::assertSame('feed.rss', $param['target']); + } }) ; @@ -84,14 +86,16 @@ class FeedControllerTest extends TestCase // Make sure that PluginManager hook is triggered $this->container->pluginManager - ->expects(static::at(0)) + ->expects(static::atLeastOnce()) ->method('executeHooks') + ->withConsecutive(['render_feed']) ->willReturnCallback(function (string $hook, array $data, array $param): void { - static::assertSame('render_feed', $hook); - static::assertSame('data', $data['content']); + if ('render_feed' === $hook) { + static::assertSame('data', $data['content']); - static::assertArrayHasKey('loggedin', $param); - static::assertSame('feed.atom', $param['target']); + static::assertArrayHasKey('loggedin', $param); + static::assertSame('feed.atom', $param['target']); + } }) ; @@ -124,14 +128,16 @@ class FeedControllerTest extends TestCase // Make sure that PluginManager hook is triggered $this->container->pluginManager - ->expects(static::at(0)) + ->expects(static::atLeastOnce()) ->method('executeHooks') + ->withConsecutive(['render_feed']) ->willReturnCallback(function (string $hook, array $data, array $param): void { - static::assertSame('render_feed', $hook); - static::assertSame('data', $data['content']); + if ('render_feed' === $hook) { + static::assertSame('data', $data['content']); - static::assertArrayHasKey('loggedin', $param); - static::assertSame('feed.atom', $param['target']); + static::assertArrayHasKey('loggedin', $param); + static::assertSame('feed.atom', $param['target']); + } }) ; diff --git a/tests/front/controller/visitor/FrontControllerMockHelper.php b/tests/front/controller/visitor/FrontControllerMockHelper.php index 6c53289b..fc0bb7d1 100644 --- a/tests/front/controller/visitor/FrontControllerMockHelper.php +++ b/tests/front/controller/visitor/FrontControllerMockHelper.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Visitor; -use PHPUnit\Framework\MockObject\MockObject; use Shaarli\Bookmark\BookmarkServiceInterface; use Shaarli\Config\ConfigManager; use Shaarli\Container\ShaarliTestContainer; @@ -115,5 +114,5 @@ trait FrontControllerMockHelper /** * Force to be used in PHPUnit context. */ - protected abstract function createMock($originalClassName): MockObject; + protected abstract function isInTestsContext(): bool; } diff --git a/tests/front/controller/visitor/InstallControllerTest.php b/tests/front/controller/visitor/InstallControllerTest.php index 994d3f33..345ad544 100644 --- a/tests/front/controller/visitor/InstallControllerTest.php +++ b/tests/front/controller/visitor/InstallControllerTest.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Visitor; -use PHPUnit\Framework\TestCase; use Shaarli\Config\ConfigManager; use Shaarli\Front\Exception\AlreadyInstalledException; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/visitor/LoginControllerTest.php b/tests/front/controller/visitor/LoginControllerTest.php index 0a21f938..1312ccb7 100644 --- a/tests/front/controller/visitor/LoginControllerTest.php +++ b/tests/front/controller/visitor/LoginControllerTest.php @@ -4,13 +4,13 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Visitor; -use PHPUnit\Framework\TestCase; use Shaarli\Config\ConfigManager; use Shaarli\Front\Exception\LoginBannedException; use Shaarli\Front\Exception\WrongTokenException; use Shaarli\Render\TemplatePage; use Shaarli\Security\CookieManager; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/visitor/OpenSearchControllerTest.php b/tests/front/controller/visitor/OpenSearchControllerTest.php index 9609a377..42d876c3 100644 --- a/tests/front/controller/visitor/OpenSearchControllerTest.php +++ b/tests/front/controller/visitor/OpenSearchControllerTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Visitor; -use PHPUnit\Framework\TestCase; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/visitor/PictureWallControllerTest.php b/tests/front/controller/visitor/PictureWallControllerTest.php index 3dc3f292..b868231d 100644 --- a/tests/front/controller/visitor/PictureWallControllerTest.php +++ b/tests/front/controller/visitor/PictureWallControllerTest.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Visitor; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; use Shaarli\Config\ConfigManager; use Shaarli\Front\Exception\ThumbnailsDisabledException; +use Shaarli\TestCase; use Shaarli\Thumbnailer; use Slim\Http\Request; use Slim\Http\Response; @@ -67,15 +67,17 @@ class PictureWallControllerTest extends TestCase // Make sure that PluginManager hook is triggered $this->container->pluginManager - ->expects(static::at(0)) + ->expects(static::atLeastOnce()) ->method('executeHooks') + ->withConsecutive(['render_picwall']) ->willReturnCallback(function (string $hook, array $data, array $param): array { - static::assertSame('render_picwall', $hook); - static::assertArrayHasKey('linksToDisplay', $data); - static::assertCount(2, $data['linksToDisplay']); - static::assertSame(1, $data['linksToDisplay'][0]['id']); - static::assertSame(3, $data['linksToDisplay'][1]['id']); - static::assertArrayHasKey('loggedin', $param); + if ('render_picwall' === $hook) { + static::assertArrayHasKey('linksToDisplay', $data); + static::assertCount(2, $data['linksToDisplay']); + static::assertSame(1, $data['linksToDisplay'][0]['id']); + static::assertSame(3, $data['linksToDisplay'][1]['id']); + static::assertArrayHasKey('loggedin', $param); + } return $data; }); diff --git a/tests/front/controller/visitor/PublicSessionFilterControllerTest.php b/tests/front/controller/visitor/PublicSessionFilterControllerTest.php index b45fbe53..7e3b00af 100644 --- a/tests/front/controller/visitor/PublicSessionFilterControllerTest.php +++ b/tests/front/controller/visitor/PublicSessionFilterControllerTest.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Visitor; -use PHPUnit\Framework\TestCase; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/visitor/ShaarliVisitorControllerTest.php b/tests/front/controller/visitor/ShaarliVisitorControllerTest.php index 00188c02..935ec24e 100644 --- a/tests/front/controller/visitor/ShaarliVisitorControllerTest.php +++ b/tests/front/controller/visitor/ShaarliVisitorControllerTest.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Visitor; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\BookmarkFilter; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/front/controller/visitor/TagCloudControllerTest.php b/tests/front/controller/visitor/TagCloudControllerTest.php index 9a6a4bc0..9305612e 100644 --- a/tests/front/controller/visitor/TagCloudControllerTest.php +++ b/tests/front/controller/visitor/TagCloudControllerTest.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Visitor; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\BookmarkFilter; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; @@ -53,14 +53,16 @@ class TagCloudControllerTest extends TestCase // Make sure that PluginManager hook is triggered $this->container->pluginManager - ->expects(static::at(0)) + ->expects(static::atLeastOnce()) ->method('executeHooks') + ->withConsecutive(['render_tagcloud']) ->willReturnCallback(function (string $hook, array $data, array $param): array { - static::assertSame('render_tagcloud', $hook); - static::assertSame('', $data['search_tags']); - static::assertCount(3, $data['tags']); + if ('render_tagcloud' === $hook) { + static::assertSame('', $data['search_tags']); + static::assertCount(3, $data['tags']); - static::assertArrayHasKey('loggedin', $param); + static::assertArrayHasKey('loggedin', $param); + } return $data; }) @@ -124,14 +126,16 @@ class TagCloudControllerTest extends TestCase // Make sure that PluginManager hook is triggered $this->container->pluginManager - ->expects(static::at(0)) + ->expects(static::atLeastOnce()) ->method('executeHooks') + ->withConsecutive(['render_tagcloud']) ->willReturnCallback(function (string $hook, array $data, array $param): array { - static::assertSame('render_tagcloud', $hook); - static::assertSame('ghi def', $data['search_tags']); - static::assertCount(1, $data['tags']); + if ('render_tagcloud' === $hook) { + static::assertSame('ghi def', $data['search_tags']); + static::assertCount(1, $data['tags']); - static::assertArrayHasKey('loggedin', $param); + static::assertArrayHasKey('loggedin', $param); + } return $data; }) @@ -175,14 +179,16 @@ class TagCloudControllerTest extends TestCase // Make sure that PluginManager hook is triggered $this->container->pluginManager - ->expects(static::at(0)) + ->expects(static::atLeastOnce()) ->method('executeHooks') + ->withConsecutive(['render_tagcloud']) ->willReturnCallback(function (string $hook, array $data, array $param): array { - static::assertSame('render_tagcloud', $hook); - static::assertSame('', $data['search_tags']); - static::assertCount(0, $data['tags']); + if ('render_tagcloud' === $hook) { + static::assertSame('', $data['search_tags']); + static::assertCount(0, $data['tags']); - static::assertArrayHasKey('loggedin', $param); + static::assertArrayHasKey('loggedin', $param); + } return $data; }) @@ -227,14 +233,16 @@ class TagCloudControllerTest extends TestCase // Make sure that PluginManager hook is triggered $this->container->pluginManager - ->expects(static::at(0)) + ->expects(static::atLeastOnce()) ->method('executeHooks') + ->withConsecutive(['render_taglist']) ->willReturnCallback(function (string $hook, array $data, array $param): array { - static::assertSame('render_taglist', $hook); - static::assertSame('', $data['search_tags']); - static::assertCount(3, $data['tags']); + if ('render_taglist' === $hook) { + static::assertSame('', $data['search_tags']); + static::assertCount(3, $data['tags']); - static::assertArrayHasKey('loggedin', $param); + static::assertArrayHasKey('loggedin', $param); + } return $data; }) @@ -297,14 +305,16 @@ class TagCloudControllerTest extends TestCase // Make sure that PluginManager hook is triggered $this->container->pluginManager - ->expects(static::at(0)) + ->expects(static::atLeastOnce()) ->method('executeHooks') + ->withConsecutive(['render_taglist']) ->willReturnCallback(function (string $hook, array $data, array $param): array { - static::assertSame('render_taglist', $hook); - static::assertSame('ghi def', $data['search_tags']); - static::assertCount(1, $data['tags']); + if ('render_taglist' === $hook) { + static::assertSame('ghi def', $data['search_tags']); + static::assertCount(1, $data['tags']); - static::assertArrayHasKey('loggedin', $param); + static::assertArrayHasKey('loggedin', $param); + } return $data; }) @@ -344,14 +354,16 @@ class TagCloudControllerTest extends TestCase // Make sure that PluginManager hook is triggered $this->container->pluginManager - ->expects(static::at(0)) + ->expects(static::atLeastOnce()) ->method('executeHooks') + ->withConsecutive(['render_taglist']) ->willReturnCallback(function (string $hook, array $data, array $param): array { - static::assertSame('render_taglist', $hook); - static::assertSame('', $data['search_tags']); - static::assertCount(0, $data['tags']); + if ('render_taglist' === $hook) { + static::assertSame('', $data['search_tags']); + static::assertCount(0, $data['tags']); - static::assertArrayHasKey('loggedin', $param); + static::assertArrayHasKey('loggedin', $param); + } return $data; }) diff --git a/tests/front/controller/visitor/TagControllerTest.php b/tests/front/controller/visitor/TagControllerTest.php index 43076086..750ea02d 100644 --- a/tests/front/controller/visitor/TagControllerTest.php +++ b/tests/front/controller/visitor/TagControllerTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Visitor; -use PHPUnit\Framework\TestCase; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/http/HttpUtils/ClientIpIdTest.php b/tests/http/HttpUtils/ClientIpIdTest.php index 982e57e0..3a0fcf30 100644 --- a/tests/http/HttpUtils/ClientIpIdTest.php +++ b/tests/http/HttpUtils/ClientIpIdTest.php @@ -10,7 +10,7 @@ require_once 'application/http/HttpUtils.php'; /** * Unitary tests for client_ip_id() */ -class ClientIpIdTest extends \PHPUnit\Framework\TestCase +class ClientIpIdTest extends \Shaarli\TestCase { /** * Get a remote client ID based on its IP diff --git a/tests/http/HttpUtils/GetHttpUrlTest.php b/tests/http/HttpUtils/GetHttpUrlTest.php index 3dc5bc9b..a868ac02 100644 --- a/tests/http/HttpUtils/GetHttpUrlTest.php +++ b/tests/http/HttpUtils/GetHttpUrlTest.php @@ -10,7 +10,7 @@ require_once 'application/http/HttpUtils.php'; /** * Unitary tests for get_http_response() */ -class GetHttpUrlTest extends \PHPUnit\Framework\TestCase +class GetHttpUrlTest extends \Shaarli\TestCase { /** * Get an invalid local URL diff --git a/tests/http/HttpUtils/GetIpAdressFromProxyTest.php b/tests/http/HttpUtils/GetIpAdressFromProxyTest.php index fe3a639e..60cdb992 100644 --- a/tests/http/HttpUtils/GetIpAdressFromProxyTest.php +++ b/tests/http/HttpUtils/GetIpAdressFromProxyTest.php @@ -7,7 +7,7 @@ require_once 'application/http/HttpUtils.php'; /** * Unitary tests for getIpAddressFromProxy() */ -class GetIpAdressFromProxyTest extends \PHPUnit\Framework\TestCase +class GetIpAdressFromProxyTest extends \Shaarli\TestCase { /** diff --git a/tests/http/HttpUtils/IndexUrlTest.php b/tests/http/HttpUtils/IndexUrlTest.php index cce45c51..f283d119 100644 --- a/tests/http/HttpUtils/IndexUrlTest.php +++ b/tests/http/HttpUtils/IndexUrlTest.php @@ -5,7 +5,7 @@ namespace Shaarli\Http; -use PHPUnit\Framework\TestCase; +use Shaarli\TestCase; require_once 'application/http/HttpUtils.php'; diff --git a/tests/http/HttpUtils/IndexUrlTestWithConstant.php b/tests/http/HttpUtils/IndexUrlTestWithConstant.php index 15ca3d72..ecaea724 100644 --- a/tests/http/HttpUtils/IndexUrlTestWithConstant.php +++ b/tests/http/HttpUtils/IndexUrlTestWithConstant.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Shaarli\Http; -use PHPUnit\Framework\TestCase; +use Shaarli\TestCase; /** * Test index_url with SHAARLI_ROOT_URL defined to override automatic retrieval. diff --git a/tests/http/HttpUtils/IsHttpsTest.php b/tests/http/HttpUtils/IsHttpsTest.php index 348956c6..8b3fd93d 100644 --- a/tests/http/HttpUtils/IsHttpsTest.php +++ b/tests/http/HttpUtils/IsHttpsTest.php @@ -9,7 +9,7 @@ require_once 'application/http/HttpUtils.php'; * * Test class for is_https() function. */ -class IsHttpsTest extends \PHPUnit\Framework\TestCase +class IsHttpsTest extends \Shaarli\TestCase { /** diff --git a/tests/http/HttpUtils/PageUrlTest.php b/tests/http/HttpUtils/PageUrlTest.php index f1991716..ebb3e617 100644 --- a/tests/http/HttpUtils/PageUrlTest.php +++ b/tests/http/HttpUtils/PageUrlTest.php @@ -10,7 +10,7 @@ require_once 'application/http/HttpUtils.php'; /** * Unitary tests for page_url() */ -class PageUrlTest extends \PHPUnit\Framework\TestCase +class PageUrlTest extends \Shaarli\TestCase { /** * If on the main page, remove "index.php" from the URL resource diff --git a/tests/http/HttpUtils/ServerUrlTest.php b/tests/http/HttpUtils/ServerUrlTest.php index 9caf1049..339664e1 100644 --- a/tests/http/HttpUtils/ServerUrlTest.php +++ b/tests/http/HttpUtils/ServerUrlTest.php @@ -10,7 +10,7 @@ require_once 'application/http/HttpUtils.php'; /** * Unitary tests for server_url() */ -class ServerUrlTest extends \PHPUnit\Framework\TestCase +class ServerUrlTest extends \Shaarli\TestCase { /** * Detect if the server uses SSL diff --git a/tests/http/UrlTest.php b/tests/http/UrlTest.php index ae92f73a..c6b39c29 100644 --- a/tests/http/UrlTest.php +++ b/tests/http/UrlTest.php @@ -8,7 +8,7 @@ namespace Shaarli\Http; /** * Unitary tests for URL utilities */ -class UrlTest extends \PHPUnit\Framework\TestCase +class UrlTest extends \Shaarli\TestCase { // base URL for tests protected static $baseUrl = 'http://domain.tld:3000'; diff --git a/tests/http/UrlUtils/CleanupUrlTest.php b/tests/http/UrlUtils/CleanupUrlTest.php index 6c4d124b..45690ecf 100644 --- a/tests/http/UrlUtils/CleanupUrlTest.php +++ b/tests/http/UrlUtils/CleanupUrlTest.php @@ -7,7 +7,7 @@ namespace Shaarli\Http; require_once 'application/http/UrlUtils.php'; -class CleanupUrlTest extends \PHPUnit\Framework\TestCase +class CleanupUrlTest extends \Shaarli\TestCase { /** * @var string reference URL diff --git a/tests/http/UrlUtils/GetUrlSchemeTest.php b/tests/http/UrlUtils/GetUrlSchemeTest.php index 2b97f7be..18a9a5e5 100644 --- a/tests/http/UrlUtils/GetUrlSchemeTest.php +++ b/tests/http/UrlUtils/GetUrlSchemeTest.php @@ -7,7 +7,7 @@ namespace Shaarli\Http; require_once 'application/http/UrlUtils.php'; -class GetUrlSchemeTest extends \PHPUnit\Framework\TestCase +class GetUrlSchemeTest extends \Shaarli\TestCase { /** * Get empty scheme string for empty UrlUtils diff --git a/tests/http/UrlUtils/UnparseUrlTest.php b/tests/http/UrlUtils/UnparseUrlTest.php index 040d8c54..5e6246cc 100644 --- a/tests/http/UrlUtils/UnparseUrlTest.php +++ b/tests/http/UrlUtils/UnparseUrlTest.php @@ -10,7 +10,7 @@ require_once 'application/http/UrlUtils.php'; /** * Unitary tests for unparse_url() */ -class UnparseUrlTest extends \PHPUnit\Framework\TestCase +class UnparseUrlTest extends \Shaarli\TestCase { /** * Thanks for building nothing diff --git a/tests/http/UrlUtils/WhitelistProtocolsTest.php b/tests/http/UrlUtils/WhitelistProtocolsTest.php index 69512dbd..b8a6baaa 100644 --- a/tests/http/UrlUtils/WhitelistProtocolsTest.php +++ b/tests/http/UrlUtils/WhitelistProtocolsTest.php @@ -9,7 +9,7 @@ require_once 'application/http/UrlUtils.php'; * * Test whitelist_protocols() function of UrlUtils. */ -class WhitelistProtocolsTest extends \PHPUnit\Framework\TestCase +class WhitelistProtocolsTest extends \Shaarli\TestCase { /** * Test whitelist_protocols() on a note (relative URL). diff --git a/tests/languages/fr/LanguagesFrTest.php b/tests/languages/fr/LanguagesFrTest.php index e412b5bc..d84feed1 100644 --- a/tests/languages/fr/LanguagesFrTest.php +++ b/tests/languages/fr/LanguagesFrTest.php @@ -12,7 +12,7 @@ use Shaarli\Config\ConfigManager; * * @package Shaarli */ -class LanguagesFrTest extends \PHPUnit\Framework\TestCase +class LanguagesFrTest extends \Shaarli\TestCase { /** * @var string Config file path (without extension). diff --git a/tests/legacy/LegacyControllerTest.php b/tests/legacy/LegacyControllerTest.php index 4e52f3e1..1a2549a3 100644 --- a/tests/legacy/LegacyControllerTest.php +++ b/tests/legacy/LegacyControllerTest.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace Shaarli\Legacy; -use PHPUnit\Framework\TestCase; use Shaarli\Front\Controller\Visitor\FrontControllerMockHelper; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; diff --git a/tests/legacy/LegacyLinkDBTest.php b/tests/legacy/LegacyLinkDBTest.php index 819bc272..66746dfc 100644 --- a/tests/legacy/LegacyLinkDBTest.php +++ b/tests/legacy/LegacyLinkDBTest.php @@ -18,7 +18,7 @@ require_once 'tests/utils/ReferenceLinkDB.php'; /** * Unitary tests for LegacyLinkDBTest */ -class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase +class LegacyLinkDBTest extends \Shaarli\TestCase { // datastore to test write operations protected static $testDatastore = 'sandbox/datastore.php'; @@ -258,7 +258,7 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase $link = self::$publicLinkDB->getLinkFromUrl('http://mediagoblin.org/'); $this->assertNotEquals(false, $link); - $this->assertContains( + $this->assertContainsPolyfill( 'A free software media publishing platform', $link['description'] ); @@ -471,9 +471,9 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase $res = $linkDB->renameTag('cartoon', 'Taz'); $this->assertEquals(3, count($res)); - $this->assertContains(' Taz ', $linkDB[4]['tags']); - $this->assertContains(' Taz ', $linkDB[1]['tags']); - $this->assertContains(' Taz ', $linkDB[0]['tags']); + $this->assertContainsPolyfill(' Taz ', $linkDB[4]['tags']); + $this->assertContainsPolyfill(' Taz ', $linkDB[1]['tags']); + $this->assertContainsPolyfill(' Taz ', $linkDB[0]['tags']); } /** @@ -513,7 +513,7 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase $res = $linkDB->renameTag('cartoon', null); $this->assertEquals(3, count($res)); - $this->assertNotContains('cartoon', $linkDB[4]['tags']); + $this->assertNotContainsPolyfill('cartoon', $linkDB[4]['tags']); } /** diff --git a/tests/legacy/LegacyLinkFilterTest.php b/tests/legacy/LegacyLinkFilterTest.php index 9db921a9..82bc93d8 100644 --- a/tests/legacy/LegacyLinkFilterTest.php +++ b/tests/legacy/LegacyLinkFilterTest.php @@ -10,7 +10,7 @@ use Shaarli\Legacy\LegacyLinkFilter; /** * Class LegacyLinkFilterTest. */ -class LegacyLinkFilterTest extends \PHPUnit\Framework\TestCase +class LegacyLinkFilterTest extends \Shaarli\TestCase { /** * @var string Test datastore path. diff --git a/tests/legacy/LegacyUpdaterTest.php b/tests/legacy/LegacyUpdaterTest.php index acfac530..0ddcb4a6 100644 --- a/tests/legacy/LegacyUpdaterTest.php +++ b/tests/legacy/LegacyUpdaterTest.php @@ -20,7 +20,7 @@ require_once 'inc/rain.tpl.class.php'; * Class UpdaterTest. * Runs unit tests against the updater class. */ -class LegacyUpdaterTest extends \PHPUnit\Framework\TestCase +class LegacyUpdaterTest extends \Shaarli\TestCase { /** * @var string Path to test datastore. @@ -725,7 +725,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; $this->assertEquals(\Shaarli\Thumbnailer::MODE_ALL, $this->conf->get('thumbnails.mode')); $this->assertEquals(125, $this->conf->get('thumbnails.width')); $this->assertEquals(90, $this->conf->get('thumbnails.height')); - $this->assertContains('You have enabled or changed thumbnails', $_SESSION['warnings'][0]); + $this->assertContainsPolyfill('You have enabled or changed thumbnails', $_SESSION['warnings'][0]); } /** diff --git a/tests/netscape/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php index a6eacae4..adf62f4f 100644 --- a/tests/netscape/BookmarkExportTest.php +++ b/tests/netscape/BookmarkExportTest.php @@ -2,12 +2,12 @@ namespace Shaarli\Netscape; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Config\ConfigManager; use Shaarli\Formatter\BookmarkFormatter; use Shaarli\Formatter\FormatterFactory; use Shaarli\History; +use Shaarli\TestCase; require_once 'tests/utils/ReferenceLinkDB.php'; diff --git a/tests/netscape/BookmarkImportTest.php b/tests/netscape/BookmarkImportTest.php index 89ae4aa7..c1e49b5f 100644 --- a/tests/netscape/BookmarkImportTest.php +++ b/tests/netscape/BookmarkImportTest.php @@ -3,13 +3,13 @@ namespace Shaarli\Netscape; use DateTime; -use PHPUnit\Framework\TestCase; use Psr\Http\Message\UploadedFileInterface; use Shaarli\Bookmark\Bookmark; use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Bookmark\BookmarkFilter; use Shaarli\Config\ConfigManager; use Shaarli\History; +use Shaarli\TestCase; use Slim\Http\UploadedFile; /** diff --git a/tests/plugins/PluginAddlinkTest.php b/tests/plugins/PluginAddlinkTest.php index 1f60d289..a3ec9fc9 100644 --- a/tests/plugins/PluginAddlinkTest.php +++ b/tests/plugins/PluginAddlinkTest.php @@ -9,7 +9,7 @@ require_once 'plugins/addlink_toolbar/addlink_toolbar.php'; /** * Unit test for the Addlink toolbar plugin */ -class PluginAddlinkTest extends \PHPUnit\Framework\TestCase +class PluginAddlinkTest extends \Shaarli\TestCase { /** * Reset plugin path. diff --git a/tests/plugins/PluginArchiveorgTest.php b/tests/plugins/PluginArchiveorgTest.php index 9c19752c..467dc3d0 100644 --- a/tests/plugins/PluginArchiveorgTest.php +++ b/tests/plugins/PluginArchiveorgTest.php @@ -6,8 +6,8 @@ namespace Shaarli\Plugin\Archiveorg; * PluginArchiveorgTest.php */ -use PHPUnit\Framework\TestCase; use Shaarli\Plugin\PluginManager; +use Shaarli\TestCase; require_once 'plugins/archiveorg/archiveorg.php'; diff --git a/tests/plugins/PluginDefaultColorsTest.php b/tests/plugins/PluginDefaultColorsTest.php index 240bb4b2..cc844c60 100644 --- a/tests/plugins/PluginDefaultColorsTest.php +++ b/tests/plugins/PluginDefaultColorsTest.php @@ -2,10 +2,10 @@ namespace Shaarli\Plugin\DefaultColors; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\LinkDB; use Shaarli\Config\ConfigManager; use Shaarli\Plugin\PluginManager; +use Shaarli\TestCase; require_once 'plugins/default_colors/default_colors.php'; diff --git a/tests/plugins/PluginIssoTest.php b/tests/plugins/PluginIssoTest.php index 2bbb93d2..16ecf357 100644 --- a/tests/plugins/PluginIssoTest.php +++ b/tests/plugins/PluginIssoTest.php @@ -2,10 +2,10 @@ namespace Shaarli\Plugin\Isso; use DateTime; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; use Shaarli\Config\ConfigManager; use Shaarli\Plugin\PluginManager; +use Shaarli\TestCase; require_once 'plugins/isso/isso.php'; @@ -116,8 +116,8 @@ class PluginIssoTest extends TestCase $processed = hook_isso_render_linklist($data, $conf); // link_plugin should be added for the icon - $this->assertContains('', $processed['links'][0]['link_plugin'][0]); - $this->assertContains('', $processed['links'][1]['link_plugin'][0]); + $this->assertContainsPolyfill('', $processed['links'][0]['link_plugin'][0]); + $this->assertContainsPolyfill('', $processed['links'][1]['link_plugin'][0]); } /** @@ -146,7 +146,7 @@ class PluginIssoTest extends TestCase $processed = hook_isso_render_linklist($data, $conf); // link_plugin should be added for the icon - $this->assertContains('', $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 de1a1aec..338d2e35 100644 --- a/tests/plugins/PluginPlayvideosTest.php +++ b/tests/plugins/PluginPlayvideosTest.php @@ -14,7 +14,7 @@ require_once 'plugins/playvideos/playvideos.php'; * Class PluginPlayvideosTest * Unit test for the PlayVideos plugin */ -class PluginPlayvideosTest extends \PHPUnit\Framework\TestCase +class PluginPlayvideosTest extends \Shaarli\TestCase { /** * Reset plugin path diff --git a/tests/plugins/PluginPubsubhubbubTest.php b/tests/plugins/PluginPubsubhubbubTest.php index d30c3703..d3f7b439 100644 --- a/tests/plugins/PluginPubsubhubbubTest.php +++ b/tests/plugins/PluginPubsubhubbubTest.php @@ -11,7 +11,7 @@ require_once 'plugins/pubsubhubbub/pubsubhubbub.php'; * Class PluginPubsubhubbubTest * Unit test for the pubsubhubbub plugin */ -class PluginPubsubhubbubTest extends \PHPUnit\Framework\TestCase +class PluginPubsubhubbubTest extends \Shaarli\TestCase { /** * @var string Config file path (without extension). diff --git a/tests/plugins/PluginQrcodeTest.php b/tests/plugins/PluginQrcodeTest.php index bc6be0eb..1d85fba6 100644 --- a/tests/plugins/PluginQrcodeTest.php +++ b/tests/plugins/PluginQrcodeTest.php @@ -14,7 +14,7 @@ require_once 'plugins/qrcode/qrcode.php'; * Class PluginQrcodeTest * Unit test for the QR-Code plugin */ -class PluginQrcodeTest extends \PHPUnit\Framework\TestCase +class PluginQrcodeTest extends \Shaarli\TestCase { /** * Reset plugin path diff --git a/tests/plugins/PluginWallabagTest.php b/tests/plugins/PluginWallabagTest.php index 372929ea..36317215 100644 --- a/tests/plugins/PluginWallabagTest.php +++ b/tests/plugins/PluginWallabagTest.php @@ -10,7 +10,7 @@ require_once 'plugins/wallabag/wallabag.php'; * Class PluginWallabagTest * Unit test for the Wallabag plugin */ -class PluginWallabagTest extends \PHPUnit\Framework\TestCase +class PluginWallabagTest extends \Shaarli\TestCase { /** * Reset plugin path diff --git a/tests/plugins/WallabagInstanceTest.php b/tests/plugins/WallabagInstanceTest.php index 4cb0d4cc..5ef3de1a 100644 --- a/tests/plugins/WallabagInstanceTest.php +++ b/tests/plugins/WallabagInstanceTest.php @@ -4,7 +4,7 @@ namespace Shaarli\Plugin\Wallabag; /** * Class WallabagInstanceTest */ -class WallabagInstanceTest extends \PHPUnit\Framework\TestCase +class WallabagInstanceTest extends \Shaarli\TestCase { /** * @var string wallabag url. diff --git a/tests/render/PageCacheManagerTest.php b/tests/render/PageCacheManagerTest.php index 4aa7e179..08d4e5ea 100644 --- a/tests/render/PageCacheManagerTest.php +++ b/tests/render/PageCacheManagerTest.php @@ -6,8 +6,8 @@ namespace Shaarli\Render; -use PHPUnit\Framework\TestCase; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; /** * Unitary tests for cached pages diff --git a/tests/render/ThemeUtilsTest.php b/tests/render/ThemeUtilsTest.php index 58e3426b..7d841e4d 100644 --- a/tests/render/ThemeUtilsTest.php +++ b/tests/render/ThemeUtilsTest.php @@ -7,7 +7,7 @@ namespace Shaarli\Render; * * @package Shaarli */ -class ThemeUtilsTest extends \PHPUnit\Framework\TestCase +class ThemeUtilsTest extends \Shaarli\TestCase { /** * Test getThemes() with existing theme directories. diff --git a/tests/security/BanManagerTest.php b/tests/security/BanManagerTest.php index 2fef82f5..698d3d10 100644 --- a/tests/security/BanManagerTest.php +++ b/tests/security/BanManagerTest.php @@ -3,8 +3,8 @@ namespace Shaarli\Security; -use PHPUnit\Framework\TestCase; use Shaarli\FileUtils; +use Shaarli\TestCase; /** * Test coverage for BanManager diff --git a/tests/security/LoginManagerTest.php b/tests/security/LoginManagerTest.php index cc9aa647..d302983d 100644 --- a/tests/security/LoginManagerTest.php +++ b/tests/security/LoginManagerTest.php @@ -2,7 +2,7 @@ namespace Shaarli\Security; -use PHPUnit\Framework\TestCase; +use Shaarli\TestCase; /** * Test coverage for LoginManager diff --git a/tests/security/SessionManagerTest.php b/tests/security/SessionManagerTest.php index 27e3b1a9..3f9c3ef5 100644 --- a/tests/security/SessionManagerTest.php +++ b/tests/security/SessionManagerTest.php @@ -2,7 +2,7 @@ namespace Shaarli\Security; -use PHPUnit\Framework\TestCase; +use Shaarli\TestCase; /** * Test coverage for SessionManager diff --git a/tests/updater/UpdaterTest.php b/tests/updater/UpdaterTest.php index 5cfcd5db..73029e07 100644 --- a/tests/updater/UpdaterTest.php +++ b/tests/updater/UpdaterTest.php @@ -2,11 +2,11 @@ namespace Shaarli\Updater; use Exception; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Bookmark\BookmarkServiceInterface; use Shaarli\Config\ConfigManager; use Shaarli\History; +use Shaarli\TestCase; /** -- cgit v1.2.3 From ab58f2542072e6bf34acd862f6cfed84b33feb29 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 29 Sep 2020 15:00:11 +0200 Subject: Compatibility with PHP 8 --- tests/PluginManagerTest.php | 4 ++-- tests/config/ConfigJsonTest.php | 13 +------------ tests/updater/DummyUpdater.php | 8 ++++---- 3 files changed, 7 insertions(+), 18 deletions(-) (limited to 'tests') diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php index 38cd5eba..bbd2e142 100644 --- a/tests/PluginManagerTest.php +++ b/tests/PluginManagerTest.php @@ -81,8 +81,8 @@ class PluginManagerTest extends \Shaarli\TestCase $data = []; $this->pluginManager->executeHooks('error', $data); - $this->assertSame( - 'test [plugin incompatibility]: Class \'Unknown\' not found', + $this->assertMatchesRegularExpression( + '/test \[plugin incompatibility\]: Class [\'"]Unknown[\'"] not found/', $this->pluginManager->getErrors()[0] ); } diff --git a/tests/config/ConfigJsonTest.php b/tests/config/ConfigJsonTest.php index 4f508925..c0ba5b8f 100644 --- a/tests/config/ConfigJsonTest.php +++ b/tests/config/ConfigJsonTest.php @@ -42,7 +42,7 @@ class ConfigJsonTest extends \Shaarli\TestCase public function testReadInvalidJson() { $this->expectException(\Exception::class); - $this->expectExceptionMessageRegExp(' /An error occurred while parsing JSON configuration file \\([\\w\\/\\.]+\\): error code #4/'); + $this->expectExceptionMessageRegExp('/An error occurred while parsing JSON configuration file \\([\\w\\/\\.]+\\): error code #4/'); $this->configIO->read('tests/utils/config/configInvalid.json.php'); } @@ -108,17 +108,6 @@ class ConfigJsonTest extends \Shaarli\TestCase unlink($dest); } - /** - * Write to invalid path. - */ - public function testWriteInvalidArray() - { - $this->expectException(\Shaarli\Exceptions\IOException::class); - - $conf = array('conf' => 'value'); - @$this->configIO->write(array(), $conf); - } - /** * Write to invalid path. */ diff --git a/tests/updater/DummyUpdater.php b/tests/updater/DummyUpdater.php index 07c7f5c4..3403233f 100644 --- a/tests/updater/DummyUpdater.php +++ b/tests/updater/DummyUpdater.php @@ -37,7 +37,7 @@ class DummyUpdater extends Updater * * @return bool true. */ - final private function updateMethodDummy1() + final protected function updateMethodDummy1() { return true; } @@ -47,7 +47,7 @@ class DummyUpdater extends Updater * * @return bool true. */ - final private function updateMethodDummy2() + final protected function updateMethodDummy2() { return true; } @@ -57,7 +57,7 @@ class DummyUpdater extends Updater * * @return bool true. */ - final private function updateMethodDummy3() + final protected function updateMethodDummy3() { return true; } @@ -67,7 +67,7 @@ class DummyUpdater extends Updater * * @throws Exception error. */ - final private function updateMethodException() + final protected function updateMethodException() { throw new Exception('whatever'); } -- cgit v1.2.3 From f447edb73b1bcb52e86286467d3ec7b7bdc29948 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 29 Sep 2020 18:41:21 +0200 Subject: Fix missing @expectedException convertion --- tests/ApplicationUtilsTest.php | 6 +++--- tests/bookmark/BookmarkFileServiceTest.php | 3 +-- tests/bookmark/BookmarkFilterTest.php | 4 ++-- tests/legacy/LegacyLinkDBTest.php | 3 +-- tests/legacy/LegacyLinkFilterTest.php | 4 ++-- tests/legacy/LegacyUpdaterTest.php | 6 ++---- tests/netscape/BookmarkExportTest.php | 2 +- tests/updater/UpdaterTest.php | 6 ++---- 8 files changed, 14 insertions(+), 20 deletions(-) (limited to 'tests') diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php index 7ad1d34c..a232b351 100644 --- a/tests/ApplicationUtilsTest.php +++ b/tests/ApplicationUtilsTest.php @@ -144,10 +144,10 @@ class ApplicationUtilsTest extends \Shaarli\TestCase /** * Test update checks - invalid Git branch - * @expectedException Exception */ public function testCheckUpdateInvalidGitBranch() { + $this->expectException(\Exception::class); $this->expectExceptionMessageRegExp('/Invalid branch selected for updates/'); ApplicationUtils::checkUpdate('', 'null', 0, true, true, 'unstable'); @@ -261,10 +261,10 @@ class ApplicationUtilsTest extends \Shaarli\TestCase /** * Check a unsupported PHP version - * @expectedException Exception */ public function testCheckSupportedPHPVersion51() { + $this->expectException(\Exception::class); $this->expectExceptionMessageRegExp('/Your PHP version is obsolete/'); $this->assertTrue(ApplicationUtils::checkPHPVersion('5.3', '5.1.0')); @@ -272,10 +272,10 @@ class ApplicationUtilsTest extends \Shaarli\TestCase /** * Check another unsupported PHP version - * @expectedException Exception */ public function testCheckSupportedPHPVersion52() { + $this->expectException(\Exception::class); $this->expectExceptionMessageRegExp('/Your PHP version is obsolete/'); $this->assertTrue(ApplicationUtils::checkPHPVersion('5.3', '5.2')); diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php index 51e71a85..c399822b 100644 --- a/tests/bookmark/BookmarkFileServiceTest.php +++ b/tests/bookmark/BookmarkFileServiceTest.php @@ -637,11 +637,10 @@ class BookmarkFileServiceTest extends TestCase */ /** * Attempt to instantiate a LinkDB whereas the datastore is not writable - * - * @expectedException Shaarli\Bookmark\Exception\NotWritableDataStoreException */ public function testConstructDatastoreNotWriteable() { + $this->expectException(\Shaarli\Bookmark\Exception\NotWritableDataStoreException::class); $this->expectExceptionMessageRegExp('#Couldn\'t load data from the data store file "null".*#'); $conf = new ConfigManager('tests/utils/config/configJson'); diff --git a/tests/bookmark/BookmarkFilterTest.php b/tests/bookmark/BookmarkFilterTest.php index 2f15cb3c..48c7f824 100644 --- a/tests/bookmark/BookmarkFilterTest.php +++ b/tests/bookmark/BookmarkFilterTest.php @@ -212,10 +212,10 @@ class BookmarkFilterTest extends TestCase /** * Use an invalid date format - * @expectedException Exception */ public function testFilterInvalidDayWithChars() { + $this->expectException(\Exception::class); $this->expectExceptionMessageRegExp('/Invalid date format/'); self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, 'Rainy day, dream away'); @@ -223,10 +223,10 @@ class BookmarkFilterTest extends TestCase /** * Use an invalid date format - * @expectedException Exception */ public function testFilterInvalidDayDigits() { + $this->expectException(\Exception::class); $this->expectExceptionMessageRegExp('/Invalid date format/'); self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20'); diff --git a/tests/legacy/LegacyLinkDBTest.php b/tests/legacy/LegacyLinkDBTest.php index 66746dfc..df2cad62 100644 --- a/tests/legacy/LegacyLinkDBTest.php +++ b/tests/legacy/LegacyLinkDBTest.php @@ -99,11 +99,10 @@ class LegacyLinkDBTest extends \Shaarli\TestCase /** * Attempt to instantiate a LinkDB whereas the datastore is not writable - * - * @expectedException Shaarli\Exceptions\IOException */ public function testConstructDatastoreNotWriteable() { + $this->expectException(\Shaarli\Exceptions\IOException::class); $this->expectExceptionMessageRegExp('/Error accessing "null"/'); new LegacyLinkDB('null/store.db', false, false); diff --git a/tests/legacy/LegacyLinkFilterTest.php b/tests/legacy/LegacyLinkFilterTest.php index 82bc93d8..45d7754d 100644 --- a/tests/legacy/LegacyLinkFilterTest.php +++ b/tests/legacy/LegacyLinkFilterTest.php @@ -197,10 +197,10 @@ class LegacyLinkFilterTest extends \Shaarli\TestCase /** * Use an invalid date format - * @expectedException Exception */ public function testFilterInvalidDayWithChars() { + $this->expectException(\Exception::class); $this->expectExceptionMessageRegExp('/Invalid date format/'); self::$linkFilter->filter(LegacyLinkFilter::$FILTER_DAY, 'Rainy day, dream away'); @@ -208,10 +208,10 @@ class LegacyLinkFilterTest extends \Shaarli\TestCase /** * Use an invalid date format - * @expectedException Exception */ public function testFilterInvalidDayDigits() { + $this->expectException(\Exception::class); $this->expectExceptionMessageRegExp('/Invalid date format/'); self::$linkFilter->filter(LegacyLinkFilter::$FILTER_DAY, '20'); diff --git a/tests/legacy/LegacyUpdaterTest.php b/tests/legacy/LegacyUpdaterTest.php index 0ddcb4a6..f7391b86 100644 --- a/tests/legacy/LegacyUpdaterTest.php +++ b/tests/legacy/LegacyUpdaterTest.php @@ -80,11 +80,10 @@ class LegacyUpdaterTest extends \Shaarli\TestCase /** * Test errors in UpdaterUtils::write_updates_file(): empty updates file. - * - * @expectedException Exception */ public function testWriteEmptyUpdatesFile() { + $this->expectException(\Exception::class); $this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/'); UpdaterUtils::write_updates_file('', array('test')); @@ -92,11 +91,10 @@ class LegacyUpdaterTest extends \Shaarli\TestCase /** * Test errors in UpdaterUtils::write_updates_file(): not writable updates file. - * - * @expectedException Exception */ public function testWriteUpdatesFileNotWritable() { + $this->expectException(\Exception::class); $this->expectExceptionMessageRegExp('/Unable to write(.*)/'); $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt'; diff --git a/tests/netscape/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php index adf62f4f..9b95ccc9 100644 --- a/tests/netscape/BookmarkExportTest.php +++ b/tests/netscape/BookmarkExportTest.php @@ -77,10 +77,10 @@ class BookmarkExportTest extends TestCase /** * Attempt to export an invalid link selection - * @expectedException Exception */ public function testFilterAndFormatInvalid() { + $this->expectException(\Exception::class); $this->expectExceptionMessageRegExp('/Invalid export selection/'); $this->netscapeBookmarkUtils->filterAndFormat( diff --git a/tests/updater/UpdaterTest.php b/tests/updater/UpdaterTest.php index 73029e07..a6280b8c 100644 --- a/tests/updater/UpdaterTest.php +++ b/tests/updater/UpdaterTest.php @@ -87,11 +87,10 @@ class UpdaterTest extends TestCase /** * Test errors in UpdaterUtils::write_updates_file(): empty updates file. - * - * @expectedException Exception */ public function testWriteEmptyUpdatesFile() { + $this->expectException(\Exception::class); $this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/'); UpdaterUtils::write_updates_file('', array('test')); @@ -99,11 +98,10 @@ class UpdaterTest extends TestCase /** * Test errors in UpdaterUtils::write_updates_file(): not writable updates file. - * - * @expectedException Exception */ public function testWriteUpdatesFileNotWritable() { + $this->expectException(\Exception::class); $this->expectExceptionMessageRegExp('/Unable to write(.*)/'); $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt'; -- cgit v1.2.3 From d246e2c5129fe8d3f8e1429b4e8ff8e3e486c779 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 29 Sep 2020 18:49:02 +0200 Subject: Use assertRegExp polyfill instead of regexMatches --- tests/PluginManagerTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php index bbd2e142..efef5e87 100644 --- a/tests/PluginManagerTest.php +++ b/tests/PluginManagerTest.php @@ -1,4 +1,5 @@ pluginManager->executeHooks('error', $data); - $this->assertMatchesRegularExpression( + $this->assertRegExp( '/test \[plugin incompatibility\]: Class [\'"]Unknown[\'"] not found/', $this->pluginManager->getErrors()[0] ); -- cgit v1.2.3