diff --git a/tests/Feed/TestFeed.php b/tests/Feed/TestFeed.php index 0ae58d5..5e4d1f6 100644 --- a/tests/Feed/TestFeed.php +++ b/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); } } \ No newline at end of file diff --git a/tests/docroot/Feed/NextFetch/NotModified.php b/tests/docroot/Feed/NextFetch/NotModified.php index 6a33b46..71dcb84 100644 --- a/tests/docroot/Feed/NextFetch/NotModified.php +++ b/tests/docroot/Feed/NextFetch/NotModified.php @@ -7,6 +7,6 @@ if(array_key_exists("t", $_GET)) { } else { return [ 'code' => 304, - 'cache' => fasel, + 'cache' => false, ]; } \ No newline at end of file diff --git a/tests/docroot/IsUp.php b/tests/docroot/IsUp.php new file mode 100644 index 0000000..83fbe21 --- /dev/null +++ b/tests/docroot/IsUp.php @@ -0,0 +1,4 @@ + 200, + 'content' => "I'm up!", +]; \ No newline at end of file