forked from pkp/ops
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkp/pkp-lib#9899 Added unit tests for queue jobs
- Loading branch information
1 parent
cd2baad
commit b227e8f
Showing
8 changed files
with
612 additions
and
1 deletion.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
tests/jobs/statistics/CompileCounterSubmissionDailyMetricsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
/** | ||
* @file tests/jobs/statistics/CompileCounterSubmissionDailyMetricsTest.php | ||
* | ||
* Copyright (c) 2024 Simon Fraser University | ||
* Copyright (c) 2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @brief Tests for compile counter submission daily metrics job. | ||
*/ | ||
|
||
namespace APP\tests\jobs\statistics; | ||
|
||
use APP\jobs\statistics\CompileCounterSubmissionDailyMetrics; | ||
use Mockery; | ||
use PKP\db\DAORegistry; | ||
use PKP\tests\PKPTestCase; | ||
|
||
/** | ||
* @runTestsInSeparateProcesses | ||
* | ||
* @see https://docs.phpunit.de/en/9.6/annotations.html#runtestsinseparateprocesses | ||
*/ | ||
class CompileCounterSubmissionDailyMetricsTest extends PKPTestCase | ||
{ | ||
/** | ||
* base64_encoded serializion from OJS 3.4.0 | ||
*/ | ||
protected string $serializedJobData = <<<END | ||
O:56:"APP\jobs\statistics\CompileCounterSubmissionDailyMetrics":3:{s:9:"\0*\0loadId";s:25:"usage_events_20240130.log";s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";} | ||
END; | ||
|
||
/** | ||
* Test job is a proper instance | ||
*/ | ||
public function testUnserializationGetProperDepositIssueJobInstance(): void | ||
{ | ||
$this->assertInstanceOf( | ||
CompileCounterSubmissionDailyMetrics::class, | ||
unserialize($this->serializedJobData) | ||
); | ||
} | ||
|
||
/** | ||
* Ensure that a serialized job can be unserialized and executed | ||
*/ | ||
public function testRunSerializedJob() | ||
{ | ||
/** @var CompileCounterSubmissionDailyMetrics $compileCounterSubmissionDailyMetricsJob */ | ||
$compileCounterSubmissionDailyMetricsJob = unserialize($this->serializedJobData); | ||
|
||
$temporaryTotalsDAOMock = Mockery::mock(\APP\statistics\TemporaryTotalsDAO::class) | ||
->makePartial() | ||
->shouldReceive([ | ||
'deleteCounterSubmissionDailyByLoadId' => null, | ||
'compileCounterSubmissionDailyMetrics' => null, | ||
]) | ||
->withAnyArgs() | ||
->getMock(); | ||
|
||
DAORegistry::registerDAO('TemporaryTotalsDAO', $temporaryTotalsDAOMock); | ||
|
||
$temporaryItemInvestigationsDAOMock = Mockery::mock(\APP\statistics\TemporaryItemInvestigationsDAO::class) | ||
->makePartial() | ||
->shouldReceive([ | ||
'compileCounterSubmissionDailyMetrics' => null, | ||
]) | ||
->withAnyArgs() | ||
->getMock(); | ||
|
||
DAORegistry::registerDAO('TemporaryItemInvestigationsDAO', $temporaryItemInvestigationsDAOMock); | ||
|
||
$temporaryItemRequestsDAOMock = Mockery::mock(\APP\statistics\TemporaryItemRequestsDAO::class) | ||
->makePartial() | ||
->shouldReceive([ | ||
'compileCounterSubmissionDailyMetrics' => null, | ||
]) | ||
->withAnyArgs() | ||
->getMock(); | ||
|
||
DAORegistry::registerDAO('TemporaryItemRequestsDAO', $temporaryItemRequestsDAOMock); | ||
|
||
|
||
$this->assertNull($compileCounterSubmissionDailyMetricsJob->handle()); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
tests/jobs/statistics/CompileCounterSubmissionInstitutionDailyMetricsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
/** | ||
* @file tests/jobs/statistics/CompileCounterSubmissionInstitutionDailyMetricsTest.php | ||
* | ||
* Copyright (c) 2024 Simon Fraser University | ||
* Copyright (c) 2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @brief Tests for compile counter submission institution daily metrics job. | ||
*/ | ||
|
||
namespace APP\tests\jobs\statistics; | ||
|
||
use APP\jobs\statistics\CompileCounterSubmissionInstitutionDailyMetrics; | ||
use Mockery; | ||
use PKP\db\DAORegistry; | ||
use PKP\tests\PKPTestCase; | ||
|
||
/** | ||
* @runTestsInSeparateProcesses | ||
* | ||
* @see https://docs.phpunit.de/en/9.6/annotations.html#runtestsinseparateprocesses | ||
*/ | ||
class CompileCounterSubmissionInstitutionDailyMetricsTest extends PKPTestCase | ||
{ | ||
/** | ||
* base64_encoded serializion from OJS 3.4.0 | ||
*/ | ||
protected string $serializedJobData = <<<END | ||
O:67:"APP\jobs\statistics\CompileCounterSubmissionInstitutionDailyMetrics":3:{s:9:"\0*\0loadId";s:25:"usage_events_20240130.log";s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";} | ||
END; | ||
|
||
/** | ||
* Test job is a proper instance | ||
*/ | ||
public function testUnserializationGetProperDepositIssueJobInstance(): void | ||
{ | ||
$this->assertInstanceOf( | ||
CompileCounterSubmissionInstitutionDailyMetrics::class, | ||
unserialize($this->serializedJobData) | ||
); | ||
} | ||
|
||
/** | ||
* Ensure that a serialized job can be unserialized and executed | ||
*/ | ||
public function testRunSerializedJob() | ||
{ | ||
/** @var CompileCounterSubmissionInstitutionDailyMetrics $compileCounterSubmissionInstitutionDailyMetricsJob */ | ||
$compileCounterSubmissionInstitutionDailyMetricsJob = unserialize($this->serializedJobData); | ||
|
||
$temporaryTotalsDAOMock = Mockery::mock(\APP\statistics\TemporaryTotalsDAO::class) | ||
->makePartial() | ||
->shouldReceive([ | ||
'deleteCounterSubmissionInstitutionDailyByLoadId' => null, | ||
'compileCounterSubmissionDailyMetrics' => null, | ||
]) | ||
->withAnyArgs() | ||
->getMock(); | ||
|
||
DAORegistry::registerDAO('TemporaryTotalsDAO', $temporaryTotalsDAOMock); | ||
|
||
$temporaryItemInvestigationsDAOMock = Mockery::mock(\APP\statistics\TemporaryItemInvestigationsDAO::class) | ||
->makePartial() | ||
->shouldReceive([ | ||
'compileCounterSubmissionInstitutionDailyMetrics' => null, | ||
]) | ||
->withAnyArgs() | ||
->getMock(); | ||
|
||
DAORegistry::registerDAO('TemporaryItemInvestigationsDAO', $temporaryItemInvestigationsDAOMock); | ||
|
||
$temporaryItemRequestsDAOMock = Mockery::mock(\APP\statistics\TemporaryItemRequestsDAO::class) | ||
->makePartial() | ||
->shouldReceive([ | ||
'compileCounterSubmissionInstitutionDailyMetrics' => null, | ||
]) | ||
->withAnyArgs() | ||
->getMock(); | ||
|
||
DAORegistry::registerDAO('TemporaryItemRequestsDAO', $temporaryItemRequestsDAOMock); | ||
|
||
|
||
$this->assertNull($compileCounterSubmissionInstitutionDailyMetricsJob->handle()); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
tests/jobs/statistics/CompileSubmissionGeoDailyMetricsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
/** | ||
* @file tests/jobs/statistics/CompileSubmissionGeoDailyMetricsTest.php | ||
* | ||
* Copyright (c) 2024 Simon Fraser University | ||
* Copyright (c) 2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @brief Tests for compile submission geo daily metrics job. | ||
*/ | ||
|
||
namespace APP\tests\jobs\statistics; | ||
|
||
use APP\jobs\statistics\CompileSubmissionGeoDailyMetrics; | ||
use Mockery; | ||
use PKP\db\DAORegistry; | ||
use PKP\tests\PKPTestCase; | ||
|
||
/** | ||
* @runTestsInSeparateProcesses | ||
* | ||
* @see https://docs.phpunit.de/en/9.6/annotations.html#runtestsinseparateprocesses | ||
*/ | ||
class CompileSubmissionGeoDailyMetricsTest extends PKPTestCase | ||
{ | ||
/** | ||
* base64_encoded serializion from OJS 3.4.0 | ||
*/ | ||
protected string $serializedJobData = <<<END | ||
O:52:"APP\jobs\statistics\CompileSubmissionGeoDailyMetrics":3:{s:9:"\0*\0loadId";s:25:"usage_events_20240130.log";s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";} | ||
END; | ||
|
||
/** | ||
* Test job is a proper instance | ||
*/ | ||
public function testUnserializationGetProperDepositIssueJobInstance(): void | ||
{ | ||
$this->assertInstanceOf( | ||
CompileSubmissionGeoDailyMetrics::class, | ||
unserialize($this->serializedJobData) | ||
); | ||
} | ||
|
||
/** | ||
* Ensure that a serialized job can be unserialized and executed | ||
*/ | ||
public function testRunSerializedJob() | ||
{ | ||
/** @var CompileSubmissionGeoDailyMetrics $compileSubmissionGeoDailyMetricsJob */ | ||
$compileSubmissionGeoDailyMetricsJob = unserialize($this->serializedJobData); | ||
|
||
$temporaryTotalsDAOMock = Mockery::mock(\APP\statistics\TemporaryTotalsDAO::class) | ||
->makePartial() | ||
->shouldReceive([ | ||
'deleteSubmissionGeoDailyByLoadId' => null, | ||
'compileSubmissionGeoDailyMetrics' => null, | ||
]) | ||
->withAnyArgs() | ||
->getMock(); | ||
|
||
DAORegistry::registerDAO('TemporaryTotalsDAO', $temporaryTotalsDAOMock); | ||
|
||
$temporaryItemInvestigationsDAOMock = Mockery::mock(\APP\statistics\TemporaryItemInvestigationsDAO::class) | ||
->makePartial() | ||
->shouldReceive([ | ||
'compileSubmissionGeoDailyMetrics' => null, | ||
]) | ||
->withAnyArgs() | ||
->getMock(); | ||
|
||
DAORegistry::registerDAO('TemporaryItemInvestigationsDAO', $temporaryItemInvestigationsDAOMock); | ||
|
||
$this->assertNull($compileSubmissionGeoDailyMetricsJob->handle()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
/** | ||
* @file tests/jobs/statistics/CompileUniqueInvestigationsTest.php | ||
* | ||
* Copyright (c) 2024 Simon Fraser University | ||
* Copyright (c) 2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @brief Tests for compile unique investigations job. | ||
*/ | ||
|
||
namespace APP\tests\jobs\statistics; | ||
|
||
use APP\jobs\statistics\CompileUniqueInvestigations; | ||
use Mockery; | ||
use PKP\db\DAORegistry; | ||
use PKP\tests\PKPTestCase; | ||
|
||
/** | ||
* @runTestsInSeparateProcesses | ||
* | ||
* @see https://docs.phpunit.de/en/9.6/annotations.html#runtestsinseparateprocesses | ||
*/ | ||
class CompileUniqueInvestigationsTest extends PKPTestCase | ||
{ | ||
/** | ||
* base64_encoded serializion from OJS 3.4.0 | ||
*/ | ||
protected string $serializedJobData = <<<END | ||
O:47:"APP\jobs\statistics\CompileUniqueInvestigations":3:{s:9:"\0*\0loadId";s:25:"usage_events_20240130.log";s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";} | ||
END; | ||
|
||
/** | ||
* Test job is a proper instance | ||
*/ | ||
public function testUnserializationGetProperDepositIssueJobInstance(): void | ||
{ | ||
$this->assertInstanceOf( | ||
CompileUniqueInvestigations::class, | ||
unserialize($this->serializedJobData) | ||
); | ||
} | ||
|
||
/** | ||
* Ensure that a serialized job can be unserialized and executed | ||
*/ | ||
public function testRunSerializedJob() | ||
{ | ||
/** @var CompileUniqueInvestigations $compileUniqueInvestigationsJob */ | ||
$compileUniqueInvestigationsJob = unserialize($this->serializedJobData); | ||
|
||
$temporaryItemInvestigationsDAOMock = Mockery::mock(\APP\statistics\TemporaryItemInvestigationsDAO::class) | ||
->makePartial() | ||
->shouldReceive([ | ||
'compileUniqueClicks' => null, | ||
]) | ||
->withAnyArgs() | ||
->getMock(); | ||
|
||
DAORegistry::registerDAO('TemporaryItemInvestigationsDAO', $temporaryItemInvestigationsDAOMock); | ||
|
||
$this->assertNull($compileUniqueInvestigationsJob->handle()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
/** | ||
* @file tests/jobs/statistics/CompileUniqueRequestsTest.php | ||
* | ||
* Copyright (c) 2024 Simon Fraser University | ||
* Copyright (c) 2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @brief Tests for compile unique requests job. | ||
*/ | ||
|
||
namespace APP\tests\jobs\statistics; | ||
|
||
use APP\jobs\statistics\CompileUniqueRequests; | ||
use Mockery; | ||
use PKP\db\DAORegistry; | ||
use PKP\tests\PKPTestCase; | ||
|
||
/** | ||
* @runTestsInSeparateProcesses | ||
* | ||
* @see https://docs.phpunit.de/en/9.6/annotations.html#runtestsinseparateprocesses | ||
*/ | ||
class CompileUniqueRequestsTest extends PKPTestCase | ||
{ | ||
/** | ||
* base64_encoded serializion from OJS 3.4.0 | ||
*/ | ||
protected string $serializedJobData = <<<END | ||
O:41:"APP\jobs\statistics\CompileUniqueRequests":3:{s:9:"\0*\0loadId";s:25:"usage_events_20240130.log";s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";} | ||
END; | ||
|
||
/** | ||
* Test job is a proper instance | ||
*/ | ||
public function testUnserializationGetProperDepositIssueJobInstance(): void | ||
{ | ||
$this->assertInstanceOf( | ||
CompileUniqueRequests::class, | ||
unserialize($this->serializedJobData) | ||
); | ||
} | ||
|
||
/** | ||
* Ensure that a serialized job can be unserialized and executed | ||
*/ | ||
public function testRunSerializedJob() | ||
{ | ||
/** @var CompileUniqueRequests $compileUniqueRequestsJob */ | ||
$compileUniqueRequestsJob = unserialize($this->serializedJobData); | ||
|
||
$temporaryItemRequestsDAOMock = Mockery::mock(\APP\statistics\TemporaryItemRequestsDAO::class) | ||
->makePartial() | ||
->shouldReceive([ | ||
'compileUniqueClicks' => null, | ||
]) | ||
->withAnyArgs() | ||
->getMock(); | ||
|
||
DAORegistry::registerDAO('TemporaryItemRequestsDAO', $temporaryItemRequestsDAOMock); | ||
|
||
$this->assertNull($compileUniqueRequestsJob->handle()); | ||
} | ||
} |
Oops, something went wrong.