1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00
Arsse/tests/cases/Service/TestService.php

63 lines
2.2 KiB
PHP
Raw Normal View History

<?php
/** @license MIT
* Copyright 2017 J. King, Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
2017-12-22 03:47:19 +00:00
namespace JKingWeb\Arsse\TestCase\Service;
2017-08-29 14:50:31 +00:00
2017-12-22 03:47:19 +00:00
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\Service;
use JKingWeb\Arsse\Misc\Date;
2017-07-20 22:36:03 +00:00
/** @covers \JKingWeb\Arsse\Service */
2017-12-22 03:47:19 +00:00
class TestService extends \JKingWeb\Arsse\Test\AbstractTest {
protected $srv;
2017-08-29 14:50:31 +00:00
public function setUp() {
2018-11-23 15:01:17 +00:00
self::clearData();
2018-11-23 00:55:54 +00:00
self::setConf();
2019-09-05 14:03:32 +00:00
Arsse::$db = \Phake::mock(Database::class);
$this->srv = new Service();
}
2017-08-29 14:50:31 +00:00
public function testCheckIn() {
$now = time();
$this->srv->checkIn();
2019-09-05 14:03:32 +00:00
\Phake::verify(Arsse::$db)->metaSet("service_last_checkin", \Phake::capture($then), "datetime");
$this->assertTime($now, $then);
}
2017-08-29 14:50:31 +00:00
public function testReportHavingCheckedIn() {
// the mock's metaGet() returns null by default
$this->assertFalse(Service::hasCheckedIn());
$interval = Arsse::$conf->serviceFrequency;
$valid = (new \DateTimeImmutable("now", new \DateTimezone("UTC")))->sub($interval);
$invalid = $valid->sub($interval)->sub($interval);
2019-09-05 14:03:32 +00:00
\Phake::when(Arsse::$db)->metaGet("service_last_checkin")->thenReturn(Date::transform($valid, "sql"))->thenReturn(Date::transform($invalid, "sql"));
$this->assertTrue(Service::hasCheckedIn());
$this->assertFalse(Service::hasCheckedIn());
}
2019-10-19 16:14:13 +00:00
public function testPerformPreCleanup() {
$this->assertTrue(Service::cleanupPre());
\Phake::verify(Arsse::$db)->feedCleanup();
\Phake::verify(Arsse::$db)->sessionCleanup();
}
public function testPerformShortPostCleanup() {
\Phake::when(Arsse::$db)->articleCleanup()->thenReturn(0);
$this->assertTrue(Service::cleanupPost());
\Phake::verify(Arsse::$db)->articleCleanup();
\Phake::verify(Arsse::$db, \Phake::times(0))->driverMaintenance();
}
public function testPerformFullPostCleanup() {
\Phake::when(Arsse::$db)->articleCleanup()->thenReturn(1);
$this->assertTrue(Service::cleanupPost());
\Phake::verify(Arsse::$db)->articleCleanup();
\Phake::verify(Arsse::$db)->driverMaintenance();
}
2017-08-29 14:50:31 +00:00
}