Permalink
Browse files

Initial Unit Tests

Bare-bones classes implemented only.
  • Loading branch information...
1 parent 352cdbc commit 39a2336ba94938315600ce628e4cbdb8a0a62e6e @rowanmanning committed Aug 23, 2011
Showing with 127 additions and 0 deletions.
  1. +16 −0 phpunit.xml.dist
  2. +49 −0 tests/TopsyTest.php
  3. +62 −0 tests/bootstrap.php
View
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit backupGlobals="false" backupStaticAttributes="false" bootstrap="./tests/bootstrap.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" syntaxCheck="false">
+
+ <testsuites>
+ <testsuite name="Topsy PHP Test Suite">
+ <directory>./tests</directory>
+ </testsuite>
+ </testsuites>
+
+ <filter>
+ <whitelist>
+ <directory>./lib</directory>
+ </whitelist>
+ </filter>
+
+</phpunit>
View
@@ -0,0 +1,49 @@
+<?php
+/**
+ * Topsy Tests.
+ *
+ * @author Rowan Manning <info@rowanmanning.co.uk>
+ * @copyright Copyright 2011, Rowan Manning
+ * @license Dual licensed under the MIT or GPL Version 2 licenses.
+ * @filesource
+ */
+
+//============================================================
+// TESTS
+//============================================================
+
+/**
+ * Topsy Test Case.
+ *
+ * @todo write tests for `Topsy::request`.
+ */
+class TopsyTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @covers Topsy::calculate_url
+ * @dataProvider getTestEndpointURLs
+ */
+ public function testURLCalculation($endpoint, $expected_result) {
+
+ $instance = new Topsy();
+ $reflection_method = new ReflectionMethod($instance, 'calculate_url');
+ $reflection_method->setAccessible(true);
+
+ $this->assertEquals($expected_result, $reflection_method->invoke($instance, $endpoint));
+
+ }
+
+ /**
+ * Data-provider for testURLCalculation.
+ */
+ public function getTestEndpointURLs() {
+ return array(
+ array('example', 'http://otter.topsy.com/example.json'),
+ array('/example', 'http://otter.topsy.com/example.json'),
+ );
+ }
+
+}
+
+//============================================================
+// end of file
View
@@ -0,0 +1,62 @@
+<?php
+/**
+ * Topsy Tests.
+ *
+ * @author Rowan Manning <info@rowanmanning.co.uk>
+ * @copyright Copyright 2011, Rowan Manning
+ * @license Dual licensed under the MIT or GPL Version 2 licenses.
+ * @filesource
+ */
+
+//============================================================
+// BOOTSTRAP
+//============================================================
+
+/**
+ * Test AutoLoader
+ */
+class TestAutoLoader {
+
+ /**
+ * Load a class from the 'lib' directory
+ */
+ public function load($class_name) {
+
+ // calculate class path
+ $class_name = trim($class_name, '\\');
+ $class_file = dirname(__FILE__) . '/../lib/' . str_replace('\\', '/', $class_name) . '.php';
+
+ // load class
+ if (file_exists($class_file)) {
+ require_once $class_file;
+ return true;
+ }
+
+ }
+
+ /**
+ * Register the auto-loader
+ */
+ public function register() {
+
+ spl_autoload_register(array($this, 'load'));
+
+ }
+
+ /**
+ * Unregister the auto-loader
+ */
+ public function unregister() {
+
+ spl_autoload_unregister(array($this, 'load'));
+
+ }
+
+}
+
+// register the autoloader
+$autoloader = new TestAutoLoader();
+$autoloader->register();
+
+//============================================================
+// end of file

0 comments on commit 39a2336

Please sign in to comment.