diff --git a/plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php b/plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php index 24fbe8bf027..d8df8881fc1 100755 --- a/plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php +++ b/plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php @@ -35,6 +35,7 @@ use APP\section\Section; use APP\submission\Submission; use Illuminate\Support\LazyCollection; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use PKP\author\Repository as AuthorRepository; use PKP\core\Dispatcher; @@ -48,6 +49,8 @@ use PKP\submission\SubmissionSubjectDAO; use PKP\tests\PKPTestCase; +#[CoversClass(OAIMetadataFormat_DC::class)] +#[CoversClass(\APP\plugins\metadata\dc11\filter\Dc11SchemaArticleAdapter::class)] class OAIMetadataFormat_DCTest extends PKPTestCase { /** @@ -74,10 +77,6 @@ protected function getMockedContainerKeys(): array return [...parent::getMockedContainerKeys(), GalleyCollector::class, AuthorRepository::class]; } - /** - * @covers OAIMetadataFormat_DC - * @covers \APP\plugins\metadata\dc11\filter\Dc11SchemaArticleAdapter - */ public function testToXml() { // @@ -123,14 +122,14 @@ public function testToXml() ->getMock(); $article->expects($this->any()) ->method('getId') - ->will($this->returnValue(9)); + ->willReturn(9); $article->setData('locale', 'en'); $article->setId(9); $article->setData('contextId', $journalId); $author->setSubmissionId($article->getId()); $article->expects($this->any()) ->method('getCurrentPublication') - ->will($this->returnValue($publication)); + ->willReturn($publication); /** @var Doi|MockObject */ $galleyDoiObject = $this->getMockBuilder(Doi::class) @@ -147,10 +146,10 @@ public function testToXml() ->getMock(); $galley->expects(self::any()) ->method('getFileType') - ->will($this->returnValue('galley-filetype')); + ->willReturn('galley-filetype'); $galley->expects(self::any()) ->method('getBestGalleyId') - ->will($this->returnValue(98)); + ->willReturn(98); $galley->setId(98); $galley->setData('doiObject', $galleyDoiObject); $galley->setData('locale', 'en'); @@ -165,7 +164,7 @@ public function testToXml() $journal->expects($this->any()) ->method('getSetting') ->with('publishingMode') - ->will($this->returnValue(Journal::PUBLISHING_MODE_OPEN)); + ->willReturn(Journal::PUBLISHING_MODE_OPEN); $journal->setName('journal-title', 'en'); $journal->setData('publisherInstitution', 'journal-publisher'); $journal->setPrimaryLocale('en'); @@ -192,7 +191,7 @@ public function testToXml() ->getMock(); $issue->expects($this->any()) ->method('getIssueIdentification') - ->will($this->returnValue('issue-identification')); + ->willReturn('issue-identification'); $issue->setId(96); $issue->setDatePublished('2010-11-05'); $issue->setData('doiObject', $issueDoiObject); @@ -217,8 +216,8 @@ public function testToXml() // Dispatcher /** @var Dispatcher|MockObject */ $dispatcher = $this->getMockBuilder(Dispatcher::class) - ->onlyMethods(['url']) - ->getMock(); + ->onlyMethods(['url']) + ->getMock(); $dispatcher->expects($this->any()) ->method('url') ->will($this->returnCallback(fn ($request, $shortcut, $newContext = null, $handler = null, $op = null, $path = null) => $handler . '-' . $op . '-' . implode('-', $path))); @@ -229,10 +228,10 @@ public function testToXml() ->getMock(); $requestMock->expects($this->any()) ->method('getRouter') - ->will($this->returnValue($router)); + ->willReturn($router); $requestMock->expects($this->any()) ->method('getDispatcher') - ->will($this->returnValue($dispatcher)); + ->willReturn($dispatcher); Registry::set('request', $requestMock); // @@ -245,13 +244,13 @@ public function testToXml() ->getMock(); $oaiDao->expects($this->any()) ->method('getJournal') - ->will($this->returnValue($journal)); + ->willReturn($journal); $oaiDao->expects($this->any()) ->method('getSection') - ->will($this->returnValue($section)); + ->willReturn($section); $oaiDao->expects($this->any()) ->method('getIssue') - ->will($this->returnValue($issue)); + ->willReturn($issue); DAORegistry::registerDAO('OAIDAO', $oaiDao); /** @var GalleyCollector|MockObject */ @@ -261,7 +260,7 @@ public function testToXml() ->getMock(); $mockGalleyCollector->expects($this->any()) ->method('getMany') - ->will($this->returnValue(LazyCollection::wrap($galleys))); + ->willReturn(LazyCollection::wrap($galleys)); app()->instance(GalleyCollector::class, $mockGalleyCollector); // Mocked DAO to return the subjects @@ -270,7 +269,7 @@ public function testToXml() ->getMock(); $submissionSubjectDao->expects($this->any()) ->method('getSubjects') - ->will($this->returnValue(['en' => ['article-subject', 'article-subject-class']])); + ->willReturn(['en' => ['article-subject', 'article-subject-class']]); DAORegistry::registerDAO('SubmissionSubjectDAO', $submissionSubjectDao); // Mocked DAO to return the keywords @@ -279,7 +278,7 @@ public function testToXml() ->getMock(); $submissionKeywordDao->expects($this->any()) ->method('getKeywords') - ->will($this->returnValue(['en' => ['article-keyword']])); + ->willReturn(['en' => ['article-keyword']]); DAORegistry::registerDAO('SubmissionKeywordDAO', $submissionKeywordDao); diff --git a/tests/classes/search/ArticleSearchIndexTest.php b/tests/classes/search/ArticleSearchIndexTest.php index f4c85f3fc8d..c8fd1d9f3ff 100644 --- a/tests/classes/search/ArticleSearchIndexTest.php +++ b/tests/classes/search/ArticleSearchIndexTest.php @@ -26,6 +26,7 @@ use APP\submission\Submission; use Mockery; use Mockery\MockInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use PKP\db\DAORegistry; use PKP\db\DAOResultFactory; @@ -34,6 +35,7 @@ use PKP\submissionFile\SubmissionFile; use PKP\tests\PKPTestCase; +#[CoversClass(ArticleSearchIndex::class)] class ArticleSearchIndexTest extends PKPTestCase { // @@ -77,9 +79,7 @@ protected function tearDown(): void // // Unit tests // - /** - * @covers ArticleSearchIndex - */ + public function testUpdateFileIndexViaPluginHook() { // Diverting to the search plugin hook. @@ -100,9 +100,6 @@ public function testUpdateFileIndexViaPluginHook() Hook::clear('ArticleSearchIndex::submissionFileChanged'); } - /** - * @covers ArticleSearchIndex - */ public function testDeleteTextIndex() { // Prepare the mock environment for this test. @@ -116,9 +113,6 @@ public function testDeleteTextIndex() $articleSearchIndex->submissionFileDeleted(0); } - /** - * @covers ArticleSearchIndex - */ public function testDeleteTextIndexViaPluginHook() { // Diverting to the search plugin hook. @@ -140,9 +134,6 @@ public function testDeleteTextIndexViaPluginHook() Hook::clear('ArticleSearchIndex::submissionFileDeleted'); } - /** - * @covers ArticleSearchIndex - */ public function testRebuildIndex() { // Prepare the mock environment for this test. @@ -160,9 +151,6 @@ public function testRebuildIndex() $articleSearchIndex->rebuildIndex(true); } - /** - * @covers ArticleSearchIndex - */ public function testRebuildIndexViaPluginHook() { // Diverting to the search plugin hook. @@ -180,9 +168,6 @@ public function testRebuildIndexViaPluginHook() Hook::clear('ArticleSearchIndex::rebuildIndex'); } - /** - * @covers ArticleSearchIndex - */ public function testIndexArticleMetadata() { // Make sure that no hook is being called. @@ -203,16 +188,13 @@ public function testIndexArticleMetadata() ->getMock(); $article->expects($this->any()) ->method('getCurrentPublication') - ->will($this->returnValue($publication)); + ->willReturn($publication); // Test indexing an article with a mock environment. $articleSearchIndex = $this->getMockArticleSearchIndex($this->atLeastOnce()); $articleSearchIndex->submissionMetadataChanged($article); } - /** - * @covers ArticleSearchIndex - */ public function testIndexArticleMetadataViaPluginHook() { // Diverting to the search plugin hook. @@ -231,9 +213,6 @@ public function testIndexArticleMetadataViaPluginHook() Hook::clear('ArticleSearchIndex::articleMetadataChanged'); } - /** - * @covers ArticleSearchIndex - */ public function testIndexSubmissionFiles() { // Make sure that no hook is being called. @@ -247,9 +226,6 @@ public function testIndexSubmissionFiles() $this->assertTrue(true); } - /** - * @covers ArticleSearchIndex - */ public function testIndexSubmissionFilesViaPluginHook() { // Diverting to the search plugin hook. @@ -388,12 +364,12 @@ private function registerMockArticleSearchDAO($clearIndexExpected, $deleteArticl // Test the clearIndex() method. $articleSearchDao->expects($clearIndexExpected) ->method('clearIndex') - ->will($this->returnValue(null)); + ->willReturn(null); // Test the deleteSubmissionKeywords() method. $articleSearchDao->expects($deleteArticleExpected) ->method('deleteSubmissionKeywords') - ->will($this->returnValue(null)); + ->willReturn(null); // Register the mock DAO. DAORegistry::registerDAO('ArticleSearchDAO', $articleSearchDao); @@ -417,12 +393,12 @@ private function registerMockJournalDAO() ->getMock(); $journalsIterator ->method('toIterator') - ->will($this->returnValue([])); + ->willReturn([]); // Mock the getAll() method. $journalDao->expects($this->any()) ->method('getAll') - ->will($this->returnValue($journalsIterator)); + ->willReturn($journalsIterator); // Register the mock DAO. DAORegistry::registerDAO('JournalDAO', $journalDao); @@ -460,7 +436,7 @@ private function getMockArticleSearchIndex($expectedCall) // Check for _updateTextIndex() calls. $articleSearchIndex->expects($expectedCall) ->method('_updateTextIndex') - ->will($this->returnValue(null)); + ->willReturn(null); return $articleSearchIndex; } } diff --git a/tests/classes/search/ArticleSearchTest.php b/tests/classes/search/ArticleSearchTest.php index 52bcdfe95fe..9dce898c7a9 100644 --- a/tests/classes/search/ArticleSearchTest.php +++ b/tests/classes/search/ArticleSearchTest.php @@ -26,10 +26,12 @@ use APP\search\ArticleSearchDAO; use Mockery; use Mockery\MockInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PKP\db\DAORegistry; use PKP\plugins\Hook; use PKP\tests\PKPTestCase; +#[CoversClass(ArticleSearch::class)] class ArticleSearchTest extends PKPTestCase { private const SUBMISSION_SEARCH_TEST_DEFAULT_ARTICLE = 1; @@ -87,9 +89,7 @@ protected function tearDown(): void // // Unit tests // - /** - * @covers ArticleSearch - */ + public function testRetrieveResults() { // Make sure that no hook is being called. @@ -133,9 +133,6 @@ public function testRetrieveResults() self::assertTrue($searchResult->eof()); } - /** - * @covers ArticleSearch - */ public function testRetrieveResultsViaPluginHook() { // Diverting a search to the search plugin hook. @@ -248,7 +245,7 @@ private function registerMockArticleSearchDAO() // Mock the getPhraseResults() method. $articleSearchDao->expects($this->any()) ->method('getPhraseResults') - ->will($this->returnValue($searchResult)); + ->willReturn($searchResult); // Register the mock DAO. DAORegistry::registerDAO('ArticleSearchDAO', $articleSearchDao); @@ -273,7 +270,7 @@ private function registerMockJournalDAO() // Mock the getById() method. $journalDao->expects($this->any()) ->method('getById') - ->will($this->returnValue($journal)); + ->willReturn($journal); // Register the mock DAO. DAORegistry::registerDAO('JournalDAO', $journalDao);