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 --- .../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 +- 14 files changed, 110 insertions(+), 89 deletions(-) (limited to 'tests/front/controller/visitor') 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