Skip to content

Commit

Permalink
#5885 added mocked context service and context class for job testing
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed May 2, 2024
1 parent 92feacb commit 915154c
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions tests/jobs/email/ReviewReminderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace PKP\tests\classes\core;

use Mockery;
use APP\core\Services;
use PKP\tests\PKPTestCase;
use PKP\jobs\email\ReviewReminder;
use Illuminate\Support\Facades\Mail;
Expand Down Expand Up @@ -88,14 +87,39 @@ public function testJobWillRunWithIfNoReviewerExists(): void
*/
public function testRunSerializedJob(): void
{
Mail::fake();

$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
$contextService = Services::get("context");
$context = $contextService->get($reviewReminderJob->contextId);
$this->mockRequest($context->getPath() . '/test-page/test-op');
$this->mockRequest();

// Need to replace the container binding of `context` with a mock object
\APP\core\Services::register(
new class extends \APP\services\OJSServiceProvider
{
public function register(\Pimple\Container $pimple)
{
$pimple['context'] = Mockery::mock(\APP\services\ContextService::class)
->makePartial()
->shouldReceive('get')
->withAnyArgs()
->andReturn(
// Mock the context(Journal/Press/Server) object
Mockery::mock(\APP\journal\Journal::class)
->makePartial()
->shouldReceive([
'getPath' => '',
'getId' => 0,
])
->withAnyArgs()
->getMock()
)
->getMock();
}
}
);

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

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

0 comments on commit 915154c

Please sign in to comment.