From c25bec30bf009eb9818dd5f59cb22adb1b13890d Mon Sep 17 00:00:00 2001 From: Will Milton Date: Wed, 16 May 2012 09:14:12 -0500 Subject: [PATCH] basic testability additions Modified phpunit.xml.dist to reflect less poor understanding of the tool. Added basic composer stuff so that Travis will work. --- composer.lock | 14 ++ phpunit.xml.dist | 9 - tests/BadFaith/Tests/ItemCollectionTest.php | 2 +- vendor/.composer/ClassLoader.php | 5 + vendor/.composer/autoload.php | 5 + vendor/.composer/autoload_classmap.php | 5 + vendor/.composer/autoload_namespaces.php | 5 + vendor/autoload.php | 25 +++ vendor/composer/ClassLoader.php | 203 ++++++++++++++++++++ vendor/composer/autoload_classmap.php | 9 + vendor/composer/autoload_namespaces.php | 10 + 11 files changed, 282 insertions(+), 10 deletions(-) create mode 100644 composer.lock create mode 100644 vendor/.composer/ClassLoader.php create mode 100644 vendor/.composer/autoload.php create mode 100644 vendor/.composer/autoload_classmap.php create mode 100644 vendor/.composer/autoload_namespaces.php create mode 100644 vendor/autoload.php create mode 100644 vendor/composer/ClassLoader.php create mode 100644 vendor/composer/autoload_classmap.php create mode 100644 vendor/composer/autoload_namespaces.php diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..b9db82e --- /dev/null +++ b/composer.lock @@ -0,0 +1,14 @@ +{ + "hash": "306849a2153bdf0e21dd3cdb340daf86", + "packages": [ + + ], + "packages-dev": null, + "aliases": [ + + ], + "minimum-stability": "dev", + "stability-flags": [ + + ] +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ebb2f9e..121cffb 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -15,14 +15,5 @@ ./tests/BadFaith - - ./tests/BadFaith - - - ./tests/BadFaith - - - ./tests/BadFaith - diff --git a/tests/BadFaith/Tests/ItemCollectionTest.php b/tests/BadFaith/Tests/ItemCollectionTest.php index 4f712ee..9f75085 100644 --- a/tests/BadFaith/Tests/ItemCollectionTest.php +++ b/tests/BadFaith/Tests/ItemCollectionTest.php @@ -38,4 +38,4 @@ public function testExpectedOrder($expected, $given) $this->assertEquals($expected[$i++], $item->getPref()); } } -} \ No newline at end of file +} diff --git a/vendor/.composer/ClassLoader.php b/vendor/.composer/ClassLoader.php new file mode 100644 index 0000000..53e65df --- /dev/null +++ b/vendor/.composer/ClassLoader.php @@ -0,0 +1,5 @@ + $path) { + $loader->add($namespace, $path); + } + + $classMap = require $composerDir . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + + $loader->register(); + + return $loader; +}); diff --git a/vendor/composer/ClassLoader.php b/vendor/composer/ClassLoader.php new file mode 100644 index 0000000..2bd60bb --- /dev/null +++ b/vendor/composer/ClassLoader.php @@ -0,0 +1,203 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0 class loader + * + * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier + * @author Jordi Boggiano + */ +class ClassLoader +{ + private $prefixes = array(); + private $fallbackDirs = array(); + private $useIncludePath = false; + private $classMap = array(); + + public function getPrefixes() + { + return $this->prefixes; + } + + public function getFallbackDirs() + { + return $this->fallbackDirs; + } + + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param array $classMap Class to filename map + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of classes + * + * @param string $prefix The classes prefix + * @param array|string $paths The location(s) of the classes + */ + public function add($prefix, $paths) + { + if (!$prefix) { + foreach ((array) $paths as $path) { + $this->fallbackDirs[] = $path; + } + return; + } + if (isset($this->prefixes[$prefix])) { + $this->prefixes[$prefix] = array_merge( + $this->prefixes[$prefix], + (array) $paths + ); + } else { + $this->prefixes[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param Boolean $useIncludePath + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return Boolean + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Registers this instance as an autoloader. + * + * @param Boolean $prepend Whether to prepend the autoloader or not + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + } + + /** + * Unregisters this instance as an autoloader. + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return Boolean|null True, if loaded + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + require $file; + return true; + } + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|null The path, if found + */ + public function findFile($class) + { + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + + if ('\\' == $class[0]) { + $class = substr($class, 1); + } + + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $classPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)) . DIRECTORY_SEPARATOR; + $className = substr($class, $pos + 1); + } else { + // PEAR-like class name + $classPath = null; + $className = $class; + } + + $classPath .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; + + foreach ($this->prefixes as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($dir . DIRECTORY_SEPARATOR . $classPath)) { + return $dir . DIRECTORY_SEPARATOR . $classPath; + } + } + } + } + + foreach ($this->fallbackDirs as $dir) { + if (file_exists($dir . DIRECTORY_SEPARATOR . $classPath)) { + return $dir . DIRECTORY_SEPARATOR . $classPath; + } + } + + if ($this->useIncludePath && $file = stream_resolve_include_path($classPath)) { + return $file; + } + } +} diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php new file mode 100644 index 0000000..4a9177d --- /dev/null +++ b/vendor/composer/autoload_classmap.php @@ -0,0 +1,9 @@ + $baseDir . '/lib/', +);