Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib#10306 unit tests for queue jobs #10340

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

touhidurabir
Copy link
Member

@touhidurabir touhidurabir commented Aug 27, 2024

for #10306

Comment on lines +322 to +325
if (PKPContainer::getInstance()->runningUnitTests()) {
$client = Registry::get(\PKP\tests\PKPTestCase::MOCKED_GUZZLE_CLIENT_NAME);
if ($client) {
return $client;
}
}

Copy link
Member Author

@touhidurabir touhidurabir Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

part of functionality to mocking ability for guzzel request .

@@ -56,7 +56,7 @@ public function updateNotification(PKPRequest $request, ?array $userIds, int $as
*
* @copydoc PKPNotificationOperationManager::createNotification()
*/
public function createNotification(PKPRequest $request, ?int $userId = null, ?int $notificationType = null, ?int $contextId = Application::SITE_CONTEXT_ID, ?int $assocType = null, ?int $assocId = null, int $level = Notification::NOTIFICATION_LEVEL_NORMAL, ?array $params = null): ?Notification
public function createNotification(?PKPRequest $request = null, ?int $userId = null, ?int $notificationType = null, ?int $contextId = Application::SITE_CONTEXT_ID, ?int $assocType = null, ?int $assocId = null, int $level = Notification::NOTIFICATION_LEVEL_NORMAL, ?array $params = null): ?Notification
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have any use of PKPRequest $request here as it seems this data not used ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right -- this parameter can be removed.

@@ -205,8 +220,7 @@ protected function mockRequest($path = 'index/test-page/test-op', $userId = null
$request->setRouter($router);

// Test user.
$session = $request->getSession();
$session->setUserId($userId);
$request->getSessionGuard()->setUserId($userId);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a leftover missing change from #9566

Comment on lines +73 to +75
$bulkEmailSenderJob->handle();

$this->expectNotToPerformAssertions();
Copy link
Member Author

@touhidurabir touhidurabir Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our previous asserting was like $this->assertNull($bulkEmailSenderJob->handle()) . However the handle method return type set as void which does turn in null and older PHPUnit version did not have a arg type defined . But the latest PHPUnit version has arg type define as mixed which in turn identified as error as return type void does not match with arg time mixed . Though this does not cause exception but modern IDEs identify it as error . So probably better to go with approach here and all other places .

@touhidurabir touhidurabir force-pushed the i10306_main branch 2 times, most recently from 6677802 to f3083e3 Compare September 8, 2024 07:21
* Override Laravel method; always false.
* Prevents the undefined method error when the Log Manager tries to determine the driver
*/
public function runningUnitTests(): bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be removed once we add and configure the Laravel logging service provider, correct? I think this is related to what you're talking about with Erik. It might be worth filing in Github, noting this function in the issue, and adding a FIXME here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly , this has there before this PR and probably will stay . Our Container class extends the laravel core container but We have our very own Application class . Once we able to handle the bootstrapping process to Laravel's foundation Application, we can remove this (as it's reside there) . As few core class required this information, so we have copied it from Laravel's foundation application class to our PKPContainer just to facilitate the dependency.


/**
* Mock the mail facade
* @see https://laravel.com/docs/10.x/mocking
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to link to 11, since that's what we're shipping.

/** @var NewAnnouncementNotifyUsers $newAnnouncementNotifyUsersJob */
$newAnnouncementNotifyUsersJob = unserialize($this->serializedJobData);

$announcementMock = Mockery::mock(\PKP\announcement\Announcement::class)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to require some work once #10328 is merged.

Copy link
Member

@asmecher asmecher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few minor suggestions -- thanks, @touhidurabir!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants