Skip to content

Commit

Permalink
pkp/pkp-lib#9892 PHPUnit 11 doc block to attributes convert to update…
Browse files Browse the repository at this point in the history
… deprecations
  • Loading branch information
touhidurabir authored and asmecher committed Aug 12, 2024
1 parent e483ae3 commit 5d6786e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 61 deletions.
39 changes: 19 additions & 20 deletions plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
/**
Expand All @@ -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()
{
//
Expand Down Expand Up @@ -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)
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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);
Expand All @@ -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)));
Expand All @@ -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);

//
Expand All @@ -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 */
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);


Expand Down
42 changes: 9 additions & 33 deletions tests/classes/search/ArticleSearchIndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +35,7 @@
use PKP\submissionFile\SubmissionFile;
use PKP\tests\PKPTestCase;

#[CoversClass(ArticleSearchIndex::class)]
class ArticleSearchIndexTest extends PKPTestCase
{
//
Expand Down Expand Up @@ -77,9 +79,7 @@ protected function tearDown(): void
//
// Unit tests
//
/**
* @covers ArticleSearchIndex
*/

public function testUpdateFileIndexViaPluginHook()
{
// Diverting to the search plugin hook.
Expand All @@ -100,9 +100,6 @@ public function testUpdateFileIndexViaPluginHook()
Hook::clear('ArticleSearchIndex::submissionFileChanged');
}

/**
* @covers ArticleSearchIndex
*/
public function testDeleteTextIndex()
{
// Prepare the mock environment for this test.
Expand All @@ -116,9 +113,6 @@ public function testDeleteTextIndex()
$articleSearchIndex->submissionFileDeleted(0);
}

/**
* @covers ArticleSearchIndex
*/
public function testDeleteTextIndexViaPluginHook()
{
// Diverting to the search plugin hook.
Expand All @@ -140,9 +134,6 @@ public function testDeleteTextIndexViaPluginHook()
Hook::clear('ArticleSearchIndex::submissionFileDeleted');
}

/**
* @covers ArticleSearchIndex
*/
public function testRebuildIndex()
{
// Prepare the mock environment for this test.
Expand All @@ -160,9 +151,6 @@ public function testRebuildIndex()
$articleSearchIndex->rebuildIndex(true);
}

/**
* @covers ArticleSearchIndex
*/
public function testRebuildIndexViaPluginHook()
{
// Diverting to the search plugin hook.
Expand All @@ -180,9 +168,6 @@ public function testRebuildIndexViaPluginHook()
Hook::clear('ArticleSearchIndex::rebuildIndex');
}

/**
* @covers ArticleSearchIndex
*/
public function testIndexArticleMetadata()
{
// Make sure that no hook is being called.
Expand All @@ -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.
Expand All @@ -231,9 +213,6 @@ public function testIndexArticleMetadataViaPluginHook()
Hook::clear('ArticleSearchIndex::articleMetadataChanged');
}

/**
* @covers ArticleSearchIndex
*/
public function testIndexSubmissionFiles()
{
// Make sure that no hook is being called.
Expand All @@ -247,9 +226,6 @@ public function testIndexSubmissionFiles()
$this->assertTrue(true);
}

/**
* @covers ArticleSearchIndex
*/
public function testIndexSubmissionFilesViaPluginHook()
{
// Diverting to the search plugin hook.
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
}
13 changes: 5 additions & 8 deletions tests/classes/search/ArticleSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,9 +89,7 @@ protected function tearDown(): void
//
// Unit tests
//
/**
* @covers ArticleSearch
*/

public function testRetrieveResults()
{
// Make sure that no hook is being called.
Expand Down Expand Up @@ -133,9 +133,6 @@ public function testRetrieveResults()
self::assertTrue($searchResult->eof());
}

/**
* @covers ArticleSearch
*/
public function testRetrieveResultsViaPluginHook()
{
// Diverting a search to the search plugin hook.
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 5d6786e

Please sign in to comment.