mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
More Feed tests; Linux fixes
- Adjusted some namespace case - Included Linux test runner; should also work with macOS - Made the PHP server run in the background on Windows
This commit is contained in:
parent
590abaf0ef
commit
97a8f473a7
7 changed files with 42 additions and 15 deletions
|
@ -298,7 +298,7 @@ class Feed {
|
|||
$offset = "30 minutes";
|
||||
} else if($diff < (3 * 60 * 60)) { // less than three hours
|
||||
$offset = "1 hour";
|
||||
} else if($diff > (36 * 60 * 60)) { // more than 36 hours
|
||||
} else if($diff >= (36 * 60 * 60)) { // more than 36 hours
|
||||
$offset = "1 day";
|
||||
} else {
|
||||
$offset = "3 hours";
|
||||
|
|
|
@ -18,6 +18,18 @@ class TestFeed extends \PHPUnit\Framework\TestCase {
|
|||
Data::$conf = new Conf();
|
||||
}
|
||||
|
||||
function testComputeNextFetchOnError() {
|
||||
for($a = 0; $a < 100; $a++) {
|
||||
if($a < 3) {
|
||||
$this->assertTime("now + 5 minutes", Feed::nextFetchOnError($a));
|
||||
} else if($a < 15) {
|
||||
$this->assertTime("now + 3 hours", Feed::nextFetchOnError($a));
|
||||
} else {
|
||||
$this->assertTime("now + 1 day", Feed::nextFetchOnError($a));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function testComputeNextFetchFrom304() {
|
||||
// if less than half an hour, check in 15 minutes
|
||||
$exp = strtotime("now + 15 minutes");
|
||||
|
@ -53,7 +65,7 @@ class TestFeed extends \PHPUnit\Framework\TestCase {
|
|||
$this->assertTime($exp, $f->nextFetch);
|
||||
// otherwise check in three hours
|
||||
$exp = strtotime("now + 3 hours");
|
||||
$t = strtotime("now - 6 hours");
|
||||
$t = strtotime("now - 3 hours");
|
||||
$f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
|
||||
$this->assertTime($exp, $f->nextFetch);
|
||||
$t = strtotime("now - 35 hours");
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace JKingWeb\Arsse;
|
||||
use JKingWeb\Arsse\Rest\Request;
|
||||
use JKingWeb\Arsse\Rest\Response;
|
||||
use JKingWeb\Arsse\REST\Request;
|
||||
use JKingWeb\Arsse\REST\Response;
|
||||
use JKingWeb\Arsse\Test\Result;
|
||||
use Phake;
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace JKingWeb\Arsse;
|
||||
use JKingWeb\Arsse\Rest\Request;
|
||||
use JKingWeb\Arsse\Rest\Response;
|
||||
use JKingWeb\Arsse\REST\Request;
|
||||
use JKingWeb\Arsse\REST\Response;
|
||||
|
||||
|
||||
class TestNCNVersionDiscovery extends \PHPUnit\Framework\TestCase {
|
||||
|
@ -14,7 +14,7 @@ class TestNCNVersionDiscovery extends \PHPUnit\Framework\TestCase {
|
|||
|
||||
function testFetchVersionList() {
|
||||
$exp = new Response(200, ['apiLevels' => ['v1-2']]);
|
||||
$h = new Rest\NextCloudNews\Versions();
|
||||
$h = new REST\NextCloudNews\Versions();
|
||||
$req = new Request("GET", "/");
|
||||
$res = $h->dispatch($req);
|
||||
$this->assertEquals($exp, $res);
|
||||
|
@ -28,7 +28,7 @@ class TestNCNVersionDiscovery extends \PHPUnit\Framework\TestCase {
|
|||
|
||||
function testUseIncorrectMethod() {
|
||||
$exp = new Response(405);
|
||||
$h = new Rest\NextCloudNews\Versions();
|
||||
$h = new REST\NextCloudNews\Versions();
|
||||
$req = new Request("POST", "/");
|
||||
$res = $h->dispatch($req);
|
||||
$this->assertEquals($exp, $res);
|
||||
|
@ -36,7 +36,7 @@ class TestNCNVersionDiscovery extends \PHPUnit\Framework\TestCase {
|
|||
|
||||
function testUseIncorrectPath() {
|
||||
$exp = new Response(501);
|
||||
$h = new Rest\NextCloudNews\Versions();
|
||||
$h = new REST\NextCloudNews\Versions();
|
||||
$req = new Request("GET", "/ook");
|
||||
$res = $h->dispatch($req);
|
||||
$this->assertEquals($exp, $res);
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
<?php return [
|
||||
'code' => 304,
|
||||
'lastMod' => (int) $_GET['t'],
|
||||
];
|
||||
<?php
|
||||
if(array_key_exists("t", $_GET)) {
|
||||
return [
|
||||
'code' => 304,
|
||||
'lastMod' => (int) $_GET['t'],
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'code' => 304,
|
||||
'cache' => fasel,
|
||||
];
|
||||
}
|
7
tests/test
Normal file
7
tests/test
Normal file
|
@ -0,0 +1,7 @@
|
|||
#! /bin/sh
|
||||
base=`dirname "$0"`
|
||||
php -S localhost:8000 "$base/server.php" >/dev/null &
|
||||
php "$base/../vendor/phpunit/phpunit/phpunit" -c "$base/phpunit.xml"
|
||||
sleep 1s
|
||||
pid=`netstat -tlpn 2>/dev/null | grep ":8000 " | grep -Eo "[0-9]+/php" | grep -Eo "[0-9]+"`
|
||||
kill $pid
|
|
@ -1,10 +1,10 @@
|
|||
@echo off
|
||||
setlocal
|
||||
set base=%~dp0
|
||||
start php -S localhost:8000 "%base%\server.php"
|
||||
start /b php -S localhost:8000 "%base%\server.php" >nul
|
||||
php "%base%\..\vendor\phpunit\phpunit\phpunit" -c "%base%\phpunit.xml"
|
||||
timeout /nobreak /t 1 >nul
|
||||
for /f "usebackq tokens=5" %%a in (`netstat -aon ^| find "LISTENING" ^| find ":8000"`) do (
|
||||
taskkill /pid %%a >nul
|
||||
taskkill /f /pid %%a >nul
|
||||
goto :eof
|
||||
)
|
Loading…
Reference in a new issue