|
|
@@ -1,4 +1,5 @@
|
|
|
<?php
|
|
|
+
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
namespace App\Tests\Unit\Service\Cron\Job;
|
|
|
@@ -12,25 +13,29 @@ use PHPUnit\Framework\MockObject\MockObject;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
|
|
-class TestableCleanDb extends CleanDb {
|
|
|
- public function purgeDb(bool $commit = true): void {
|
|
|
+class TestableCleanDb extends CleanDb
|
|
|
+{
|
|
|
+ public function purgeDb(bool $commit = true): void
|
|
|
+ {
|
|
|
parent::purgeDb($commit);
|
|
|
}
|
|
|
|
|
|
- public function purgeAuditTables(\DateTime $maxDate): int {
|
|
|
+ public function purgeAuditTables(\DateTime $maxDate): int
|
|
|
+ {
|
|
|
return parent::purgeAuditTables($maxDate);
|
|
|
}
|
|
|
|
|
|
- public function purgeMessages(\DateTime $maxDate): int {
|
|
|
+ public function purgeMessages(\DateTime $maxDate): int
|
|
|
+ {
|
|
|
return parent::purgeMessages($maxDate);
|
|
|
}
|
|
|
|
|
|
- public function purgeNotifications(\DateTime $maxDate): int {
|
|
|
+ public function purgeNotifications(\DateTime $maxDate): int
|
|
|
+ {
|
|
|
return parent::purgeNotifications($maxDate);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
class CleanDbTest extends TestCase
|
|
|
{
|
|
|
private CronUIInterface|MockObject $ui;
|
|
|
@@ -45,7 +50,8 @@ class CleanDbTest extends TestCase
|
|
|
$this->connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
|
|
|
}
|
|
|
|
|
|
- private function getMockFor(string $method): MockObject | TestableCleanDb {
|
|
|
+ private function getMockFor(string $method): MockObject|TestableCleanDb
|
|
|
+ {
|
|
|
$cleanDb = $this->getMockBuilder(TestableCleanDb::class)
|
|
|
->setConstructorArgs([$this->connection])
|
|
|
->setMethodsExcept([$method, 'setUI', 'setLoggerInterface'])
|
|
|
@@ -74,7 +80,8 @@ class CleanDbTest extends TestCase
|
|
|
$cleanDb->execute();
|
|
|
}
|
|
|
|
|
|
- public function testPurgeDb(): void {
|
|
|
+ public function testPurgeDb(): void
|
|
|
+ {
|
|
|
DatesUtils::setFakeDatetime('2022-01-08 00:00:00');
|
|
|
|
|
|
$maxDate = DatesUtils::new();
|
|
|
@@ -85,7 +92,6 @@ class CleanDbTest extends TestCase
|
|
|
|
|
|
$cleanDb = $this->getMockFor('purgeDb');
|
|
|
|
|
|
-
|
|
|
$this->connection->expects($this->once())->method('beginTransaction');
|
|
|
$this->connection->expects($this->once())->method('setAutoCommit')->with(false);
|
|
|
$this->connection->expects($this->once())->method('commit');
|
|
|
@@ -100,7 +106,8 @@ class CleanDbTest extends TestCase
|
|
|
$cleanDb->purgeDb();
|
|
|
}
|
|
|
|
|
|
- public function testPurgeDbNoCommit(): void {
|
|
|
+ public function testPurgeDbNoCommit(): void
|
|
|
+ {
|
|
|
DatesUtils::setFakeDatetime('2022-01-08 00:00:00');
|
|
|
|
|
|
$maxDate = DatesUtils::new();
|
|
|
@@ -125,7 +132,8 @@ class CleanDbTest extends TestCase
|
|
|
$cleanDb->purgeDb(false);
|
|
|
}
|
|
|
|
|
|
- public function testPurgeDbWithError(): void {
|
|
|
+ public function testPurgeDbWithError(): void
|
|
|
+ {
|
|
|
DatesUtils::setFakeDatetime('2022-01-08 00:00:00');
|
|
|
|
|
|
$maxDate = DatesUtils::new();
|
|
|
@@ -148,7 +156,8 @@ class CleanDbTest extends TestCase
|
|
|
$cleanDb->purgeDb(false);
|
|
|
}
|
|
|
|
|
|
- public function testPurgeAuditTables(): void {
|
|
|
+ public function testPurgeAuditTables(): void
|
|
|
+ {
|
|
|
$maxDateAudit = DatesUtils::new('2022-06-30 00:00:00');
|
|
|
$maxDateAudit->sub(new \DateInterval('P180D'));
|
|
|
|
|
|
@@ -172,19 +181,19 @@ class CleanDbTest extends TestCase
|
|
|
->method('prepare')
|
|
|
->willReturnMap([
|
|
|
[
|
|
|
- "DELETE a, r
|
|
|
+ 'DELETE a, r
|
|
|
FROM opentalent.Audit_table1 a
|
|
|
INNER JOIN opentalent.revisions r ON r.id = a.rev
|
|
|
- WHERE r.timestamp < :maxDate;",
|
|
|
- $stmt1
|
|
|
+ WHERE r.timestamp < :maxDate;',
|
|
|
+ $stmt1,
|
|
|
],
|
|
|
[
|
|
|
- "DELETE a, r
|
|
|
+ 'DELETE a, r
|
|
|
FROM opentalent.Audit_table2 a
|
|
|
INNER JOIN opentalent.revisions r ON r.id = a.rev
|
|
|
- WHERE r.timestamp < :maxDate;",
|
|
|
- $stmt2
|
|
|
- ]
|
|
|
+ WHERE r.timestamp < :maxDate;',
|
|
|
+ $stmt2,
|
|
|
+ ],
|
|
|
]);
|
|
|
|
|
|
$stmt1
|
|
|
@@ -202,7 +211,8 @@ class CleanDbTest extends TestCase
|
|
|
$this->assertEquals(200, $cleanDb->purgeAuditTables($maxDateAudit));
|
|
|
}
|
|
|
|
|
|
- public function testPurgeMessages(): void {
|
|
|
+ public function testPurgeMessages(): void
|
|
|
+ {
|
|
|
$maxDate = DatesUtils::new('2022-03-02');
|
|
|
$maxDate->sub(new \DateInterval('P60D'));
|
|
|
|
|
|
@@ -216,18 +226,18 @@ class CleanDbTest extends TestCase
|
|
|
->method('prepare')
|
|
|
->willReturnMap([
|
|
|
[
|
|
|
- "DELETE r
|
|
|
+ 'DELETE r
|
|
|
FROM opentalent.Message m
|
|
|
inner join opentalent.ReportMessage r on r.message_id = m.id
|
|
|
- where (m.dateSent < :maxDate or (m.dateSent is null and m.createDate < :maxDate)) and m.isSystem = true and m.id > 0;",
|
|
|
- $stmt1
|
|
|
+ where (m.dateSent < :maxDate or (m.dateSent is null and m.createDate < :maxDate)) and m.isSystem = true and m.id > 0;',
|
|
|
+ $stmt1,
|
|
|
],
|
|
|
[
|
|
|
- "DELETE
|
|
|
+ 'DELETE
|
|
|
FROM opentalent.Message
|
|
|
- where (dateSent < :maxDate or (dateSent is null and createDate < :maxDate)) and isSystem = true and id > 0;",
|
|
|
- $stmt2
|
|
|
- ]
|
|
|
+ where (dateSent < :maxDate or (dateSent is null and createDate < :maxDate)) and isSystem = true and id > 0;',
|
|
|
+ $stmt2,
|
|
|
+ ],
|
|
|
]);
|
|
|
|
|
|
$stmt1
|
|
|
@@ -245,7 +255,8 @@ class CleanDbTest extends TestCase
|
|
|
$this->assertEquals(200, $cleanDb->purgeMessages($maxDate));
|
|
|
}
|
|
|
|
|
|
- public function testPurgeNotifications(): void {
|
|
|
+ public function testPurgeNotifications(): void
|
|
|
+ {
|
|
|
$maxDate = DatesUtils::new('2022-03-02');
|
|
|
$maxDate->sub(new \DateInterval('P60D'));
|
|
|
|
|
|
@@ -263,14 +274,14 @@ class CleanDbTest extends TestCase
|
|
|
FROM opentalent.Information i
|
|
|
inner join opentalent.NotificationUser u on u.notification_id = i.id
|
|
|
where i.createDate < :maxDate and i.discr = 'notification';",
|
|
|
- $stmt1
|
|
|
+ $stmt1,
|
|
|
],
|
|
|
[
|
|
|
"DELETE
|
|
|
FROM opentalent.Information
|
|
|
where createDate < :maxDate and discr = 'notification';",
|
|
|
- $stmt2
|
|
|
- ]
|
|
|
+ $stmt2,
|
|
|
+ ],
|
|
|
]);
|
|
|
|
|
|
$stmt1
|