Commit 3566402f authored by Taddeus Kroes's avatar Taddeus Kroes

Camelized class method names

parent 4dde6795
...@@ -16,7 +16,7 @@ require_once 'base.php'; ...@@ -16,7 +16,7 @@ require_once 'base.php';
* Simple example: all classes are located in the 'classes' directory. * Simple example: all classes are located in the 'classes' directory.
* <code> * <code>
* $loader = new Autoloader('classes'); * $loader = new Autoloader('classes');
* $loader->load_class('FooBar'); // Includes file 'classes/foo_bar.php' * $loader->loadClass('FooBar'); // Includes file 'classes/foo_bar.php'
* </code> * </code>
* *
* An Autoloader instance can register itself to the SPL autoload stack, so * An Autoloader instance can register itself to the SPL autoload stack, so
...@@ -85,9 +85,9 @@ class Autoloader extends Base { ...@@ -85,9 +85,9 @@ class Autoloader extends Base {
* @param bool $throw Whether to throw an exception when a class file does not exist. * @param bool $throw Whether to throw an exception when a class file does not exist.
*/ */
function __construct($root_directory, $root_namespace='\\', $throw=false) { function __construct($root_directory, $root_namespace='\\', $throw=false) {
$this->set_root_directory($root_directory); $this->setRootDirectory($root_directory);
$this->set_root_namespace($root_namespace); $this->setRootNamespace($root_namespace);
$this->set_throw_errors($throw); $this->setThrowErrors($throw);
} }
/** /**
...@@ -95,7 +95,7 @@ class Autoloader extends Base { ...@@ -95,7 +95,7 @@ class Autoloader extends Base {
* *
* @param bool $throw Whether to throw exceptions. * @param bool $throw Whether to throw exceptions.
*/ */
function set_throw_errors($throw) { function setThrowErrors($throw) {
$this->throw_errors = !!$throw; $this->throw_errors = !!$throw;
} }
...@@ -104,7 +104,7 @@ class Autoloader extends Base { ...@@ -104,7 +104,7 @@ class Autoloader extends Base {
* *
* @return bool * @return bool
*/ */
function get_throw_errors() { function getThrowErrors() {
return $this->throw_errors; return $this->throw_errors;
} }
...@@ -113,8 +113,8 @@ class Autoloader extends Base { ...@@ -113,8 +113,8 @@ class Autoloader extends Base {
* *
* @param string $directory The new root directory. * @param string $directory The new root directory.
*/ */
function set_root_directory($directory) { function setRootDirectory($directory) {
$this->root_directory = self::path_with_slash($directory); $this->root_directory = self::pathWithSlash($directory);
} }
/** /**
...@@ -122,7 +122,7 @@ class Autoloader extends Base { ...@@ -122,7 +122,7 @@ class Autoloader extends Base {
* *
* @return string * @return string
*/ */
function get_root_directory() { function getRootDirectory() {
return $this->root_directory; return $this->root_directory;
} }
...@@ -131,9 +131,9 @@ class Autoloader extends Base { ...@@ -131,9 +131,9 @@ class Autoloader extends Base {
* *
* @param string $namespace The new root namespace. * @param string $namespace The new root namespace.
*/ */
function set_root_namespace($namespace) { function setRootNamespace($namespace) {
// Assert that the namespace ends with a backslash // Assert that the namespace ends with a backslash
if( $namespace[strlen($namespace) - 1] != '\\' ) if ($namespace[strlen($namespace) - 1] != '\\')
$namespace .= '\\'; $namespace .= '\\';
$this->root_namespace = $namespace; $this->root_namespace = $namespace;
...@@ -144,7 +144,7 @@ class Autoloader extends Base { ...@@ -144,7 +144,7 @@ class Autoloader extends Base {
* *
* @return string * @return string
*/ */
function get_root_namespace() { function getRootNamespace() {
return $this->root_namespace; return $this->root_namespace;
} }
...@@ -157,7 +157,7 @@ class Autoloader extends Base { ...@@ -157,7 +157,7 @@ class Autoloader extends Base {
* @param string $classname The class name to convert. * @param string $classname The class name to convert.
* @return string * @return string
*/ */
static function classname_to_filename($classname) { static function classnameToFilename($classname) {
return strtolower(preg_replace('/(?<=.)([A-Z])/', '_\\1', $classname)); return strtolower(preg_replace('/(?<=.)([A-Z])/', '_\\1', $classname));
} }
...@@ -167,7 +167,7 @@ class Autoloader extends Base { ...@@ -167,7 +167,7 @@ class Autoloader extends Base {
* @param string $classname The name of the class to strip the namespace from. * @param string $classname The name of the class to strip the namespace from.
* @return string The stripped class name. * @return string The stripped class name.
*/ */
private function strip_root_namespace($classname) { private function stripRootNamespace($classname) {
$begin = substr($classname, 0, strlen($this->root_namespace)); $begin = substr($classname, 0, strlen($this->root_namespace));
if ($begin == $this->root_namespace) if ($begin == $this->root_namespace)
...@@ -184,9 +184,9 @@ class Autoloader extends Base { ...@@ -184,9 +184,9 @@ class Autoloader extends Base {
* *
* @param string $classname The name of the class to create the file path of. * @param string $classname The name of the class to create the file path of.
*/ */
function create_path($classname) { function createPath($classname) {
$namespaces = array_filter(explode('\\', $classname)); $namespaces = array_filter(explode('\\', $classname));
$dirs = array_map('self::classname_to_filename', $namespaces); $dirs = array_map('self::classnameToFilename', $namespaces);
$path = $this->root_directory; $path = $this->root_directory;
if (count($dirs) > 1) if (count($dirs) > 1)
...@@ -207,9 +207,9 @@ class Autoloader extends Base { ...@@ -207,9 +207,9 @@ class Autoloader extends Base {
* @return bool * @return bool
* @throws FileNotFoundError If the class file does not exist. * @throws FileNotFoundError If the class file does not exist.
*/ */
function load_class($classname, $throw=null) { function loadClass($classname, $throw=null) {
$classname = $this->strip_root_namespace($classname); $classname = $this->stripRootNamespace($classname);
$path = $this->create_path($classname); $path = $this->createPath($classname);
if (!file_exists($path)) { if (!file_exists($path)) {
if ($throw || ($throw === null && $this->throw_errors)) if ($throw || ($throw === null && $this->throw_errors))
...@@ -229,7 +229,7 @@ class Autoloader extends Base { ...@@ -229,7 +229,7 @@ class Autoloader extends Base {
* the stack, instead of appending it. * the stack, instead of appending it.
*/ */
function register($prepend=false) { function register($prepend=false) {
spl_autoload_register(array($this, 'load_class'), true, $prepend); spl_autoload_register(array($this, 'loadClass'), true, $prepend);
} }
} }
......
...@@ -61,7 +61,7 @@ abstract class Base { ...@@ -61,7 +61,7 @@ abstract class Base {
* @param string $directory The directory to append a slash to. * @param string $directory The directory to append a slash to.
* @return string * @return string
*/ */
static function path_with_slash($directory) { static function pathWithSlash($directory) {
return $directory[strlen($directory) - 1] == '/' ? $directory : $directory.'/'; return $directory[strlen($directory) - 1] == '/' ? $directory : $directory.'/';
} }
} }
......
...@@ -16,25 +16,25 @@ require_once 'base.php'; ...@@ -16,25 +16,25 @@ require_once 'base.php';
* *
* Example 1: Index a list based on its values and extract a single attribute. * Example 1: Index a list based on its values and extract a single attribute.
* <code> * <code>
* class Book extends PHPActiveRecord\Model { * class Book extends ActiveRecord\Model {
* static $attr_accessible = array('id', 'name'); * static $attr_accessible = array('id', 'name');
* } * }
* *
* // Index all book names by their id. * // Index all book names by their id.
* $books = Book::all(); // Find a list of books * $books = Book::all(); // Find a list of books
* $collection = new Collection($books); // Put the list in a collection * $collection = new Collection($books); // Put the list in a collection
* $indexed = $collection->index_by('id'); // Create indexes for all books * $indexed = $collection->indexBy('id'); // Create indexes for all books
* $names = $indexed->get_attribute('name'); // Get the values of a single attribute * $names = $indexed->getAttribute('name'); // Get the values of a single attribute
* // $names now contains something like array(1 => 'Some book', 2 => 'Another book') * // $names now contains something like array(1 => 'Some book', 2 => 'Another book')
* *
* // Same as above: * // Same as above:
* $names = Collection::create(Book::all())->index_by('id')->get_attribute('name'); * $names = Collection::create(Book::all())->indexBy('id')->getAttribute('name');
* </code> * </code>
* *
* Example 2: Execute a method for each item in a list. * Example 2: Execute a method for each item in a list.
* <code> * <code>
* // Delete all books * // Delete all books
* Collection::create(Book::all())->map_method('delete'); * Collection::create(Book::all())->mapMethod('delete');
* </code> * </code>
* *
* @package WebBasics * @package WebBasics
...@@ -138,7 +138,7 @@ class Collection extends Base { ...@@ -138,7 +138,7 @@ class Collection extends Base {
* @param int|string $index The index to check existance of. * @param int|string $index The index to check existance of.
* @return bool Whether the index exists. * @return bool Whether the index exists.
*/ */
function index_exists($index) { function indexExists($index) {
return isset($this->items[$index]); return isset($this->items[$index]);
} }
...@@ -157,7 +157,7 @@ class Collection extends Base { ...@@ -157,7 +157,7 @@ class Collection extends Base {
* *
* @param int|string $index The index to the item to delete. * @param int|string $index The index to the item to delete.
*/ */
function delete_index($index) { function deleteIndex($index) {
unset($this->items[$index]); unset($this->items[$index]);
} }
...@@ -167,7 +167,7 @@ class Collection extends Base { ...@@ -167,7 +167,7 @@ class Collection extends Base {
* @param mixed $item The item to delete. * @param mixed $item The item to delete.
*/ */
function delete($item) { function delete($item) {
$this->delete_index(array_search($item, $this->items)); $this->deleteIndex(array_search($item, $this->items));
} }
/** /**
...@@ -178,7 +178,7 @@ class Collection extends Base { ...@@ -178,7 +178,7 @@ class Collection extends Base {
* object's item set and not create a new object. * object's item set and not create a new object.
* @return Collection A collection with the new item set. * @return Collection A collection with the new item set.
*/ */
private function set_items(array $items, $clone=true) { private function setItems(array $items, $clone=true) {
if ($clone) if ($clone)
return new self($items); return new self($items);
...@@ -194,7 +194,7 @@ class Collection extends Base { ...@@ -194,7 +194,7 @@ class Collection extends Base {
* @return Collection A collection without duplicates. * @return Collection A collection without duplicates.
*/ */
function uniques($clone=false) { function uniques($clone=false) {
return $this->set_items(array_values(array_unique($this->items)), $clone); return $this->setItems(array_values(array_unique($this->items)), $clone);
} }
/** /**
...@@ -207,7 +207,7 @@ class Collection extends Base { ...@@ -207,7 +207,7 @@ class Collection extends Base {
* @return Collection A collection with the filtered set of items. * @return Collection A collection with the filtered set of items.
*/ */
function filter($callback, $clone=true) { function filter($callback, $clone=true) {
return $this->set_items(array_values(array_filter($this->items, $callback)), $clone); return $this->setItems(array_values(array_filter($this->items, $callback)), $clone);
} }
/** /**
...@@ -227,13 +227,13 @@ class Collection extends Base { ...@@ -227,13 +227,13 @@ class Collection extends Base {
return $this->filter(function($item) use ($conditions) { return $this->filter(function($item) use ($conditions) {
if (is_object($item)) { if (is_object($item)) {
// Object, match property values // Object, match property values
foreach( $conditions as $property => $value ) foreach ($conditions as $property => $value)
if( $item->{$property} != $value ) if ($item->{$property} != $value)
return false; return false;
} elseif (is_array($item)) { } elseif (is_array($item)) {
// Array item, match array values // Array item, match array values
foreach ($conditions as $property => $value) foreach ($conditions as $property => $value)
if( $item[$property] != $value ) if ($item[$property] != $value)
return false; return false;
} else { } else {
// Other, incompatible type -> throw exception // Other, incompatible type -> throw exception
...@@ -254,7 +254,7 @@ class Collection extends Base { ...@@ -254,7 +254,7 @@ class Collection extends Base {
* @param string $attribute The name of the attribute to get the value of. * @param string $attribute The name of the attribute to get the value of.
* @return array The original item keys, pointing to single attribute values. * @return array The original item keys, pointing to single attribute values.
*/ */
function get_attribute($attribute) { function getAttribute($attribute) {
return array_map(function($item) use ($attribute) { return array_map(function($item) use ($attribute) {
return $item->{$attribute}; return $item->{$attribute};
}, $this->items); }, $this->items);
...@@ -269,13 +269,13 @@ class Collection extends Base { ...@@ -269,13 +269,13 @@ class Collection extends Base {
* @param bool $clone Whether to create a new object, or overwrite the current item set. * @param bool $clone Whether to create a new object, or overwrite the current item set.
* @return Collection A collection object with the values of the attribute used as indices. * @return Collection A collection object with the values of the attribute used as indices.
*/ */
function index_by($attribute, $clone=true) { function indexBy($attribute, $clone=true) {
$indexed = array(); $indexed = array();
foreach( $this->items as $item ) foreach ($this->items as $item)
$indexed[$item->$attribute] = $item; $indexed[$item->$attribute] = $item;
return $this->set_items($indexed, $clone); return $this->setItems($indexed, $clone);
} }
/** /**
...@@ -286,7 +286,7 @@ class Collection extends Base { ...@@ -286,7 +286,7 @@ class Collection extends Base {
* @return Collection A collection with return values of the callback calls. * @return Collection A collection with return values of the callback calls.
*/ */
function map($callback, $clone=true) { function map($callback, $clone=true) {
return $this->set_items(array_map($callback, $this->items), $clone); return $this->setItems(array_map($callback, $this->items), $clone);
} }
/** /**
...@@ -299,13 +299,13 @@ class Collection extends Base { ...@@ -299,13 +299,13 @@ class Collection extends Base {
* @param bool $clone Whether to create a new object, or overwrite the current item set. * @param bool $clone Whether to create a new object, or overwrite the current item set.
* @return Collection A collection with return values of the method calls. * @return Collection A collection with return values of the method calls.
*/ */
function map_method($method_name, array $args=array(), $clone=true) { function mapMethod($method_name, array $args=array(), $clone=true) {
$items = array(); $items = array();
foreach ($this->items as $item) foreach ($this->items as $item)
$items[] = call_user_func_array(array($item, $method_name), $args); $items[] = call_user_func_array(array($item, $method_name), $args);
return $this->set_items($items); return $this->setItems($items);
} }
} }
......
...@@ -35,34 +35,34 @@ class Logger extends Base { ...@@ -35,34 +35,34 @@ class Logger extends Base {
private $dump_format = 'plain'; private $dump_format = 'plain';
private $log_directory = ''; private $log_directory = '';
function set_directory($directory) { function setDirectory($directory) {
$this->log_directory = self::path_with_slash($directory); $this->log_directory = self::pathWithSlash($directory);
} }
function set_dump_format($format) { function setDumpFormat($format) {
if (!in_array($format, self::$allowed_dump_formats)) if (!in_array($format, self::$allowed_dump_formats))
throw new \InvalidArgumentException(sprintf('', $format)); throw new \InvalidArgumentException(sprintf('', $format));
$this->dump_format = $format; $this->dump_format = $format;
} }
function set_format($format) { function setFormat($format) {
$this->format = (string)$format; $this->format = (string)$format;
} }
function get_format() { function getFormat() {
return $this->format; return $this->format;
} }
function get_level() { function getLevel() {
return $this->level; return $this->level;
} }
function get_level_name() { function getLevelName() {
return self::$level_names[$this->level]; return self::$level_names[$this->level];
} }
function set_level($level) { function setLevel($level) {
if (is_string($level)) { if (is_string($level)) {
$level = strtoupper($level); $level = strtoupper($level);
...@@ -78,7 +78,7 @@ class Logger extends Base { ...@@ -78,7 +78,7 @@ class Logger extends Base {
$this->level = $level; $this->level = $level;
} }
function set_property($name, $value) { function setProperty($name, $value) {
$this->properties[$name] = (string)$value; $this->properties[$name] = (string)$value;
} }
...@@ -133,7 +133,7 @@ class Logger extends Base { ...@@ -133,7 +133,7 @@ class Logger extends Base {
if ($name == 'level') if ($name == 'level')
return Logger::$level_names[$level]; return Logger::$level_names[$level];
return $logger->get_formatted_property($matches[1]); return $logger->getFormattedProperty($matches[1]);
}, },
$this->format $this->format
); );
...@@ -169,7 +169,7 @@ class Logger extends Base { ...@@ -169,7 +169,7 @@ class Logger extends Base {
file_put_contents($this->log_directory . $path, $this->dumps()); file_put_contents($this->log_directory . $path, $this->dumps());
} }
function handle_exception(\Exception $e) { function handleException(\Exception $e) {
if( $e === null ) if( $e === null )
return; return;
...@@ -179,17 +179,17 @@ class Logger extends Base { ...@@ -179,17 +179,17 @@ class Logger extends Base {
$this->dump('error'); $this->dump('error');
} }
function set_as_exception_handler() { function setAsExceptionHandler() {
set_exception_handler(array($this, 'handle_exception')); set_exception_handler(array($this, 'handle_exception'));
} }
function get_formatted_property($property) { function getFormattedProperty($property) {
if (isset($this->properties[$property])) if (isset($this->properties[$property]))
return $this->properties[$property]; return $this->properties[$property];
switch( $property ) { switch( $property ) {
case 'loglevel': case 'loglevel':
return $this->get_level_name(); return $this->getLevelName();
case 'date': case 'date':
return strftime('%d-%m-%Y'); return strftime('%d-%m-%Y');
case 'time': case 'time':
......
...@@ -88,7 +88,7 @@ class Node extends Base { ...@@ -88,7 +88,7 @@ class Node extends Base {
* *
* @return int The node's id. * @return int The node's id.
*/ */
function get_id() { function getId() {
return $this->id; return $this->id;
} }
...@@ -97,7 +97,7 @@ class Node extends Base { ...@@ -97,7 +97,7 @@ class Node extends Base {
* *
* @return string The node's name. * @return string The node's name.
*/ */
function get_name() { function getName() {
return $this->name; return $this->name;
} }
...@@ -106,7 +106,7 @@ class Node extends Base { ...@@ -106,7 +106,7 @@ class Node extends Base {
* *
* @return Node|null The parent node if any, NULL otherwise. * @return Node|null The parent node if any, NULL otherwise.
*/ */
function get_parent() { function getParent() {
return $this->parent_node; return $this->parent_node;
} }
...@@ -115,7 +115,7 @@ class Node extends Base { ...@@ -115,7 +115,7 @@ class Node extends Base {
* *
* @return array A list of child nodes. * @return array A list of child nodes.
*/ */
function get_children() { function getChildren() {
return $this->children; return $this->children;
} }
...@@ -126,7 +126,7 @@ class Node extends Base { ...@@ -126,7 +126,7 @@ class Node extends Base {
* @return bool Whether the nodes have the same unique id. * @return bool Whether the nodes have the same unique id.
*/ */
function is(Node $node) { function is(Node $node) {
return $node->get_id() == $this->id; return $node->getId() == $this->id;
} }
/** /**
...@@ -136,7 +136,7 @@ class Node extends Base { ...@@ -136,7 +136,7 @@ class Node extends Base {
* *
* @return bool Whether this node is the root node. * @return bool Whether this node is the root node.
*/ */
function is_root() { function isRoot() {
return $this->parent_node === null; return $this->parent_node === null;
} }
...@@ -147,7 +147,7 @@ class Node extends Base { ...@@ -147,7 +147,7 @@ class Node extends Base {
* *
* @return bool Whether this node is a leaf node. * @return bool Whether this node is a leaf node.
*/ */
function is_leaf() { function isLeaf() {
return !count($this->children); return !count($this->children);
} }
...@@ -158,9 +158,9 @@ class Node extends Base { ...@@ -158,9 +158,9 @@ class Node extends Base {
* @param bool $set_parent Whether to set this node as the child's parent * @param bool $set_parent Whether to set this node as the child's parent
* (defaults to TRUE). * (defaults to TRUE).
*/ */
function add_child(Node &$node, $set_parent=true) { function addChild(Node &$node, $set_parent=true) {
$this->children[] = $node; $this->children[] = $node;
$set_parent && $node->set_parent($this); $set_parent && $node->setParent($this);
} }
/** /**
...@@ -172,7 +172,7 @@ class Node extends Base { ...@@ -172,7 +172,7 @@ class Node extends Base {
*/ */
function add($name, array $data=array()) { function add($name, array $data=array()) {
$node = new self($name, $this); $node = new self($name, $this);
$this->add_child($node, false); $this->addChild($node, false);
return $node->set($data); return $node->set($data);
} }
...@@ -182,7 +182,7 @@ class Node extends Base { ...@@ -182,7 +182,7 @@ class Node extends Base {
* *
* @param Node &$child The node to remove. * @param Node &$child The node to remove.
*/ */
function remove_child(Node &$child) { function removeChild(Node &$child) {
foreach ($this->children as $i => $node) foreach ($this->children as $i => $node)
$node->is($child) && array_splice($this->children, $i, 1); $node->is($child) && array_splice($this->children, $i, 1);
} }
...@@ -194,13 +194,13 @@ class Node extends Base { ...@@ -194,13 +194,13 @@ class Node extends Base {
* @return Node This node. * @return Node This node.
*/ */
function remove() { function remove() {
if ($this->is_root()) if ($this->isRoot())
throw new \RuntimeException('Cannot remove the root node of a tree.'); throw new \RuntimeException('Cannot remove the root node of a tree.');
$this->parent_node->remove_child($this); $this->parent_node->removeChild($this);
foreach ($this->children as $child) foreach ($this->children as $child)
$child->set_parent(null); $child->setParent(null);
return $this; return $this;
} }
...@@ -214,9 +214,9 @@ class Node extends Base { ...@@ -214,9 +214,9 @@ class Node extends Base {
* @param Node|null $parent The parent node to set. * @param Node|null $parent The parent node to set.
* @return Node This node. * @return Node This node.
*/ */
function set_parent($parent) { function setParent($parent) {
if ($this->parent_node !== null) if ($this->parent_node !== null)
$this->parent_node->remove_child($this); $this->parent_node->removeChild($this);
$this->parent_node = &$parent; $this->parent_node = &$parent;
...@@ -292,7 +292,7 @@ class Node extends Base { ...@@ -292,7 +292,7 @@ class Node extends Base {
*/ */
function find($name) { function find($name) {
$has_name = function($child) use ($name) { $has_name = function($child) use ($name) {
return $child->get_name() == $name; return $child->getName() == $name;
}; };
return array_values(array_filter($this->children, $has_name)); return array_values(array_filter($this->children, $has_name));
...@@ -314,9 +314,9 @@ class Node extends Base { ...@@ -314,9 +314,9 @@ class Node extends Base {
foreach ($this->children as $child) { foreach ($this->children as $child) {
if ($deep) { if ($deep) {
$child_copy = $child->copy(true); $child_copy = $child->copy(true);
$copy->add_child($child_copy); $copy->addChild($child_copy);
} else { } else {
$copy->add_child($child, false); $copy->addChild($child, false);
} }
} }
......
...@@ -28,8 +28,8 @@ require_once 'base.php'; ...@@ -28,8 +28,8 @@ require_once 'base.php';
* '/home' => 'home', * '/home' => 'home',
* '/contact' => 'contact' * '/contact' => 'contact'
* )); * ));
* $response = $router->call_handler('/home'); // 'This is the home page.' * $response = $router->callHandler('/home'); // 'This is the home page.'
* $response = $router->call_handler('/contact'); // 'This is the contact page.' * $response = $router->callHandler('/contact'); // 'This is the contact page.'
* </code> * </code>
* *
* You can use regular expression patterns to specify an URL. Any matches are * You can use regular expression patterns to specify an URL. Any matches are
...@@ -42,8 +42,8 @@ require_once 'base.php'; ...@@ -42,8 +42,8 @@ require_once 'base.php';
* $router = new Router(array( * $router = new Router(array(
* '/(home|contact)' => 'page' * '/(home|contact)' => 'page'
* )); * ));
* $response = $router->call_handler('/home'); // 'This is the home page.' * $response = $router->callHandler('/home'); // 'This is the home page.'
* $response = $router->call_handler('/contact'); // 'This is the contact page.' * $response = $router->callHandler('/contact'); // 'This is the contact page.'
* </code> * </code>
* *
* @package WebBasics * @package WebBasics
...@@ -70,7 +70,7 @@ class Router extends Base { ...@@ -70,7 +70,7 @@ class Router extends Base {
*/ */
function __construct(array $routes=array()) { function __construct(array $routes=array()) {
foreach ($routes as $pattern => $handler) foreach ($routes as $pattern => $handler)
$this->add_route($pattern, $handler); $this->addRoute($pattern, $handler);
} }
/** /**
...@@ -87,7 +87,7 @@ class Router extends Base { ...@@ -87,7 +87,7 @@ class Router extends Base {
* @param mixed $handler The handler function to call when $pattern is matched. * @param mixed $handler The handler function to call when $pattern is matched.
* @throws \InvalidArgumentException If $handler is not callable. * @throws \InvalidArgumentException If $handler is not callable.
*/ */
function add_route($pattern, $handler) { function addRoute($pattern, $handler) {
if (!is_callable($handler)) if (!is_callable($handler))
throw new \InvalidArgumentException(sprintf('Handler for patterns "%s" is not callable.', $pattern)); throw new \InvalidArgumentException(sprintf('Handler for patterns "%s" is not callable.', $pattern));
...@@ -107,7 +107,7 @@ class Router extends Base { ...@@ -107,7 +107,7 @@ class Router extends Base {
* @return mixed FALSE if no pattern was matched, the return value of the * @return mixed FALSE if no pattern was matched, the return value of the
* corresponding handler function otherwise. * corresponding handler function otherwise.
*/ */
function call_handler($url) { function callHandler($url) {
foreach ($this->routes as $pattern => $handler) { foreach ($this->routes as $pattern => $handler) {
if (preg_match($pattern, $url, $matches)) { if (preg_match($pattern, $url, $matches)) {
array_shift($matches); array_shift($matches);
......
This diff is collapsed.
...@@ -10,139 +10,139 @@ class AutoloaderTest extends PHPUnit_Framework_TestCase { ...@@ -10,139 +10,139 @@ class AutoloaderTest extends PHPUnit_Framework_TestCase {
$this->autoloader = new Autoloader(PATH); $this->autoloader = new Autoloader(PATH);
} }
function test_set_root_namespace() { function testSetRootNamespace() {
$this->assertAttributeEquals('\\', 'root_namespace', $this->autoloader); $this->assertAttributeEquals('\\', 'root_namespace', $this->autoloader);
$this->autoloader->set_root_namespace('Foo'); $this->autoloader->setRootNamespace('Foo');
$this->assertAttributeEquals('Foo\\', 'root_namespace', $this->autoloader); $this->assertAttributeEquals('Foo\\', 'root_namespace', $this->autoloader);
$this->autoloader->set_root_namespace('Foo\\'); $this->autoloader->setRootNamespace('Foo\\');
$this->assertAttributeEquals('Foo\\', 'root_namespace', $this->autoloader); $this->assertAttributeEquals('Foo\\', 'root_namespace', $this->autoloader);
} }
/** /**
* @depends test_set_root_namespace * @depends testSetRootNamespace
*/ */
function test_get_root_namespace() { function testGetRootNamespace() {
$this->autoloader->set_root_namespace('Foo'); $this->autoloader->setRootNamespace('Foo');
$this->assertEquals($this->autoloader->get_root_namespace(), 'Foo\\'); $this->assertEquals($this->autoloader->getRootNamespace(), 'Foo\\');
} }
/** /**
* @depends test_set_root_namespace * @depends testSetRootNamespace
*/ */
function test_construct_root_namespace() { function testConstructRootNamespace() {
$autoloader = new Autoloader(PATH, 'Foo'); $autoloader = new Autoloader(PATH, 'Foo');
$this->assertAttributeEquals('Foo\\', 'root_namespace', $autoloader); $this->assertAttributeEquals('Foo\\', 'root_namespace', $autoloader);
} }
/** /**
* @depends test_set_root_namespace * @depends testSetRootNamespace
*/ */
function test_strip_root_namespace() { function testStripRootNamespace() {
$strip = new ReflectionMethod('webbasics\Autoloader', 'strip_root_namespace'); $strip = new ReflectionMethod('webbasics\Autoloader', 'stripRootNamespace');
$strip->setAccessible(true); $strip->setAccessible(true);
$this->autoloader->set_root_namespace('Foo'); $this->autoloader->setRootNamespace('Foo');
$this->assertEquals($strip->invoke($this->autoloader, 'Foo\Bar'), 'Bar'); $this->assertEquals($strip->invoke($this->autoloader, 'Foo\Bar'), 'Bar');
} }
function test_set_root_directory() { function testSetRootDirectory() {
$this->autoloader->set_root_directory('tests'); $this->autoloader->setRootDirectory('tests');
$this->assertEquals($this->autoloader->get_root_directory(), 'tests/'); $this->assertEquals($this->autoloader->getRootDirectory(), 'tests/');
} }
function test_classname_to_filename() { function testClassnameToFilename() {
$this->assertEquals(Autoloader::classname_to_filename('Foo'), 'foo'); $this->assertEquals(Autoloader::classnameToFilename('Foo'), 'foo');
$this->assertEquals(Autoloader::classname_to_filename('FooBar'), 'foo_bar'); $this->assertEquals(Autoloader::classnameToFilename('FooBar'), 'foo_bar');
$this->assertEquals(Autoloader::classname_to_filename('fooBar'), 'foo_bar'); $this->assertEquals(Autoloader::classnameToFilename('fooBar'), 'foo_bar');
$this->assertEquals(Autoloader::classname_to_filename('FooBarBaz'), 'foo_bar_baz'); $this->assertEquals(Autoloader::classnameToFilename('FooBarBaz'), 'foo_bar_baz');
} }
/** /**
* @depends test_classname_to_filename * @depends testClassnameToFilename
*/ */
function test_create_path() { function testCreatePath() {
$this->assertEquals($this->autoloader->create_path('Foo'), PATH.'foo.php'); $this->assertEquals($this->autoloader->createPath('Foo'), PATH.'foo.php');
$this->assertEquals($this->autoloader->create_path('\Foo'), PATH.'foo.php'); $this->assertEquals($this->autoloader->createPath('\Foo'), PATH.'foo.php');
$this->assertEquals($this->autoloader->create_path('Foo\Bar'), PATH.'foo/bar.php'); $this->assertEquals($this->autoloader->createPath('Foo\Bar'), PATH.'foo/bar.php');
$this->assertEquals($this->autoloader->create_path('Foo\Bar\Baz'), PATH.'foo/bar/baz.php'); $this->assertEquals($this->autoloader->createPath('Foo\Bar\Baz'), PATH.'foo/bar/baz.php');
$this->assertEquals($this->autoloader->create_path('FooBar\Baz'), PATH.'foo_bar/baz.php'); $this->assertEquals($this->autoloader->createPath('FooBar\Baz'), PATH.'foo_bar/baz.php');
} }
function test_throw_errors() { function testThrowErrors() {
$this->assertFalse($this->autoloader->get_throw_errors()); $this->assertFalse($this->autoloader->getThrowErrors());
$this->autoloader->set_throw_errors(true); $this->autoloader->setThrowErrors(true);
$this->assertTrue($this->autoloader->get_throw_errors()); $this->assertTrue($this->autoloader->getThrowErrors());
} }
/** /**
* @depends test_create_path * @depends testCreatePath
* @depends test_throw_errors * @depends testThrowErrors
*/ */
function test_load_class_not_found() { function testLoadClassNotFound() {
$this->assertFalse($this->autoloader->load_class('foobar')); $this->assertFalse($this->autoloader->loadClass('foobar'));
} }
/** /**
* @depends test_load_class_not_found * @depends testLoadClassNotFound
* @expectedException webbasics\FileNotFoundError * @expectedException webbasics\FileNotFoundError
* @expectedExceptionMessage File "tests/_files/foobar.php" does not exist. * @expectedExceptionMessage File "tests/_files/foobar.php" does not exist.
*/ */
function test_load_class_not_found_error() { function testLoadClassNotFoundError() {
$this->autoloader->set_throw_errors(true); $this->autoloader->setThrowErrors(true);
$this->autoloader->load_class('foobar'); $this->autoloader->loadClass('foobar');
} }
/** /**
* @depends test_load_class_not_found * @depends testLoadClassNotFound
* @expectedException webbasics\FileNotFoundError * @expectedException webbasics\FileNotFoundError
* @expectedExceptionMessage File "tests/_files/foobar.php" does not exist. * @expectedExceptionMessage File "tests/_files/foobar.php" does not exist.
*/ */
function test_load_class_not_found_noerror_overwrite() { function testLoadClassNotFoundNoerrorOverwrite() {
$this->autoloader->load_class('foobar', true); $this->autoloader->loadClass('foobar', true);
} }
/** /**
* @depends test_load_class_not_found * @depends testLoadClassNotFound
*/ */
function test_load_class_not_found_error_overwrite() { function testLoadClassNotFoundErrorOverwrite() {
$this->autoloader->set_throw_errors(true); $this->autoloader->setThrowErrors(true);
$this->assertFalse($this->autoloader->load_class('foobar', false)); $this->assertFalse($this->autoloader->loadClass('foobar', false));
} }
/** /**
* @depends test_load_class_not_found * @depends testLoadClassNotFound
*/ */
function test_load_class() { function testLoadClass() {
$this->assertTrue($this->autoloader->load_class('Foo')); $this->assertTrue($this->autoloader->loadClass('Foo'));
$this->assertTrue(class_exists('Foo', false)); $this->assertTrue(class_exists('Foo', false));
$this->assertTrue($this->autoloader->load_class('Foo\Bar')); $this->assertTrue($this->autoloader->loadClass('Foo\Bar'));
$this->assertTrue(class_exists('Foo\Bar', false)); $this->assertTrue(class_exists('Foo\Bar', false));
} }
/** /**
* @depends test_load_class * @depends testLoadClass
* @depends test_strip_root_namespace * @depends testStripRootNamespace
*/ */
function test_load_class_root_namespace() { function testLoadClassRootNamespace() {
$autoloader = new Autoloader(PATH.'foo'); $autoloader = new Autoloader(PATH.'foo');
$autoloader->set_root_namespace('Foo'); $autoloader->setRootNamespace('Foo');
$this->assertTrue($autoloader->load_class('Bar')); $this->assertTrue($autoloader->loadClass('Bar'));
$this->assertTrue(class_exists('Foo\Bar', false)); $this->assertTrue(class_exists('Foo\Bar', false));
} }
/** /**
* @depends test_load_class * @depends testLoadClass
*/ */
function test_register() { function testRegister() {
$this->autoloader->register(); $this->autoloader->register();
$this->assertTrue(class_exists('Baz')); $this->assertTrue(class_exists('Baz'));
} }
/** /**
* @depends test_register * @depends testRegister
* @depends test_throw_errors * @depends testThrowErrors
*/ */
function test_register_prepend() { function testRegisterPrepend() {
$second_loader = new Autoloader(PATH.'second'); $second_loader = new Autoloader(PATH.'second');
$this->autoloader->register(); $this->autoloader->register();
$second_loader->register(true); // Prepend so that the second loader attemps to load Bar first $second_loader->register(true); // Prepend so that the second loader attemps to load Bar first
......
...@@ -11,11 +11,11 @@ class BaseExtension extends Base { ...@@ -11,11 +11,11 @@ class BaseExtension extends Base {
} }
class BaseTest extends PHPUnit_Framework_TestCase { class BaseTest extends PHPUnit_Framework_TestCase {
function test_create() { function testCreate() {
$this->assertEquals(BaseExtension::create('a', 'b'), new BaseExtension('a', 'b')); $this->assertEquals(BaseExtension::create('a', 'b'), new BaseExtension('a', 'b'));
} }
function test_asprintf() { function testAsprintf() {
$this->assertEquals(webbasics\asprintf('%(foo) baz', array('foo' => 'bar')), 'bar baz'); $this->assertEquals(webbasics\asprintf('%(foo) baz', array('foo' => 'bar')), 'bar baz');
$this->assertEquals(webbasics\asprintf('%(foo) baz %(foo)', $this->assertEquals(webbasics\asprintf('%(foo) baz %(foo)',
array('foo' => 'bar')), 'bar baz bar'); array('foo' => 'bar')), 'bar baz bar');
...@@ -23,9 +23,9 @@ class BaseTest extends PHPUnit_Framework_TestCase { ...@@ -23,9 +23,9 @@ class BaseTest extends PHPUnit_Framework_TestCase {
array('foo' => 'bar', 'bar' => 'foobar')), 'foobar baz bar'); array('foo' => 'bar', 'bar' => 'foobar')), 'foobar baz bar');
} }
function test_path_with_slash() { function testPathWithSlash() {
$this->assertEquals(Base::path_with_slash('dirname'), 'dirname/'); $this->assertEquals(Base::pathWithSlash('dirname'), 'dirname/');
$this->assertEquals(Base::path_with_slash('dirname/'), 'dirname/'); $this->assertEquals(Base::pathWithSlash('dirname/'), 'dirname/');
} }
} }
......
...@@ -11,11 +11,11 @@ class IdObject { ...@@ -11,11 +11,11 @@ class IdObject {
$this->foo = $foo; $this->foo = $foo;
} }
function get_id() { function getId() {
return $this->id; return $this->id;
} }
static function clear_counter() { static function clearCounter() {
self::$count = 0; self::$count = 0;
} }
} }
...@@ -39,7 +39,7 @@ class CollectionTest extends PHPUnit_Framework_TestCase { ...@@ -39,7 +39,7 @@ class CollectionTest extends PHPUnit_Framework_TestCase {
$this->set = set(array(1, 2)); $this->set = set(array(1, 2));
} }
function test_add() { function testAdd() {
$this->set->add(3); $this->set->add(3);
$this->assertEquals($this->set, set(array(1, 2, 3))); $this->assertEquals($this->set, set(array(1, 2, 3)));
} }
...@@ -47,18 +47,18 @@ class CollectionTest extends PHPUnit_Framework_TestCase { ...@@ -47,18 +47,18 @@ class CollectionTest extends PHPUnit_Framework_TestCase {
/** /**
* @expectedException InvalidArgumentException * @expectedException InvalidArgumentException
*/ */
function test_insert_error() { function testInsertError() {
set(array('foo' => 1))->insert(2, 'foo'); set(array('foo' => 1))->insert(2, 'foo');
} }
function test_insert_success() { function testInsertSuccess() {
$this->set->insert(4, 1); $this->set->insert(4, 1);
$this->assertEquals($this->set, set(array(1, 4, 2))); $this->assertEquals($this->set, set(array(1, 4, 2)));
$this->set->insert(5, 0); $this->set->insert(5, 0);
$this->assertEquals($this->set, set(array(5, 1, 4, 2))); $this->assertEquals($this->set, set(array(5, 1, 4, 2)));
} }
function test_all() { function testAll() {
$this->assertEquals(set()->all(), array()); $this->assertEquals(set()->all(), array());
$this->assertEquals(set(array())->all(), array()); $this->assertEquals(set(array())->all(), array());
$this->assertEquals(set(array(1))->all(), array(1)); $this->assertEquals(set(array(1))->all(), array(1));
...@@ -68,108 +68,108 @@ class CollectionTest extends PHPUnit_Framework_TestCase { ...@@ -68,108 +68,108 @@ class CollectionTest extends PHPUnit_Framework_TestCase {
/** /**
* @expectedException OutOfBoundsException * @expectedException OutOfBoundsException
*/ */
function test_last_empty() { function testLastEmpty() {
set()->last(); set()->last();
} }
function test_last() { function testLast() {
$this->assertEquals($this->set->last(), 2); $this->assertEquals($this->set->last(), 2);
} }
/** /**
* @expectedException OutOfBoundsException * @expectedException OutOfBoundsException
*/ */
function test_first_empty() { function testFirstEmpty() {
set()->first(); set()->first();
} }
function test_first() { function testFirst() {
$this->assertEquals($this->set->first(), 1); $this->assertEquals($this->set->first(), 1);
} }
function test_count() { function testCount() {
$this->assertEquals(set()->count(), 0); $this->assertEquals(set()->count(), 0);
$this->assertEquals(set(array())->count(), 0); $this->assertEquals(set(array())->count(), 0);
$this->assertEquals(set(array(1))->count(), 1); $this->assertEquals(set(array(1))->count(), 1);
$this->assertEquals(set(array(1, 2))->count(), 2); $this->assertEquals(set(array(1, 2))->count(), 2);
} }
function test_index_exists() { function testIndexExists() {
$this->assertTrue($this->set->index_exists(1)); $this->assertTrue($this->set->indexExists(1));
$this->assertTrue(set(array('foo' => 'bar'))->index_exists('foo')); $this->assertTrue(set(array('foo' => 'bar'))->indexExists('foo'));
} }
function test_get() { function testGet() {
$this->assertEquals($this->set->get(0), 1); $this->assertEquals($this->set->get(0), 1);
$this->assertEquals($this->set->get(1), 2); $this->assertEquals($this->set->get(1), 2);
$this->assertEquals(set(array('foo' => 'bar'))->get('foo'), 'bar'); $this->assertEquals(set(array('foo' => 'bar'))->get('foo'), 'bar');
} }
function test_delete_index() { function testDeleteIndex() {
$this->set->delete_index(0); $this->set->deleteIndex(0);
$this->assertEquals($this->set, set(array(1 => 2))); $this->assertEquals($this->set, set(array(1 => 2)));
} }
function test_delete() { function testDelete() {
$this->set->delete(1); $this->set->delete(1);
$this->assertEquals($this->set, set(array(1 => 2))); $this->assertEquals($this->set, set(array(1 => 2)));
} }
function assert_set_equals(array $expected_items, $set) { function assertSetEquals(array $expected_items, $set) {
$this->assertAttributeEquals($expected_items, 'items', $set); $this->assertAttributeEquals($expected_items, 'items', $set);
} }
function test_uniques() { function testUniques() {
$this->assert_set_equals(array(1, 2), set(array(1, 2, 2))->uniques()); $this->assertSetEquals(array(1, 2), set(array(1, 2, 2))->uniques());
$this->assert_set_equals(array(2, 1), set(array(2, 1, 2))->uniques()); $this->assertSetEquals(array(2, 1), set(array(2, 1, 2))->uniques());
$this->assert_set_equals(array(2, 1), set(array(2, 2, 1))->uniques()); $this->assertSetEquals(array(2, 1), set(array(2, 2, 1))->uniques());
} }
function set_items($collection, $items, $clone) { function setItems($collection, $items, $clone) {
$rm = new ReflectionMethod($collection, 'set_items'); $rm = new ReflectionMethod($collection, 'setItems');
$rm->setAccessible(true); $rm->setAccessible(true);
return $rm->invoke($collection, $items, $clone); return $rm->invoke($collection, $items, $clone);
} }
function test_set_items_clone() { function testSetItemsClone() {
$result = $this->set_items($this->set, array(3, 4), true); $result = $this->setItems($this->set, array(3, 4), true);
$this->assert_set_equals(array(1, 2), $this->set); $this->assertSetEquals(array(1, 2), $this->set);
$this->assert_set_equals(array(3, 4), $result); $this->assertSetEquals(array(3, 4), $result);
$this->assertNotSame($this->set, $result); $this->assertNotSame($this->set, $result);
} }
function test_set_items_no_clone() { function testSetItemsNoClone() {
$result = $this->set_items($this->set, array(3, 4), false); $result = $this->setItems($this->set, array(3, 4), false);
$this->assertSame($this->set, $result); $this->assertSame($this->set, $result);
} }
/** /**
* @depends test_set_items_clone * @depends testSetItemsClone
*/ */
function test_filter() { function testFilter() {
$smaller_than_five = function($number) { return $number < 5; }; $smaller_than_five = function($number) { return $number < 5; };
$this->assert_set_equals(array(2, 4, 1, 4), set(array(2, 7, 4, 7, 1, 8, 4, 5))->filter($smaller_than_five)); $this->assertSetEquals(array(2, 4, 1, 4), set(array(2, 7, 4, 7, 1, 8, 4, 5))->filter($smaller_than_five));
} }
/** /**
* @depends test_filter * @depends testFilter
*/ */
function test_find_success() { function testFindSuccess() {
$items = array( $items = array(
array('foo' => 'bar', 'bar' => 'baz'), array('foo' => 'bar', 'bar' => 'baz'),
array('foo' => 'baz', 'bar' => 'foo'), array('foo' => 'baz', 'bar' => 'foo'),
std_object(array('foo' => 'bar', 'baz' => 'bar')), std_object(array('foo' => 'bar', 'baz' => 'bar')),
); );
$this->assert_set_equals(array($items[1]), set($items)->find(array('foo' => 'baz'))); $this->assertSetEquals(array($items[1]), set($items)->find(array('foo' => 'baz')));
$this->assert_set_equals(array($items[0], $items[2]), set($items)->find(array('foo' => 'bar'))); $this->assertSetEquals(array($items[0], $items[2]), set($items)->find(array('foo' => 'bar')));
} }
/** /**
* @depends test_find_success * @depends testFindSuccess
* @expectedException \UnexpectedValueException * @expectedException \UnexpectedValueException
* @expectedExceptionMessage Collection::find encountered a non-object and non-array item "foobar". * @expectedExceptionMessage Collection::find encountered a non-object and non-array item "foobar".
*/ */
function test_find_failure() { function testFindFailure() {
$items = array( $items = array(
array('foo' => 'bar', 'bar' => 'baz'), array('foo' => 'bar', 'bar' => 'baz'),
'foobar', 'foobar',
...@@ -177,47 +177,47 @@ class CollectionTest extends PHPUnit_Framework_TestCase { ...@@ -177,47 +177,47 @@ class CollectionTest extends PHPUnit_Framework_TestCase {
set($items)->find(array('foo' => 'bar')); set($items)->find(array('foo' => 'bar'));
} }
function test_get_attribute_simple() { function testGetAttributeSimple() {
IdObject::clear_counter(); IdObject::clearCounter();
$set = set(array(new IdObject(), new IdObject(), new IdObject())); $set = set(array(new IdObject(), new IdObject(), new IdObject()));
$this->assertEquals(array(1, 2, 3), $set->get_attribute('id')); $this->assertEquals(array(1, 2, 3), $set->getAttribute('id'));
} }
/** /**
* @depends test_get_attribute_simple * @depends testGetAttributeSimple
*/ */
function test_get_attribute_indices() { function testGetAttributeIndices() {
IdObject::clear_counter(); IdObject::clearCounter();
$set = set(array('foo' => new IdObject(), 'bar' => new IdObject(), 'baz' => new IdObject())); $set = set(array('foo' => new IdObject(), 'bar' => new IdObject(), 'baz' => new IdObject()));
$this->assertEquals(array('foo' => 1, 'bar' => 2, 'baz' => 3), $set->get_attribute('id')); $this->assertEquals(array('foo' => 1, 'bar' => 2, 'baz' => 3), $set->getAttribute('id'));
} }
/** /**
* @depends test_all * @depends testAll
* @depends test_set_items_clone * @depends testSetItemsClone
*/ */
function test_index_by() { function testIndexBy() {
IdObject::clear_counter(); IdObject::clearCounter();
$set = set(array(new IdObject('foo'), new IdObject('bar'), new IdObject('baz'))); $set = set(array(new IdObject('foo'), new IdObject('bar'), new IdObject('baz')));
list($foo, $bar, $baz) = $set->all(); list($foo, $bar, $baz) = $set->all();
$this->assert_set_equals(array('foo' => $foo, 'bar' => $bar, 'baz' => $baz), $set->index_by('foo')); $this->assertSetEquals(array('foo' => $foo, 'bar' => $bar, 'baz' => $baz), $set->indexBy('foo'));
} }
/** /**
* @depends test_set_items_clone * @depends testSetItemsClone
*/ */
function test_map() { function testMap() {
$plus_five = function($number) { return $number + 5; }; $plus_five = function($number) { return $number + 5; };
$this->assert_set_equals(array(6, 7, 8), set(array(1, 2, 3))->map($plus_five)); $this->assertSetEquals(array(6, 7, 8), set(array(1, 2, 3))->map($plus_five));
} }
/** /**
* @depends test_set_items_clone * @depends testSetItemsClone
*/ */
function test_map_method() { function testMapMethod() {
IdObject::clear_counter(); IdObject::clearCounter();
$set = set(array(new IdObject(), new IdObject(), new IdObject())); $set = set(array(new IdObject(), new IdObject(), new IdObject()));
$this->assert_set_equals(array(1, 2, 3), $set->map_method('get_id')); $this->assertSetEquals(array(1, 2, 3), $set->mapMethod('getId'));
} }
} }
......
...@@ -11,138 +11,138 @@ define('LOGFILE', 'build/temp.log'); ...@@ -11,138 +11,138 @@ define('LOGFILE', 'build/temp.log');
class LoggerTest extends PHPUnit_Extensions_OutputTestCase { class LoggerTest extends PHPUnit_Extensions_OutputTestCase {
function setUp() { function setUp() {
$this->logger = new Logger(); $this->logger = new Logger();
$this->logger->set_property('name', NAME); $this->logger->setProperty('name', NAME);
$this->logger->set_format(FORMAT); $this->logger->setFormat(FORMAT);
is_dir('build') || mkdir('build'); is_dir('build') || mkdir('build');
} }
function assert_dumps($expected) { function assertDumps($expected) {
$this->assertEquals($this->logger->dumps(), $expected); $this->assertEquals($this->logger->dumps(), $expected);
} }
function test_set_directory() { function testSetDirectory() {
$this->logger->set_directory('logs'); $this->logger->setDirectory('logs');
$this->assertAttributeEquals('logs/', 'log_directory', $this->logger); $this->assertAttributeEquals('logs/', 'log_directory', $this->logger);
$this->logger->set_directory('logs/'); $this->logger->setDirectory('logs/');
$this->assertAttributeEquals('logs/', 'log_directory', $this->logger); $this->assertAttributeEquals('logs/', 'log_directory', $this->logger);
} }
function test_set_format() { function testSetFormat() {
$this->logger->set_format('foo'); $this->logger->setFormat('foo');
$this->assertAttributeEquals('foo', 'format', $this->logger); $this->assertAttributeEquals('foo', 'format', $this->logger);
} }
function test_set_dump_format_success() { function testSetDumpFormatSuccess() {
$this->logger->set_dump_format('html'); $this->logger->setDumpFormat('html');
$this->assertAttributeEquals('html', 'dump_format', $this->logger); $this->assertAttributeEquals('html', 'dump_format', $this->logger);
} }
/** /**
* @expectedException InvalidArgumentException * @expectedException InvalidArgumentException
*/ */
function test_set_dump_format_failure() { function testSetDumpFormatFailure() {
$this->logger->set_dump_format('foo'); $this->logger->setDumpFormat('foo');
} }
function test_get_format() { function testGetFormat() {
$this->assertEquals($this->logger->get_format(), FORMAT); $this->assertEquals($this->logger->getFormat(), FORMAT);
} }
function test_get_level() { function testGetLevel() {
$this->assertEquals($this->logger->get_level(), Logger::WARNING); $this->assertEquals($this->logger->getLevel(), Logger::WARNING);
$this->assertEquals($this->logger->get_level_name(), 'WARNING'); $this->assertEquals($this->logger->getLevelName(), 'WARNING');
} }
/** /**
* @depends test_get_level * @depends testGetLevel
*/ */
function test_set_level() { function testSetLevel() {
$this->logger->set_level('info'); $this->logger->setLevel('info');
$this->assertEquals($this->logger->get_level(), Logger::INFO); $this->assertEquals($this->logger->getLevel(), Logger::INFO);
$this->logger->set_level('DEBUG'); $this->logger->setLevel('DEBUG');
$this->assertEquals($this->logger->get_level(), Logger::DEBUG); $this->assertEquals($this->logger->getLevel(), Logger::DEBUG);
$this->logger->set_level('WaRnInG'); $this->logger->setLevel('WaRnInG');
$this->assertEquals($this->logger->get_level(), Logger::WARNING); $this->assertEquals($this->logger->getLevel(), Logger::WARNING);
$this->logger->set_level(Logger::ERROR); $this->logger->setLevel(Logger::ERROR);
$this->assertEquals($this->logger->get_level(), Logger::ERROR); $this->assertEquals($this->logger->getLevel(), Logger::ERROR);
} }
function test_format() { function testFormat() {
$this->logger->error('test message'); $this->logger->error('test message');
$this->assert_dumps('ERROR: test message'); $this->assertDumps('ERROR: test message');
} }
function test_set_property() { function testSetProperty() {
$this->logger->set_property('name', 'Logger'); $this->logger->setProperty('name', 'Logger');
$this->assertEquals($this->logger->get_formatted_property('name'), 'Logger'); $this->assertEquals($this->logger->getFormattedProperty('name'), 'Logger');
} }
/** /**
* @depends test_format * @depends testFormat
*/ */
function test_clear() { function testClear() {
$this->logger->warning('test message'); $this->logger->warning('test message');
$this->logger->clear(); $this->logger->clear();
$this->assert_dumps(''); $this->assertDumps('');
} }
/** /**
* @depends test_set_level * @depends testSetLevel
* @depends test_clear * @depends testClear
*/ */
function test_process_level() { function testProcessLevel() {
$this->logger->info('test message'); $this->logger->info('test message');
$this->assert_dumps(''); $this->assertDumps('');
$this->logger->warning('test message'); $this->logger->warning('test message');
$this->assert_dumps('WARNING: test message'); $this->assertDumps('WARNING: test message');
$this->logger->critical('test message'); $this->logger->critical('test message');
$this->assert_dumps("WARNING: test message\nCRITICAL: test message"); $this->assertDumps("WARNING: test message\nCRITICAL: test message");
$this->logger->clear(); $this->logger->clear();
$this->logger->set_level('debug'); $this->logger->setLevel('debug');
$this->logger->debug('test message'); $this->logger->debug('test message');
$this->assert_dumps('DEBUG: test message'); $this->assertDumps('DEBUG: test message');
} }
function test_get_formatted_property() { function testGetFormattedProperty() {
$this->assertEquals($this->logger->get_formatted_property('name'), NAME); $this->assertEquals($this->logger->getFormattedProperty('name'), NAME);
$this->assertEquals($this->logger->get_formatted_property('loglevel'), 'WARNING'); $this->assertEquals($this->logger->getFormattedProperty('loglevel'), 'WARNING');
$this->assertRegExp('/^\d{2}-\d{2}-\d{4}$/', $this->assertRegExp('/^\d{2}-\d{2}-\d{4}$/',
$this->logger->get_formatted_property('date')); $this->logger->getFormattedProperty('date'));
$this->assertRegExp('/^\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2}$/', $this->assertRegExp('/^\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2}$/',
$this->logger->get_formatted_property('datetime')); $this->logger->getFormattedProperty('datetime'));
$this->assertRegExp('/^\d{2}:\d{2}:\d{2}$/', $this->assertRegExp('/^\d{2}:\d{2}:\d{2}$/',
$this->logger->get_formatted_property('time')); $this->logger->getFormattedProperty('time'));
$this->setExpectedException('\InvalidArgumentException'); $this->setExpectedException('\InvalidArgumentException');
$this->logger->get_formatted_property('foo'); $this->logger->getFormattedProperty('foo');
} }
function test_dumps_property_format() { function testDumpsPropertyFormat() {
$this->logger->warning('test message'); $this->logger->warning('test message');
$this->logger->set_format('%(name): %(level): %(message)'); $this->logger->setFormat('%(name): %(level): %(message)');
$this->assert_dumps(NAME.': WARNING: test message'); $this->assertDumps(NAME.': WARNING: test message');
} }
/** /**
* @depends test_process_level * @depends testProcessLevel
*/ */
function test_dump_plain() { function testDumpPlain() {
$this->logger->warning('test message'); $this->logger->warning('test message');
$this->expectOutputString('WARNING: test message'); $this->expectOutputString('WARNING: test message');
$this->logger->dump(); $this->logger->dump();
} }
/** /**
* @depends test_process_level * @depends testProcessLevel
*/ */
function test_dump_html() { function testDumpHtml() {
$this->logger->warning('test message'); $this->logger->warning('test message');
$this->logger->set_dump_format('html'); $this->logger->setDumpFormat('html');
$this->expectOutputString('<strong>Log:</strong><br /><pre>WARNING: test message</pre>'); $this->expectOutputString('<strong>Log:</strong><br /><pre>WARNING: test message</pre>');
$this->logger->dump(); $this->logger->dump();
} }
function test_save() { function testSave() {
$this->logger->warning('test message'); $this->logger->warning('test message');
$this->logger->save(LOGFILE); $this->logger->save(LOGFILE);
$this->assertStringEqualsFile(LOGFILE, 'WARNING: test message'); $this->assertStringEqualsFile(LOGFILE, 'WARNING: test message');
...@@ -152,30 +152,30 @@ class LoggerTest extends PHPUnit_Extensions_OutputTestCase { ...@@ -152,30 +152,30 @@ class LoggerTest extends PHPUnit_Extensions_OutputTestCase {
unlink(LOGFILE); unlink(LOGFILE);
} }
function find_logfile() { function findLogfile() {
$files = scandir(LOGDIR); $files = scandir(LOGDIR);
$this->assertEquals(3, count($files)); $this->assertEquals(3, count($files));
return $files[2]; return $files[2];
} }
/** /**
* @depends test_save * @depends testSave
*/ */
function test_dump_file_regular() { function testDumpFileRegular() {
$this->logger->set_directory(LOGDIR); $this->logger->setDirectory(LOGDIR);
$this->logger->set_dump_format('file'); $this->logger->setDumpFormat('file');
$this->logger->warning('test message'); $this->logger->warning('test message');
$this->logger->dump(); $this->logger->dump();
$filename = $this->find_logfile(); $filename = $this->findLogfile();
$this->assertStringEqualsFile(LOGDIR . $filename, 'WARNING: test message'); $this->assertStringEqualsFile(LOGDIR . $filename, 'WARNING: test message');
unlink(LOGDIR . $filename); unlink(LOGDIR . $filename);
$this->assertRegExp('/^log_\d{2}-\d{2}-\d{4}_\d{2}-\d{2}-\d{2}.log$/', $filename); $this->assertRegExp('/^log_\d{2}-\d{2}-\d{4}_\d{2}-\d{2}-\d{2}.log$/', $filename);
} }
function test_handle_exception() { function testHandleException() {
$this->logger->set_dump_format('none'); $this->logger->setDumpFormat('none');
$this->logger->handle_exception(new RuntimeException('test message')); $this->logger->handleException(new RuntimeException('test message'));
$this->assertNotEquals($this->logger->dumps(), ''); $this->assertNotEquals($this->logger->dumps(), '');
} }
} }
......
...@@ -10,90 +10,90 @@ class NodeTest extends PHPUnit_Framework_TestCase { ...@@ -10,90 +10,90 @@ class NodeTest extends PHPUnit_Framework_TestCase {
$this->root = new Node('test node'); $this->root = new Node('test node');
} }
function test_get_id() { function testGetId() {
$this->assertEquals($this->root->get_id(), 1); $this->assertEquals($this->root->getId(), 1);
$this->assertEquals(Node::create('')->get_id(), 2); $this->assertEquals(Node::create('')->getId(), 2);
} }
function test_get_name() { function testGetName() {
$this->assertEquals($this->root->get_name(), 'test node'); $this->assertEquals($this->root->getName(), 'test node');
$this->assertEquals(Node::create('second node')->get_name(), 'second node'); $this->assertEquals(Node::create('second node')->getName(), 'second node');
} }
function test_get_parent() { function testGetParent() {
$this->assertNull($this->root->get_parent()); $this->assertNull($this->root->getParent());
$this->assertSame(Node::create('', $this->root)->get_parent(), $this->root); $this->assertSame(Node::create('', $this->root)->getParent(), $this->root);
} }
function test_is() { function testIs() {
$mirror = $this->root; $mirror = $this->root;
$this->assertTrue($mirror->is($this->root)); $this->assertTrue($mirror->is($this->root));
$this->assertFalse(Node::create('')->is($this->root)); $this->assertFalse(Node::create('')->is($this->root));
} }
function test_is_root() { function testIsRoot() {
$this->assertTrue($this->root->is_root()); $this->assertTrue($this->root->isRoot());
$this->assertFalse(Node::create('', $this->root)->is_root()); $this->assertFalse(Node::create('', $this->root)->isRoot());
} }
function test_add_child() { function testAddChild() {
$node = new Node(''); $node = new Node('');
$this->root->add_child($node); $this->root->addChild($node);
$this->assertAttributeEquals(array($node), 'children', $this->root); $this->assertAttributeEquals(array($node), 'children', $this->root);
$this->assertSame($node->get_parent(), $this->root); $this->assertSame($node->getParent(), $this->root);
} }
/** /**
* @depends test_add_child * @depends testAddChild
*/ */
function test_get_children() { function testGetChildren() {
$this->assertEquals($this->root->get_children(), array()); $this->assertEquals($this->root->getChildren(), array());
$node = new Node(''); $node = new Node('');
$this->root->add_child($node); $this->root->addChild($node);
$this->assertSame($this->root->get_children(), array($node)); $this->assertSame($this->root->getChildren(), array($node));
} }
function test_add_child_no_set_parent() { function testAddChildNoSetParent() {
$node = new Node(''); $node = new Node('');
$this->root->add_child($node, false); $this->root->addChild($node, false);
$this->assertAttributeEquals(array($node), 'children', $this->root); $this->assertAttributeEquals(array($node), 'children', $this->root);
$this->assertNull($node->get_parent()); $this->assertNull($node->getParent());
} }
/** /**
* @depends test_add_child * @depends testAddChild
*/ */
function test_is_leaf() { function testIsLeaf() {
$node = new Node(''); $node = new Node('');
$this->root->add_child($node); $this->root->addChild($node);
$this->assertTrue($node->is_leaf()); $this->assertTrue($node->isLeaf());
$this->assertFalse($this->root->is_leaf()); $this->assertFalse($this->root->isLeaf());
} }
/** /**
* @depends test_add_child * @depends testAddChild
*/ */
function test_add() { function testAdd() {
$node = $this->root->add('name', array('foo' => 'bar')); $node = $this->root->add('name', array('foo' => 'bar'));
$this->assertEquals($node->get_name(), 'name'); $this->assertEquals($node->getName(), 'name');
$this->assertEquals($node->get('foo'), 'bar'); $this->assertEquals($node->get('foo'), 'bar');
$this->assertSame($node->get_parent(), $this->root); $this->assertSame($node->getParent(), $this->root);
} }
/** /**
* @depends test_add * @depends testAdd
*/ */
function test_remove_child() { function testRemoveChild() {
$node1 = $this->root->add('name', array('foo' => 'bar')); $node1 = $this->root->add('name', array('foo' => 'bar'));
$node2 = $this->root->add('name', array('foo' => 'bar')); $node2 = $this->root->add('name', array('foo' => 'bar'));
$this->root->remove_child($node2); $this->root->removeChild($node2);
$this->assertAttributeSame(array($node1), 'children', $this->root); $this->assertAttributeSame(array($node1), 'children', $this->root);
} }
/** /**
* @depends test_remove_child * @depends testRemoveChild
*/ */
function test_remove_leaf() { function testRemoveLeaf() {
$node1 = $this->root->add('name', array('foo' => 'bar')); $node1 = $this->root->add('name', array('foo' => 'bar'));
$node2 = $this->root->add('name', array('foo' => 'bar')); $node2 = $this->root->add('name', array('foo' => 'bar'));
$node1->remove(); $node1->remove();
...@@ -101,39 +101,39 @@ class NodeTest extends PHPUnit_Framework_TestCase { ...@@ -101,39 +101,39 @@ class NodeTest extends PHPUnit_Framework_TestCase {
} }
/** /**
* @depends test_remove_leaf * @depends testRemoveLeaf
*/ */
function test_remove_node() { function testRemoveNode() {
$node = $this->root->add('node'); $node = $this->root->add('node');
$leaf = $node->add('leaf'); $leaf = $node->add('leaf');
$node->remove(); $node->remove();
$this->assertAttributeEquals(array(), 'children', $this->root); $this->assertAttributeEquals(array(), 'children', $this->root);
$this->assertNull($leaf->get_parent()); $this->assertNull($leaf->getParent());
} }
/** /**
* @depends test_remove_child * @depends testRemoveChild
* @expectedException \RuntimeException * @expectedException \RuntimeException
*/ */
function test_remove_root() { function testRemoveRoot() {
$node1 = $this->root->add('name', array('foo' => 'bar')); $node1 = $this->root->add('name', array('foo' => 'bar'));
$node2 = $this->root->add('name', array('foo' => 'bar')); $node2 = $this->root->add('name', array('foo' => 'bar'));
$this->root->remove(); $this->root->remove();
$this->assertAttributeSame(array($node2), 'children', $this->root); $this->assertAttributeSame(array($node2), 'children', $this->root);
} }
function test_set_single() { function testSetSingle() {
$this->root->set('foo', 'bar'); $this->root->set('foo', 'bar');
$this->assertAttributeEquals(array('foo' => 'bar'), 'variables', $this->root); $this->assertAttributeEquals(array('foo' => 'bar'), 'variables', $this->root);
$this->root->set('bar', 'baz'); $this->root->set('bar', 'baz');
$this->assertAttributeEquals(array('foo' => 'bar', 'bar' => 'baz'), 'variables', $this->root); $this->assertAttributeEquals(array('foo' => 'bar', 'bar' => 'baz'), 'variables', $this->root);
} }
function test_set_return() { function testSetReturn() {
$this->assertSame($this->root->set('foo', 'bar'), $this->root); $this->assertSame($this->root->set('foo', 'bar'), $this->root);
} }
function test_set_multiple() { function testSetMultiple() {
$this->root->set(array('foo' => 'bar')); $this->root->set(array('foo' => 'bar'));
$this->assertAttributeEquals(array('foo' => 'bar'), 'variables', $this->root); $this->assertAttributeEquals(array('foo' => 'bar'), 'variables', $this->root);
$this->root->set(array('bar' => 'baz')); $this->root->set(array('bar' => 'baz'));
...@@ -141,7 +141,7 @@ class NodeTest extends PHPUnit_Framework_TestCase { ...@@ -141,7 +141,7 @@ class NodeTest extends PHPUnit_Framework_TestCase {
} }
/** /**
* @depends test_set_single * @depends testSetSingle
*/ */
function test___set() { function test___set() {
$this->root->foo = 'bar'; $this->root->foo = 'bar';
...@@ -151,16 +151,16 @@ class NodeTest extends PHPUnit_Framework_TestCase { ...@@ -151,16 +151,16 @@ class NodeTest extends PHPUnit_Framework_TestCase {
} }
/** /**
* @depends test_set_multiple * @depends testSetMultiple
*/ */
function test_get_direct() { function testGetDirect() {
$this->root->set(array('foo' => 'bar', 'bar' => 'baz')); $this->root->set(array('foo' => 'bar', 'bar' => 'baz'));
$this->assertEquals($this->root->get('foo'), 'bar'); $this->assertEquals($this->root->get('foo'), 'bar');
$this->assertEquals($this->root->get('bar'), 'baz'); $this->assertEquals($this->root->get('bar'), 'baz');
} }
/** /**
* @depends test_get_direct * @depends testGetDirect
*/ */
function test___get() { function test___get() {
$this->root->set(array('foo' => 'bar', 'bar' => 'baz')); $this->root->set(array('foo' => 'bar', 'bar' => 'baz'));
...@@ -169,22 +169,22 @@ class NodeTest extends PHPUnit_Framework_TestCase { ...@@ -169,22 +169,22 @@ class NodeTest extends PHPUnit_Framework_TestCase {
} }
/** /**
* @depends test_set_single * @depends testSetSingle
*/ */
function test_get_ancestor() { function testGetAncestor() {
$this->root->set('foo', 'bar'); $this->root->set('foo', 'bar');
$node = $this->root->add(''); $node = $this->root->add('');
$this->assertEquals($node->get('foo'), 'bar'); $this->assertEquals($node->get('foo'), 'bar');
} }
function test_get_failure() { function testGetFailure() {
$this->assertNull($this->root->get('foo')); $this->assertNull($this->root->get('foo'));
} }
/** /**
* @depends test_get_name * @depends testGetName
*/ */
function test_find() { function testFind() {
$node1 = $this->root->add('foo'); $node1 = $this->root->add('foo');
$node2 = $this->root->add('bar'); $node2 = $this->root->add('bar');
$node3 = $this->root->add('foo'); $node3 = $this->root->add('foo');
...@@ -192,34 +192,34 @@ class NodeTest extends PHPUnit_Framework_TestCase { ...@@ -192,34 +192,34 @@ class NodeTest extends PHPUnit_Framework_TestCase {
} }
/** /**
* @depends test_set_multiple * @depends testSetMultiple
*/ */
function test_copy_simple() { function testCopySimple() {
$copy = $this->root->copy(); $copy = $this->root->copy();
$this->assertEquals($this->root, $copy); $this->assertEquals($this->root, $copy);
$this->assertNotSame($this->root, $copy); $this->assertNotSame($this->root, $copy);
} }
/** /**
* @depends test_copy_simple * @depends testCopySimple
*/ */
function test_copy_shallow() { function testCopyShallow() {
$child = $this->root->add(''); $child = $this->root->add('');
$copy = $this->root->copy(); $copy = $this->root->copy();
$this->assertAttributeSame(array($child), 'children', $copy); $this->assertAttributeSame(array($child), 'children', $copy);
} }
/** /**
* @depends test_get_children * @depends testGetChildren
* @depends test_copy_simple * @depends testCopySimple
*/ */
function test_copy_deep() { function testCopyDeep() {
$child = $this->root->add('foo'); $child = $this->root->add('foo');
$copy = $this->root->copy(true); $copy = $this->root->copy(true);
$copy_children = $copy->get_children(); $copy_children = $copy->getChildren();
$child_copy = reset($copy_children); $child_copy = reset($copy_children);
$this->assertNotSame($copy_children, $this->root->get_children()); $this->assertNotSame($copy_children, $this->root->getChildren());
$this->assertSame($child_copy->get_parent(), $copy); $this->assertSame($child_copy->getParent(), $copy);
} }
} }
......
...@@ -24,29 +24,29 @@ class RouterTest extends PHPUnit_Framework_TestCase { ...@@ -24,29 +24,29 @@ class RouterTest extends PHPUnit_Framework_TestCase {
)); ));
} }
function test_call_handler_success() { function testCallHandlerSuccess() {
$this->assertEquals(true, $this->router->call_handler('foo')); $this->assertEquals(true, $this->router->callHandler('foo'));
$this->assertEquals('bar', $this->router->call_handler('bar')); $this->assertEquals('bar', $this->router->callHandler('bar'));
$this->assertEquals('baz', $this->router->call_handler('baz')); $this->assertEquals('baz', $this->router->callHandler('baz'));
$this->assertEquals('barbaz', $this->router->call_handler('bazbar')); $this->assertEquals('barbaz', $this->router->callHandler('bazbar'));
} }
function test_call_handler_failure() { function testCallHandlerFailure() {
$this->assertFalse($this->router->call_handler('barfoo')); $this->assertFalse($this->router->callHandler('barfoo'));
} }
function test_call_handler_skip() { function testCallHandlerSkip() {
$foo = 'foo'; $foo = 'foo';
$bar = function() use (&$foo) { $foo = 'bar'; return false; }; $bar = function() use (&$foo) { $foo = 'bar'; return false; };
$baz = function() { return; }; $baz = function() { return; };
$router = new Router(array('.*' => $bar, 'baz' => $baz)); $router = new Router(array('.*' => $bar, 'baz' => $baz));
$router->call_handler('baz'); $router->callHandler('baz');
$this->assertEquals('bar', $foo); $this->assertEquals('bar', $foo);
} }
function test_add_route() { function testAddRoute() {
$this->router->add_route('(foobar)', 'test_handler_arg'); $this->router->addRoute('(foobar)', 'test_handler_arg');
$this->assertEquals('foobar', $this->router->call_handler('foobar')); $this->assertEquals('foobar', $this->router->callHandler('foobar'));
} }
} }
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment