From 728eecfbb5696a94c4b463e71a331299c9add175 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Sat, 19 Oct 2019 12:14:13 -0400 Subject: [PATCH] Additional service tests --- lib/Conf.php | 3 +++ lib/REST/Fever/API.php | 2 +- lib/Service.php | 2 ++ tests/cases/Service/TestService.php | 20 ++++++++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/Conf.php b/lib/Conf.php index 15a8345d..13635c89 100644 --- a/lib/Conf.php +++ b/lib/Conf.php @@ -264,6 +264,7 @@ class Conf { $type |= Value::M_NULL; } } else { + // catch-all for custom properties $type = Value::T_MIXED; // @codeCoverageIgnore } $out[$p->name] = ['name' => $match[0], 'const' => $type]; @@ -286,6 +287,7 @@ class Conf { } switch (self::EXPECTED_TYPES[$key] ?? gettype($this->$key)) { case "integer": + // no properties are currently typed as integers return Value::normalize($value, Value::T_INT | $mode); // @codeCoverageIgnore case "double": return Value::normalize($value, Value::T_FLOAT | $mode); @@ -293,6 +295,7 @@ class Conf { case "object": return $value; default: + // this should never occur throw new Conf\Exception("ambiguousDefault", ['param' => $key]); // @codeCoverageIgnore } } diff --git a/lib/REST/Fever/API.php b/lib/REST/Fever/API.php index ac85aa84..16bd8897 100644 --- a/lib/REST/Fever/API.php +++ b/lib/REST/Fever/API.php @@ -207,7 +207,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler { // indexed arrays $p->appendChild($this->makeXMLIndexed($v, $d->createElement($k), substr($k, 0, strlen($k) - 1))); } else { - // this case does not actually occur in a proper Fever response + // this case is never encountered with Fever's output $p->appendChild($this->makeXMLAssoc($v, $d->createElement($k))); // @codeCoverageIgnore } } diff --git a/lib/Service.php b/lib/Service.php index aed35c77..bd02fc90 100644 --- a/lib/Service.php +++ b/lib/Service.php @@ -40,11 +40,13 @@ class Service { } static::cleanupPost(); $t->add($this->interval); + // @codeCoverageIgnoreStart if ($loop) { do { @time_sleep_until($t->getTimestamp()); } while ($t->getTimestamp() > time()); } + // @codeCoverageIgnoreEnd } while ($loop); return $t; } diff --git a/tests/cases/Service/TestService.php b/tests/cases/Service/TestService.php index 3f6ea6b3..a1db8626 100644 --- a/tests/cases/Service/TestService.php +++ b/tests/cases/Service/TestService.php @@ -39,4 +39,24 @@ class TestService extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertTrue(Service::hasCheckedIn()); $this->assertFalse(Service::hasCheckedIn()); } + + 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(); + } }