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

Camelized class method names

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