From 64c3ec3571584d9bc17cdd0e2cf219508c475e61 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Thu, 17 Oct 2019 13:00:56 -0400 Subject: [PATCH] Coverage fixes and OPML bugfix --- CHANGELOG | 1 + RoboFile.php | 6 ++++-- lib/CLI.php | 4 ++-- lib/ImportExport/AbstractImportExport.php | 8 ++++---- lib/REST/Fever/API.php | 3 ++- tests/cases/ImportExport/TestImportExport.php | 2 ++ .../Lang/{testComplex.php => TestComplex.php} | 0 tests/lib/Lang/Setup.php | 6 +++++- tests/lib/Lang/TestLang.php | 15 --------------- 9 files changed, 20 insertions(+), 25 deletions(-) rename tests/cases/Lang/{testComplex.php => TestComplex.php} (100%) delete mode 100644 tests/lib/Lang/TestLang.php diff --git a/CHANGELOG b/CHANGELOG index 3e48ece9..54483641 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ Version 0.8.1 (2019-??-??) Bug fixes: - Don't crash updating feeds cached solely via ETag +- Don't fail importing new folders from OPML files - Don't fail adding a feed which collides with another via redirection - Don't fail on very long text-search queries containing question marks when using PostgreSQL or MySQL diff --git a/RoboFile.php b/RoboFile.php index 23cd78a7..f382090e 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -5,6 +5,7 @@ use Robo\Result; const BASE = __DIR__.\DIRECTORY_SEPARATOR; const BASE_TEST = BASE."tests".\DIRECTORY_SEPARATOR; define("IS_WIN", defined("PHP_WINDOWS_VERSION_MAJOR")); +define("IS_MAC", php_uname("s") === "Darwin"); function norm(string $path): string { $out = realpath($path); @@ -92,12 +93,13 @@ class RoboFile extends \Robo\Tasks { $dbg = dirname(\PHP_BINARY)."\\phpdbg.exe"; $dbg = file_exists($dbg) ? $dbg : ""; } else { - $dbg = trim(`which phpdbg`); + $dbg = trim(`which phpdbg 2>/dev/null`); } if ($dbg) { return escapeshellarg($dbg)." -qrr"; } else { - return escapeshellarg(\PHP_BINARY); + $ext = IS_WIN ? "dll" : (IS_MAC ? "dylib" : "so"); + return escapeshellarg(\PHP_BINARY)." -d zend_extension=xdebug.$ext"; } } diff --git a/lib/CLI.php b/lib/CLI.php index bbd99300..702b9f52 100644 --- a/lib/CLI.php +++ b/lib/CLI.php @@ -206,7 +206,7 @@ USAGE_TEXT; $this->logError($e->getMessage()); return $e->getCode(); } - } + } // @codeCoverageIgnore /** @codeCoverageIgnore */ protected function logError(string $msg) { @@ -248,7 +248,7 @@ USAGE_TEXT; case "": return $this->userList(); } - } + } // @codeCoverageIgnore protected function userAddOrSetPassword(string $method, string $user, string $password = null, string $oldpass = null): int { $passwd = Arsse::$user->$method(...array_slice(func_get_args(), 1)); diff --git a/lib/ImportExport/AbstractImportExport.php b/lib/ImportExport/AbstractImportExport.php index f882ea16..19fa5fc7 100644 --- a/lib/ImportExport/AbstractImportExport.php +++ b/lib/ImportExport/AbstractImportExport.php @@ -57,7 +57,7 @@ abstract class AbstractImportExport { } if (!isset($folderMap[$id])) { // if no existing folder exists, add one - $folderMap[$id] = Arsse::$db->folderAdd($user, ['name' => $f['name'], 'parent' -> $parent]); + $folderMap[$id] = Arsse::$db->folderAdd($user, ['name' => $f['name'], 'parent' => $parent]); } } // process newsfeed subscriptions @@ -118,21 +118,21 @@ abstract class AbstractImportExport { foreach (array_diff(array_column($feedsDb, "id"), $feedMap) as $id) { try { Arsse::$db->subscriptionRemove($user, $id); - } catch (InputException $e) { + } catch (InputException $e) { // @codeCoverageIgnore // ignore errors } } foreach (array_diff(array_column($foldersDb, "id"), $folderMap) as $id) { try { Arsse::$db->folderRemove($user, $id); - } catch (InputException $e) { + } catch (InputException $e) { // @codeCoverageIgnore // ignore errors } } foreach (array_diff(array_column($tagsDb, "name"), array_keys($tagMap)) as $id) { try { Arsse::$db->tagRemove($user, $id, true); - } catch (InputException $e) { + } catch (InputException $e) { // @codeCoverageIgnore // ignore errors } } diff --git a/lib/REST/Fever/API.php b/lib/REST/Fever/API.php index 1401d63a..ac85aa84 100644 --- a/lib/REST/Fever/API.php +++ b/lib/REST/Fever/API.php @@ -207,7 +207,8 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler { // indexed arrays $p->appendChild($this->makeXMLIndexed($v, $d->createElement($k), substr($k, 0, strlen($k) - 1))); } else { - $p->appendChild($this->makeXMLAssoc($v, $d->createElement($k))); + // this case does not actually occur in a proper Fever response + $p->appendChild($this->makeXMLAssoc($v, $d->createElement($k))); // @codeCoverageIgnore } } return $p; diff --git a/tests/cases/ImportExport/TestImportExport.php b/tests/cases/ImportExport/TestImportExport.php index c8af2c19..6c7de1f1 100644 --- a/tests/cases/ImportExport/TestImportExport.php +++ b/tests/cases/ImportExport/TestImportExport.php @@ -212,11 +212,13 @@ class TestImportExport extends \JKingWeb\Arsse\Test\AbstractTest { ['id' => 4, 'name' => "Politics", 'parent' => 0], ['id' => 5, 'name' => "Local", 'parent' => 4], ['id' => 6, 'name' => "National", 'parent' => 4], + ['id' => 7, 'name' => "Nature", 'parent' => 0], // new folder ]]; \Phake::when($this->proc)->parse->thenReturn($in); $this->proc->import("john.doe@example.com", "", false, true); $exp = $this->primeExpectations($this->data, $this->checkTables); $exp['arsse_subscriptions']['rows'][3] = [4, "john.doe@example.com", null, 4, "CBC"]; + $exp['arsse_folders']['rows'][] = [7, "john.doe@example.com", null, "Nature"]; $this->compareExpectations($this->drv, $exp); } diff --git a/tests/cases/Lang/testComplex.php b/tests/cases/Lang/TestComplex.php similarity index 100% rename from tests/cases/Lang/testComplex.php rename to tests/cases/Lang/TestComplex.php diff --git a/tests/lib/Lang/Setup.php b/tests/lib/Lang/Setup.php index 381806f5..e70ccb03 100644 --- a/tests/lib/Lang/Setup.php +++ b/tests/lib/Lang/Setup.php @@ -9,6 +9,7 @@ namespace JKingWeb\Arsse\Test\Lang; use JKingWeb\Arsse\Lang; use JKingWeb\Arsse\Arsse; use org\bovigo\vfs\vfsStream; +use Webmozart\Glob\Glob; trait Setup { public function setUp() { @@ -36,7 +37,10 @@ trait Setup { // set up a file without read access chmod($this->path."ru.php", 0000); // make the test Lang class use the vfs files - $this->l = new TestLang($this->path); + $this->l = \Phake::partialMock(Lang::class, $this->path); + \Phake::when($this->l)->globFiles->thenReturnCallback(function(string $path): array { + return Glob::glob($this->path."*.php"); + }); // create a mock Lang object so as not to create a dependency loop self::clearData(false); Arsse::$lang = \Phake::mock(Lang::class); diff --git a/tests/lib/Lang/TestLang.php b/tests/lib/Lang/TestLang.php deleted file mode 100644 index 3022535e..00000000 --- a/tests/lib/Lang/TestLang.php +++ /dev/null @@ -1,15 +0,0 @@ -path."*.php"); - } -}