diff --git a/.gitignore b/.gitignore index 19ce2922..11eaf823 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,4 @@ .htconfig.php #* favicon.* - - +tests/coverage.html diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..3cf4a7c0 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +test: + cd tests && phpunit --coverage-html=coverage.html && x-www-browser ./coverage.html/index.html \ No newline at end of file diff --git a/autoload.php b/autoload.php new file mode 100644 index 00000000..0ac5f982 --- /dev/null +++ b/autoload.php @@ -0,0 +1,41 @@ + array( + __DIR__ . '/src', + __DIR__ . '/tests/unit/src', + ), + ); + + // go through the prefixes + foreach ($prefixes as $prefix => $dirs) { + + // does the requested class match the namespace prefix? + $prefix_len = strlen($prefix); + if (substr($class, 0, $prefix_len) !== $prefix) { + continue; + } + + // strip the prefix off the class + $class = substr($class, $prefix_len); + + // a partial filename + $part = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php'; + + // go through the directories to find classes + foreach ($dirs as $dir) { + $dir = str_replace('/', DIRECTORY_SEPARATOR, $dir); + $file = $dir . DIRECTORY_SEPARATOR . $part; + if (is_readable($file)) { + require $file; + return; + } + } + } + +}); diff --git a/index.php b/index.php index e6fc910c..464afaed 100755 --- a/index.php +++ b/index.php @@ -1,5 +1,6 @@ + + + unit/src + + + + + ../src + + + diff --git a/tests/unit/src/Example/HelloTest.php b/tests/unit/src/Example/HelloTest.php new file mode 100644 index 00000000..3e6c06a0 --- /dev/null +++ b/tests/unit/src/Example/HelloTest.php @@ -0,0 +1,23 @@ +sayHello(); + + //Check that it returns the message we expect. + $this->assertEquals("Hello world!", $output); + + } + +} \ No newline at end of file