1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 13:12:41 +00:00

Tweaks to Feed tests

- Ensure Web server is up before running tests (skip otherwise)
- Place expected timestamps closer to assertions, to lessen chances of off-by-one failures
This commit is contained in:
J. King 2017-05-21 23:26:36 -04:00
parent 757f2af343
commit f04ba956a9
3 changed files with 27 additions and 8 deletions

View file

@ -7,13 +7,23 @@ Use Phake;
class TestFeed extends \PHPUnit\Framework\TestCase {
use Test\Tools;
protected $base = "http://localhost:8000/Feed/";
protected static $host = "http://localhost:8000/";
protected static $serverUp = true;
protected $base = "";
function time(string $t): string {
return gmdate("D, d M Y H:i:s \G\M\T", strtotime($t));
}
static function setUpBeforeClass() {
if(!@file_get_contents(self::$host."IsUp")) self::$serverUp = false;
}
function setUp() {
if(!self::$serverUp) {
$this->markTestSkipped("Test Web server is not accepting requests");
}
$this->base = self::$host."Feed/";
$this->clearData();
Data::$conf = new Conf();
}
@ -32,44 +42,49 @@ class TestFeed extends \PHPUnit\Framework\TestCase {
function testComputeNextFetchFrom304() {
// if less than half an hour, check in 15 minutes
$exp = strtotime("now + 15 minutes");
$t = strtotime("now");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 15 minutes");
$this->assertTime($exp, $f->nextFetch);
$t = strtotime("now - 29 minutes");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 15 minutes");
$this->assertTime($exp, $f->nextFetch);
// if less than an hour, check in 30 minutes
$exp = strtotime("now + 30 minutes");
$t = strtotime("now - 30 minutes");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 30 minutes");
$this->assertTime($exp, $f->nextFetch);
$t = strtotime("now - 59 minutes");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 30 minutes");
$this->assertTime($exp, $f->nextFetch);
// if less than three hours, check in an hour
$exp = strtotime("now + 1 hour");
$t = strtotime("now - 1 hour");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 1 hour");
$this->assertTime($exp, $f->nextFetch);
$t = strtotime("now - 2 hours 59 minutes");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 1 hour");
$this->assertTime($exp, $f->nextFetch);
// if more than 36 hours, check in 24 hours
$exp = strtotime("now + 1 day");
$t = strtotime("now - 36 hours");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 1 day");
$this->assertTime($exp, $f->nextFetch);
$t = strtotime("now - 2 years");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 1 day");
$this->assertTime($exp, $f->nextFetch);
// otherwise check in three hours
$exp = strtotime("now + 3 hours");
$t = strtotime("now - 3 hours");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 3 hours");
$this->assertTime($exp, $f->nextFetch);
$t = strtotime("now - 35 hours");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 3 hours");
$this->assertTime($exp, $f->nextFetch);
}
}

View file

@ -7,6 +7,6 @@ if(array_key_exists("t", $_GET)) {
} else {
return [
'code' => 304,
'cache' => fasel,
'cache' => false,
];
}

4
tests/docroot/IsUp.php Normal file
View file

@ -0,0 +1,4 @@
<?php return [
'code' => 200,
'content' => "I'm up!",
];