Skip to content

Commit

Permalink
Added unit tests (phpunit) for FeedService.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbenard committed Aug 1, 2015
1 parent 7016de2 commit b767b3b
Show file tree
Hide file tree
Showing 13 changed files with 2,502 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app.yaml
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
application: comicfeeds-1022 application: comicfeeds-1022
version: 6 version: 7
runtime: php55 runtime: php55
api_version: 1 api_version: 1
threadsafe: no threadsafe: no
Expand Down
10 changes: 9 additions & 1 deletion classes/FeedService.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ public function fetchPageContents($url) {
} }


public function getLinkFromEntry(SimpleXMLElement $entry) { public function getLinkFromEntry(SimpleXMLElement $entry) {
$url = $entry->link['href']; if (!isset($entry->link)) {
throw new Exception("Link element was not present");
}

$url = $entry->link['href'] ? $entry->link['href'] : (string)$entry->link;
if (!$url) {
throw new Exception("Unable to detect link URL.");
}

return $url; return $url;
} }


Expand Down
9 changes: 1 addition & 8 deletions classes/GenericComicService.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -73,14 +73,7 @@ protected function fetch() {
} }


private function getEntryContents(SimpleXMLElement $entry) { private function getEntryContents(SimpleXMLElement $entry) {
if (!isset($entry->link)) { $url = $this->feedService->getLinkFromEntry($entry);
throw new Exception("Link element was not present");
}

$url = $entry->link['href'] ? $entry->link['href'] : (string)$entry->link;
if (!$url) {
throw new Exception("Unable to detect link URL.");
}


$this->log->log("\tFetching URL: $url"); $this->log->log("\tFetching URL: $url");
$contents = $this->feedService->fetchPageContents($url); $contents = $this->feedService->fetchPageContents($url);
Expand Down
5 changes: 4 additions & 1 deletion classes/autoload.php
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php <?php


spl_autoload_register(function ($class) { spl_autoload_register(function ($class) {
include __DIR__ . '/../classes/' . $class . '.php'; $filename = __DIR__ . '/../classes/' . $class . '.php';
if (file_exists($filename)) {
include(__DIR__ . '/../classes/' . $class . '.php');
}
}); });
3 changes: 2 additions & 1 deletion composer.json
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,6 @@
{ {
"require": { "require": {
"pimple/pimple": "~3.0" "pimple/pimple": "~3.0",
"phpunit/phpunit": "4.7.*"
} }
} }
Loading

0 comments on commit b767b3b

Please sign in to comment.