1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +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 { class TestFeed extends \PHPUnit\Framework\TestCase {
use Test\Tools; 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 { function time(string $t): string {
return gmdate("D, d M Y H:i:s \G\M\T", strtotime($t)); 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() { function setUp() {
if(!self::$serverUp) {
$this->markTestSkipped("Test Web server is not accepting requests");
}
$this->base = self::$host."Feed/";
$this->clearData(); $this->clearData();
Data::$conf = new Conf(); Data::$conf = new Conf();
} }
@ -32,44 +42,49 @@ class TestFeed extends \PHPUnit\Framework\TestCase {
function testComputeNextFetchFrom304() { function testComputeNextFetchFrom304() {
// if less than half an hour, check in 15 minutes // if less than half an hour, check in 15 minutes
$exp = strtotime("now + 15 minutes");
$t = strtotime("now"); $t = strtotime("now");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 15 minutes");
$this->assertTime($exp, $f->nextFetch); $this->assertTime($exp, $f->nextFetch);
$t = strtotime("now - 29 minutes"); $t = strtotime("now - 29 minutes");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 15 minutes");
$this->assertTime($exp, $f->nextFetch); $this->assertTime($exp, $f->nextFetch);
// if less than an hour, check in 30 minutes // if less than an hour, check in 30 minutes
$exp = strtotime("now + 30 minutes");
$t = strtotime("now - 30 minutes"); $t = strtotime("now - 30 minutes");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 30 minutes");
$this->assertTime($exp, $f->nextFetch); $this->assertTime($exp, $f->nextFetch);
$t = strtotime("now - 59 minutes"); $t = strtotime("now - 59 minutes");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 30 minutes");
$this->assertTime($exp, $f->nextFetch); $this->assertTime($exp, $f->nextFetch);
// if less than three hours, check in an hour // if less than three hours, check in an hour
$exp = strtotime("now + 1 hour");
$t = strtotime("now - 1 hour"); $t = strtotime("now - 1 hour");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 1 hour");
$this->assertTime($exp, $f->nextFetch); $this->assertTime($exp, $f->nextFetch);
$t = strtotime("now - 2 hours 59 minutes"); $t = strtotime("now - 2 hours 59 minutes");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 1 hour");
$this->assertTime($exp, $f->nextFetch); $this->assertTime($exp, $f->nextFetch);
// if more than 36 hours, check in 24 hours // if more than 36 hours, check in 24 hours
$exp = strtotime("now + 1 day");
$t = strtotime("now - 36 hours"); $t = strtotime("now - 36 hours");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 1 day");
$this->assertTime($exp, $f->nextFetch); $this->assertTime($exp, $f->nextFetch);
$t = strtotime("now - 2 years"); $t = strtotime("now - 2 years");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 1 day");
$this->assertTime($exp, $f->nextFetch); $this->assertTime($exp, $f->nextFetch);
// otherwise check in three hours // otherwise check in three hours
$exp = strtotime("now + 3 hours");
$t = strtotime("now - 3 hours"); $t = strtotime("now - 3 hours");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 3 hours");
$this->assertTime($exp, $f->nextFetch); $this->assertTime($exp, $f->nextFetch);
$t = strtotime("now - 35 hours"); $t = strtotime("now - 35 hours");
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$exp = strtotime("now + 3 hours");
$this->assertTime($exp, $f->nextFetch); $this->assertTime($exp, $f->nextFetch);
} }
} }

View file

@ -7,6 +7,6 @@ if(array_key_exists("t", $_GET)) {
} else { } else {
return [ return [
'code' => 304, '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!",
];