Skip to content

Commit

Permalink
#5885 job test update
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Jun 13, 2024
1 parent 757b701 commit f21fab9
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions tests/jobs/email/ReviewReminderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @brief Tests for review response and submit due reminder job.
*/

namespace PKP\tests\classes\core;
namespace PKP\tests\jobs\email;

use Mockery;
use PKP\tests\PKPTestCase;
Expand All @@ -22,6 +22,7 @@
use PKP\invitation\repositories\Invitation as InvitationRepository;
use PKP\submission\reviewAssignment\Repository as ReviewAssignmentRepository;
use PKP\log\event\Repository as EventRepository;
use APP\user\Repository as UserRepository;

/**
* @runTestsInSeparateProcesses
Expand All @@ -37,18 +38,25 @@ class ReviewReminderTest extends PKPTestCase
/**
* Test job is a proper instance
*/
public function testUnserializationGetProperReviewReminderJobInstance(): void
public function testUnserializationGetProperJobInstance(): void
{
$this->assertInstanceOf(ReviewReminder::class, unserialize($this->serializedJobData));
}

/**
* Test job will not fail when no reviewer associated with review assignment
* Ensure that a serialized job can be unserialized and executed
*/
public function testJobWillRunWithIfNoReviewerExists(): void
public function testRunSerializedJob(): void
{
/** @var ReviewReminder $reviewReminderJob */
$reviewReminderJob = unserialize($this->serializedJobData);

// Fake the mail facade
Mail::fake();

// need to mock request so that a valid context information is set and can be retrived
$this->mockRequest();

$reviewAssignmentMock = Mockery::mock(ReviewAssignment::class)
->shouldReceive([
'getReviewerId' => 0,
Expand All @@ -66,8 +74,6 @@ public function testJobWillRunWithIfNoReviewerExists(): void
->withAnyArgs()
->getMock();

app()->instance(ReviewAssignment::class, $reviewAssignmentMock);

$reviewAssignmentRepoMock = Mockery::mock(app(ReviewAssignmentRepository::class))
->makePartial()
->shouldReceive([
Expand All @@ -78,24 +84,28 @@ public function testJobWillRunWithIfNoReviewerExists(): void
->getMock();

app()->instance(ReviewAssignmentRepository::class, $reviewAssignmentRepoMock);

$this->assertNull($reviewReminderJob->handle());
}

/**
* Test job will not fail
*/
public function testRunSerializedJob(): void
{
// Fake the mail facade
Mail::fake();

// need to mock request so that a valid context information is set and can be retrived
$this->mockRequest();
$userMock = Mockery::mock(\PKP\user\User::class)
->makePartial()
->shouldReceive([
'getId' => 0,
'getFullName' => 'Test User',
])
->withAnyArgs()
->getMock();

$userRepoMock = Mockery::mock(app(UserRepository::class))
->makePartial()
->shouldReceive('get')
->withAnyArgs()
->andReturn($userMock)
->getMock();

app()->instance(UserRepository::class, $userRepoMock);

// Need to replace the container binding of `context` with a mock object
\APP\core\Services::register(
new class extends \APP\services\OJSServiceProvider
new class implements \Pimple\ServiceProviderInterface
{
public function register(\Pimple\Container $pimple)
{
Expand All @@ -119,8 +129,6 @@ public function register(\Pimple\Container $pimple)
}
);

$reviewReminderJob = unserialize($this->serializedJobData);

$publicationMock = Mockery::mock(\APP\publication\Publication::class)
->makePartial()
->shouldReceive('getData')
Expand Down

0 comments on commit f21fab9

Please sign in to comment.