Permalink
Browse files

Updating tests for better coverage and streamlining phar file boostrap

  • Loading branch information...
1 parent 6bdc6ce commit b17e9c5109b11aa711b1ee0ae0a44f212bbf60d7 @a-musing-moose committed Mar 1, 2011
View
@@ -2,5 +2,5 @@ package.title = Freebase
package.file = Freebase.phar
package.author = Jonathan Moss <jonathan.moss@tangentone.com.au>
package.copyright = Tangent/One Australia Pty Ltd (c)
-package.description = Freebase is a php library for Freebase
+package.description = Freebase is a php library for accessing Freebase.com
package.default = freebase
View
@@ -15,7 +15,7 @@
}
/**
- * Autoloader for the wotsit package
+ * Autoloader for the Freebase package
*/
class FreebaseAutoLoader
{
@@ -85,12 +85,11 @@ public function processParameters(array $argv)
switch (true) {
case in_array('test', $commands):
require_once 'PHPUnit/Autoload.php';
- $verbose = in_array('--verbose', $switches);
$this->printHeader($filename);
if (in_array('--testdox', $switches)) {
$listener = new PHPUnit_Util_TestDox_ResultPrinter_Text();
} else {
- $listener = new PHPUnit_TextUI_ResultPrinter(null, $verbose);
+ $listener = new PHPUnit_TextUI_ResultPrinter(null, false);
}
$this->runTests($listener);
break;
@@ -113,8 +112,7 @@ public function processParameters(array $argv)
*/
private function runTests(PHPUnit_Framework_TestListener $listener)
{
- echo "RUNNING TEST SUITE:\n^^^^^^^^^^^^^^^^^^^\n";
- ini_set('display_errors', true);
+ echo "RUNNING TEST SUITE:\n\n";
set_include_path(get_include_path() . PATH_SEPARATOR . 'Freebase.phar');
require_once 'phar://Freebase/tests/unit/UnitTests.php';
$suite = UnitTests::suite();
@@ -125,7 +123,7 @@ private function runTests(PHPUnit_Framework_TestListener $listener)
} catch (Exception $e) {
die($e->getMessage());
}
- echo "\n";
+ echo $result->wasSuccessful() ? "[OK]\n" : "[FAIL]\n";
die((int)$result->wasSuccessful());
}
@@ -136,12 +134,12 @@ private function runTests(PHPUnit_Framework_TestListener $listener)
private function listContent($filename)
{
$p = new Phar($filename, 0);
- echo "LISTING METADATA\n^^^^^^^^^^^^^^^^\n";
+ echo "METADATA:\n";
foreach ($p->getMetadata() as $key => $value) {
echo "\t{$key}: {$value}\n";
}
- echo "\nLISTING CONTENTS\n^^^^^^^^^^^^^^^^\n";
+ echo "\nCONTENTS:\n";
foreach (new RecursiveIteratorIterator($p) as $file) {
$path = $file->getPathname();
$path = substr($path, strpos($path, $filename) + strlen($filename));
@@ -171,17 +169,16 @@ private function printHeader($filename)
private function printHelp()
{
echo <<<EOD
-Usage: php Wotsit.phar [switches] test
- php Wotsit.phar [switches] help
- php Wotsit.phar [switches] list
+Usage: php Freebase.phar [switches] test
+ php Freebase.phar [switches] help
+ php Freebase.phar [switches] list
Actions:
test Runs the unit test suite
help Show this usage information
list Lists the metadata and file content of this library
Switches:
- --verbose Will output a more verbose test report
--testdox Will output a test results in the testdox format
@@ -39,7 +39,7 @@ public function getAttributeValue($key)
*/
public function getChildren()
{
- return array($this);
+ return array();
}
/**
View
@@ -66,13 +66,17 @@ public function fetchByQuery(Query $query)
protected function doRequest($url, $jsonData = null)
{
$ch = \curl_init();
- \curl_setopt($ch, \CURLOPT_URL, $url);
- \curl_setopt($ch, \CURLOPT_HEADER, false);
- \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, true);
+ $options = array(
+ \CURLOPT_URL => $url,
+ \CURLOPT_HEADER => false,
+ \CURLOPT_RETURNTRANSFER => true
+ );
if (null !== $jsonData) {
- \curl_setopt($ch, \CURLOPT_POST, true);
- \curl_setopt($ch, \CURLOPT_POSTFIELDS, array('query' => $jsonData));
+ $options[\CURLOPT_POST] = true;
+ $options[\CURLOPT_POSTFIELDS] = array('query' => $jsonData);
}
+
+ \curl_setopt_array($ch, $options);
$response = \curl_exec($ch);
\curl_close($ch);
return $response;
View
@@ -185,14 +185,11 @@ public function getChildByPath($path)
$nodeList = \explode(".", $path);
$node = $this;
foreach ($nodeList as $name) {
- if (null === $node) {
+ if ($node instanceof \freebase\EmptyNode) {
break;
}
$node = $node->getChildByName($name);
}
- if (null === $node) {
- $node = new EmptyNode();
- }
return $node;
}
View
@@ -0,0 +1,15 @@
+{
+ "code": "/api/status/error",
+ "messages": [{
+ "code": "/api/status/error/mql/parse",
+ "info": {
+ },
+ "message": "Can't use a default clause at the root of the query",
+ "path": "",
+ "query": [{
+ "error_inside": "."
+ }]
+ }],
+ "status": "200 OK",
+ "transaction_id": "cache;cache03.p01.sjc1:8101;2011-03-01T00:35:01Z;0051"
+}
View
@@ -0,0 +1,110 @@
+{
+ "code": "/api/status/ok",
+ "result": {
+ "alias": [],
+ "id": "/soft/isbn/9780006476153/best",
+ "properties": {
+ "/book/book_edition/book": {
+ "expected_type": {
+ "id": "/book/book",
+ "text": "Book"
+ },
+ "text": "Edition Of",
+ "values": [
+ {
+ "id": "/en/along_came_a_spider",
+ "text": "Along Came a Spider",
+ "url": "http://www.freebase.com/view/en/along_came_a_spider"
+ }
+ ]
+ },
+ "/book/book_edition/dewey_decimal_number": {
+ "expected_type": {
+ "id": "/type/text",
+ "text": "Text"
+ },
+ "text": "Dewey decimal number",
+ "values": [
+ {
+ "text": "813",
+ "value": "813"
+ }
+ ]
+ },
+ "/book/book_edition/isbn": {
+ "expected_type": {
+ "id": "/book/isbn",
+ "text": "ISBN"
+ },
+ "text": "ISBN",
+ "values": [
+ {
+ "id": "/soft/isbn/9780006476153",
+ "text": "9780006476153",
+ "url": "http://www.freebase.com/view/soft/isbn/9780006476153"
+ }
+ ]
+ },
+ "/book/book_edition/number_of_pages": {
+ "expected_type": {
+ "id": "/book/pagination",
+ "text": "Pagination"
+ },
+ "properties": [
+ {
+ "expected_type": {
+ "id": "/type/int",
+ "text": "Integer"
+ },
+ "id": "/book/pagination/numbered_pages",
+ "text": "Numbered pages"
+ }
+ ],
+ "text": "Number of pages",
+ "values": [
+ {
+ "/book/pagination/numbered_pages": {
+ "expected_type": {
+ "id": "/type/int",
+ "text": "Integer"
+ },
+ "text": "Numbered pages",
+ "values": [
+ {
+ "text": "435",
+ "value": 435
+ }
+ ]
+ },
+ "id": "/m/04vd7l_",
+ "text": "435"
+ }
+ ]
+ },
+ "/book/book_edition/publication_date": {
+ "expected_type": {
+ "id": "/type/datetime",
+ "text": "Date/Time"
+ },
+ "text": "Publication date",
+ "values": [
+ {
+ "text": "1994",
+ "value": "1994"
+ }
+ ]
+ }
+ },
+ "text": "Along came a spider",
+ "type": [
+ {
+ "id": "/book/book_edition",
+ "text": "Book Edition"
+ }
+ ],
+ "url": "http://www.freebase.com/view/soft/isbn/9780006476153/best",
+ "webpage": []
+ },
+ "status": "200 OK",
+ "transaction_id": "cache;cache02.p01.sjc1:8101;2011-02-23T23:51:28Z;0011"
+}
Oops, something went wrong.

0 comments on commit b17e9c5

Please sign in to comment.