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/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 +- 35 files changed, 157 insertions(+), 133 deletions(-) (limited to 'tests/front') 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; -- cgit v1.2.3