Browse Source

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
microsub
J. King 7 years ago
parent
commit
f04ba956a9
  1. 29
      tests/Feed/TestFeed.php
  2. 2
      tests/docroot/Feed/NextFetch/NotModified.php
  3. 4
      tests/docroot/IsUp.php

29
tests/Feed/TestFeed.php

@ -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);
}
}

2
tests/docroot/Feed/NextFetch/NotModified.php

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

4
tests/docroot/IsUp.php

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