From 8462bed7820cecc23a0e0d64aa50db7be92272d9 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 9 Oct 2014 09:08:19 +0200 Subject: cleanup test method in appconfig class, add test for item serialization --- config/appconfig.php | 56 +++++++++++++++++++++++++++++----------------- tests/unit/db/ItemTest.php | 40 +++++++++++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 23 deletions(-) diff --git a/config/appconfig.php b/config/appconfig.php index 52e82dc25..3729e56b2 100644 --- a/config/appconfig.php +++ b/config/appconfig.php @@ -153,51 +153,65 @@ class AppConfig { } } - private function testDatabaseDependencies($databases, $databaseType) { - if(!in_array($databaseType, $databases)) { + + private function testDatabaseDependencies() { + if(array_key_exists('databases', $this->config)) { + $databases = $this->config['databases']; + $databaseType = $this->databaseType; + + if(!in_array($databaseType, $databases)) { return 'Database ' . $databaseType . ' not supported.' . 'App is only compatible with ' . implode(', ', $databases); - } else { - return ''; + } } + return ''; } - /** - * Validates all dependencies that the app has - * @throws DependencyException if one version is not satisfied - */ - public function testDependencies() { - $msg = ''; - - // test databases - if(array_key_exists('databases', $this->config)) { - $msg .= $this->testDatabaseDependencies( - $this->config['databases'], $this->databaseType - ); - } - // test dependencies + private function testPHPDependencies() { if(array_key_exists('dependencies', $this->config)) { $deps = $this->config['dependencies']; if (array_key_exists('php', $deps)) { - $msg .= $this->requireVersion($this->phpVersion, $deps['php'], + return $this->requireVersion($this->phpVersion, $deps['php'], 'PHP'); } + } + return ''; + } + + + private function testLibraryDependencies() { + if(array_key_exists('dependencies', $this->config)) { + + $deps = $this->config['dependencies']; + if (array_key_exists('libs', $deps)) { foreach ($deps['libs'] as $lib => $versions) { if(array_key_exists($lib, $this->installedExtensions)) { - $msg .= $this->requireVersion($this->installedExtensions[$lib], + return $this->requireVersion($this->installedExtensions[$lib], $versions, 'PHP extension ' . $lib); } else { - $msg .= 'PHP extension ' . $lib . ' required but not installed'; + return 'PHP extension ' . $lib . ' required but not installed'; } } } } + return ''; + } + + + /** + * Validates all dependencies that the app has + * @throws DependencyException if one version is not satisfied + */ + public function testDependencies() { + $msg = $this->testDatabaseDependencies(); + $msg .= $this->testPHPDependencies(); + $msg .= $this->testLibraryDependencies(); if($msg !== '') { throw new DependencyException($msg); diff --git a/tests/unit/db/ItemTest.php b/tests/unit/db/ItemTest.php index 23deb4c14..4c9569ed4 100644 --- a/tests/unit/db/ItemTest.php +++ b/tests/unit/db/ItemTest.php @@ -89,6 +89,42 @@ class ItemTest extends \PHPUnit_Framework_TestCase { } + public function testJSONSerialize() { + $item = new Item(); + $item->setId(3); + $item->setGuid('guid'); + $item->setGuidHash('hash'); + $item->setUrl('https://google'); + $item->setTitle('title'); + $item->setAuthor('author'); + $item->setPubDate(123); + $item->setBody('body'); + $item->setEnclosureMime('audio/ogg'); + $item->setEnclosureLink('enclink'); + $item->setFeedId(1); + $item->setStatus(0); + $item->setUnread(); + $item->setStarred(); + $item->setLastModified(321); + + $this->assertEquals([ + 'id' => 3, + 'guid' => 'guid', + 'guidHash' => 'hash', + 'url' => 'https://google', + 'title' => 'title', + 'author' => 'author', + 'pubDate' => 123, + 'body' => 'body', + 'enclosureMime' => 'audio/ogg', + 'enclosureLink' => 'enclink', + 'feedId' => 1, + 'unread' => true, + 'starred' => true, + 'lastModified' => 321 + ], $item->jsonSerialize()); + } + public function testToExport() { $item = new Item(); $item->setId(3); @@ -154,7 +190,7 @@ class ItemTest extends \PHPUnit_Framework_TestCase { ]; $compareWith = Item::fromImport($import); - + $this->assertEquals($item, $compareWith); } @@ -199,7 +235,7 @@ class ItemTest extends \PHPUnit_Framework_TestCase { public function testMakeLinksInBodyOpenNewTab() { $item = new Item(); $item->setBody("ha"); - $this->assertEquals("ha", + $this->assertEquals("ha", $item->getBody()); } -- cgit v1.2.3