Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webbasics
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
webbasics
Commits
3566402f
Commit
3566402f
authored
Oct 05, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Camelized class method names
parent
4dde6795
Changes
14
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
575 additions
and
575 deletions
+575
-575
autoloader.php
autoloader.php
+20
-20
base.php
base.php
+1
-1
collection.php
collection.php
+21
-21
logger.php
logger.php
+14
-14
node.php
node.php
+19
-19
router.php
router.php
+7
-7
template.php
template.php
+41
-41
tests/test_autoloader.php
tests/test_autoloader.php
+61
-61
tests/test_base.php
tests/test_base.php
+5
-5
tests/test_collection.php
tests/test_collection.php
+59
-59
tests/test_logger.php
tests/test_logger.php
+70
-70
tests/test_node.php
tests/test_node.php
+65
-65
tests/test_router.php
tests/test_router.php
+12
-12
tests/test_template.php
tests/test_template.php
+180
-180
No files found.
autoloader.php
View file @
3566402f
...
...
@@ -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
_c
lass('FooBar'); // Includes file 'classes/foo_bar.php'
* $loader->load
C
lass('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_d
irectory
(
$root_directory
);
$this
->
set
_root_n
amespace
(
$root_namespace
);
$this
->
set
_throw_e
rrors
(
$throw
);
$this
->
set
RootD
irectory
(
$root_directory
);
$this
->
set
RootN
amespace
(
$root_namespace
);
$this
->
set
ThrowE
rrors
(
$throw
);
}
/**
...
...
@@ -95,7 +95,7 @@ class Autoloader extends Base {
*
* @param bool $throw Whether to throw exceptions.
*/
function
set
_throw_e
rrors
(
$throw
)
{
function
set
ThrowE
rrors
(
$throw
)
{
$this
->
throw_errors
=
!!
$throw
;
}
...
...
@@ -104,7 +104,7 @@ class Autoloader extends Base {
*
* @return bool
*/
function
get
_throw_e
rrors
()
{
function
get
ThrowE
rrors
()
{
return
$this
->
throw_errors
;
}
...
...
@@ -113,8 +113,8 @@ class Autoloader extends Base {
*
* @param string $directory The new root directory.
*/
function
set
_root_d
irectory
(
$directory
)
{
$this
->
root_directory
=
self
::
path
_with_s
lash
(
$directory
);
function
set
RootD
irectory
(
$directory
)
{
$this
->
root_directory
=
self
::
path
WithS
lash
(
$directory
);
}
/**
...
...
@@ -122,7 +122,7 @@ class Autoloader extends Base {
*
* @return string
*/
function
get
_root_d
irectory
()
{
function
get
RootD
irectory
()
{
return
$this
->
root_directory
;
}
...
...
@@ -131,9 +131,9 @@ class Autoloader extends Base {
*
* @param string $namespace The new root namespace.
*/
function
set
_root_n
amespace
(
$namespace
)
{
function
set
RootN
amespace
(
$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_n
amespace
()
{
function
get
RootN
amespace
()
{
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_f
ilename
(
$classname
)
{
static
function
classname
ToF
ilename
(
$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_n
amespace
(
$classname
)
{
private
function
strip
RootN
amespace
(
$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
_p
ath
(
$classname
)
{
function
create
P
ath
(
$classname
)
{
$namespaces
=
array_filter
(
explode
(
'\\'
,
$classname
));
$dirs
=
array_map
(
'self::classname
_to_f
ilename'
,
$namespaces
);
$dirs
=
array_map
(
'self::classname
ToF
ilename'
,
$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
_c
lass
(
$classname
,
$throw
=
null
)
{
$classname
=
$this
->
strip
_root_n
amespace
(
$classname
);
$path
=
$this
->
create
_p
ath
(
$classname
);
function
load
C
lass
(
$classname
,
$throw
=
null
)
{
$classname
=
$this
->
strip
RootN
amespace
(
$classname
);
$path
=
$this
->
create
P
ath
(
$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
_c
lass'
),
true
,
$prepend
);
spl_autoload_register
(
array
(
$this
,
'load
C
lass'
),
true
,
$prepend
);
}
}
...
...
base.php
View file @
3566402f
...
...
@@ -61,7 +61,7 @@ abstract class Base {
* @param string $directory The directory to append a slash to.
* @return string
*/
static
function
path
_with_s
lash
(
$directory
)
{
static
function
path
WithS
lash
(
$directory
)
{
return
$directory
[
strlen
(
$directory
)
-
1
]
==
'/'
?
$directory
:
$directory
.
'/'
;
}
}
...
...
collection.php
View file @
3566402f
...
...
@@ -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
PHP
ActiveRecord\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
_b
y('id'); // Create indexes for all books
* $names = $indexed->get
_a
ttribute('name'); // Get the values of a single attribute
* $indexed = $collection->index
B
y('id'); // Create indexes for all books
* $names = $indexed->get
A
ttribute('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_a
ttribute('name');
* $names = Collection::create(Book::all())->index
By('id')->getA
ttribute('name');
* </code>
*
* Example 2: Execute a method for each item in a list.
* <code>
* // Delete all books
* Collection::create(Book::all())->map
_m
ethod('delete');
* Collection::create(Book::all())->map
M
ethod('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
_e
xists
(
$index
)
{
function
index
E
xists
(
$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
_i
ndex
(
$index
)
{
function
delete
I
ndex
(
$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
_i
ndex
(
array_search
(
$item
,
$this
->
items
));
$this
->
delete
I
ndex
(
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
_i
tems
(
array
$items
,
$clone
=
true
)
{
private
function
set
I
tems
(
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
_i
tems
(
array_values
(
array_unique
(
$this
->
items
)),
$clone
);
return
$this
->
set
I
tems
(
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
_i
tems
(
array_values
(
array_filter
(
$this
->
items
,
$callback
)),
$clone
);
return
$this
->
set
I
tems
(
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
_a
ttribute
(
$attribute
)
{
function
get
A
ttribute
(
$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
_b
y
(
$attribute
,
$clone
=
true
)
{
function
index
B
y
(
$attribute
,
$clone
=
true
)
{
$indexed
=
array
();
foreach
(
$this
->
items
as
$item
)
foreach
(
$this
->
items
as
$item
)
$indexed
[
$item
->
$attribute
]
=
$item
;
return
$this
->
set
_i
tems
(
$indexed
,
$clone
);
return
$this
->
set
I
tems
(
$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
_i
tems
(
array_map
(
$callback
,
$this
->
items
),
$clone
);
return
$this
->
set
I
tems
(
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
_m
ethod
(
$method_name
,
array
$args
=
array
(),
$clone
=
true
)
{
function
map
M
ethod
(
$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
_i
tems
(
$items
);
return
$this
->
set
I
tems
(
$items
);
}
}
...
...
logger.php
View file @
3566402f
...
...
@@ -35,34 +35,34 @@ class Logger extends Base {
private
$dump_format
=
'plain'
;
private
$log_directory
=
''
;
function
set
_d
irectory
(
$directory
)
{
$this
->
log_directory
=
self
::
path
_with_s
lash
(
$directory
);
function
set
D
irectory
(
$directory
)
{
$this
->
log_directory
=
self
::
path
WithS
lash
(
$directory
);
}
function
set
_dump_f
ormat
(
$format
)
{
function
set
DumpF
ormat
(
$format
)
{
if
(
!
in_array
(
$format
,
self
::
$allowed_dump_formats
))
throw
new
\InvalidArgumentException
(
sprintf
(
''
,
$format
));
$this
->
dump_format
=
$format
;
}
function
set
_f
ormat
(
$format
)
{
function
set
F
ormat
(
$format
)
{
$this
->
format
=
(
string
)
$format
;
}
function
get
_f
ormat
()
{
function
get
F
ormat
()
{
return
$this
->
format
;
}
function
get
_l
evel
()
{
function
get
L
evel
()
{
return
$this
->
level
;
}
function
get
_level_n
ame
()
{
function
get
LevelN
ame
()
{
return
self
::
$level_names
[
$this
->
level
];
}
function
set
_l
evel
(
$level
)
{
function
set
L
evel
(
$level
)
{
if
(
is_string
(
$level
))
{
$level
=
strtoupper
(
$level
);
...
...
@@ -78,7 +78,7 @@ class Logger extends Base {
$this
->
level
=
$level
;
}
function
set
_p
roperty
(
$name
,
$value
)
{
function
set
P
roperty
(
$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_p
roperty
(
$matches
[
1
]);
return
$logger
->
get
FormattedP
roperty
(
$matches
[
1
]);
},
$this
->
format
);
...
...
@@ -169,7 +169,7 @@ class Logger extends Base {
file_put_contents
(
$this
->
log_directory
.
$path
,
$this
->
dumps
());
}
function
handle
_e
xception
(
\Exception
$e
)
{
function
handle
E
xception
(
\Exception
$e
)
{
if
(
$e
===
null
)
return
;
...
...
@@ -179,17 +179,17 @@ class Logger extends Base {
$this
->
dump
(
'error'
);
}
function
set
_as_exception_h
andler
()
{
function
set
AsExceptionH
andler
()
{
set_exception_handler
(
array
(
$this
,
'handle_exception'
));
}
function
get
_formatted_p
roperty
(
$property
)
{
function
get
FormattedP
roperty
(
$property
)
{
if
(
isset
(
$this
->
properties
[
$property
]))
return
$this
->
properties
[
$property
];
switch
(
$property
)
{
case
'loglevel'
:
return
$this
->
get
_level_n
ame
();
return
$this
->
get
LevelN
ame
();
case
'date'
:
return
strftime
(
'%d-%m-%Y'
);
case
'time'
:
...
...
node.php
View file @
3566402f
...
...
@@ -88,7 +88,7 @@ class Node extends Base {
*
* @return int The node's id.
*/
function
get
_i
d
()
{
function
get
I
d
()
{
return
$this
->
id
;
}
...
...
@@ -97,7 +97,7 @@ class Node extends Base {
*
* @return string The node's name.
*/
function
get
_n
ame
()
{
function
get
N
ame
()
{
return
$this
->
name
;
}
...
...
@@ -106,7 +106,7 @@ class Node extends Base {
*
* @return Node|null The parent node if any, NULL otherwise.
*/
function
get
_p
arent
()
{
function
get
P
arent
()
{
return
$this
->
parent_node
;
}
...
...
@@ -115,7 +115,7 @@ class Node extends Base {
*
* @return array A list of child nodes.
*/
function
get
_c
hildren
()
{
function
get
C
hildren
()
{
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
_i
d
()
==
$this
->
id
;
return
$node
->
get
I
d
()
==
$this
->
id
;
}
/**
...
...
@@ -136,7 +136,7 @@ class Node extends Base {
*
* @return bool Whether this node is the root node.
*/
function
is
_r
oot
()
{
function
is
R
oot
()
{
return
$this
->
parent_node
===
null
;
}
...
...
@@ -147,7 +147,7 @@ class Node extends Base {
*
* @return bool Whether this node is a leaf node.
*/
function
is
_l
eaf
()
{
function
is
L
eaf
()
{
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
_c
hild
(
Node
&
$node
,
$set_parent
=
true
)
{
function
add
C
hild
(
Node
&
$node
,
$set_parent
=
true
)
{
$this
->
children
[]
=
$node
;
$set_parent
&&
$node
->
set
_p
arent
(
$this
);
$set_parent
&&
$node
->
set
P
arent
(
$this
);
}
/**
...
...
@@ -172,7 +172,7 @@ class Node extends Base {
*/
function
add
(
$name
,
array
$data
=
array
())
{
$node
=
new
self
(
$name
,
$this
);
$this
->
add
_c
hild
(
$node
,
false
);
$this
->
add
C
hild
(
$node
,
false
);
return
$node
->
set
(
$data
);
}
...
...
@@ -182,7 +182,7 @@ class Node extends Base {
*
* @param Node &$child The node to remove.
*/
function
remove
_c
hild
(
Node
&
$child
)
{
function
remove
C
hild
(
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
_r
oot
())
if
(
$this
->
is
R
oot
())
throw
new
\RuntimeException
(
'Cannot remove the root node of a tree.'
);
$this
->
parent_node
->
remove
_c
hild
(
$this
);
$this
->
parent_node
->
remove
C
hild
(
$this
);
foreach
(
$this
->
children
as
$child
)
$child
->
set
_p
arent
(
null
);
$child
->
set
P
arent
(
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
_p
arent
(
$parent
)
{
function
set
P
arent
(
$parent
)
{
if
(
$this
->
parent_node
!==
null
)
$this
->
parent_node
->
remove
_c
hild
(
$this
);
$this
->
parent_node
->
remove
C
hild
(
$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
_n
ame
()
==
$name
;
return
$child
->
get
N
ame
()
==
$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
_c
hild
(
$child_copy
);
$copy
->
add
C
hild
(
$child_copy
);
}
else
{
$copy
->
add
_c
hild
(
$child
,
false
);
$copy
->
add
C
hild
(
$child
,
false
);
}
}
...
...
router.php
View file @
3566402f
...
...
@@ -28,8 +28,8 @@ require_once 'base.php';
* '/home' => 'home',
* '/contact' => 'contact'
* ));
* $response = $router->call
_h
andler('/home'); // 'This is the home page.'
* $response = $router->call
_h
andler('/contact'); // 'This is the contact page.'
* $response = $router->call
H
andler('/home'); // 'This is the home page.'
* $response = $router->call
H
andler('/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
_h
andler('/home'); // 'This is the home page.'
* $response = $router->call
_h
andler('/contact'); // 'This is the contact page.'
* $response = $router->call
H
andler('/home'); // 'This is the home page.'
* $response = $router->call
H
andler('/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
_r
oute
(
$pattern
,
$handler
);
$this
->
add
R
oute
(
$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
_r
oute
(
$pattern
,
$handler
)
{
function
add
R
oute
(
$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
_h
andler
(
$url
)
{
function
call
H
andler
(
$url
)
{
foreach
(
$this
->
routes
as
$pattern
=>
$handler
)
{
if
(
preg_match
(
$pattern
,
$url
,
$matches
))
{
array_shift
(
$matches
);
...
...
template.php
View file @
3566402f
This diff is collapsed.
Click to expand it.
tests/test_autoloader.php
View file @
3566402f
...
...
@@ -10,139 +10,139 @@ class AutoloaderTest extends PHPUnit_Framework_TestCase {
$this
->
autoloader
=
new
Autoloader
(
PATH
);
}
function
test
_set_root_n
amespace
()
{
function
test
SetRootN
amespace
()
{
$this
->
assertAttributeEquals
(
'\\'
,
'root_namespace'
,
$this
->
autoloader
);
$this
->
autoloader
->
set
_root_n
amespace
(
'Foo'
);
$this
->
autoloader
->
set
RootN
amespace
(
'Foo'
);
$this
->
assertAttributeEquals
(
'Foo\\'
,
'root_namespace'
,
$this
->
autoloader
);
$this
->
autoloader
->
set
_root_n
amespace
(
'Foo\\'
);
$this
->
autoloader
->
set
RootN
amespace
(
'Foo\\'
);
$this
->
assertAttributeEquals
(
'Foo\\'
,
'root_namespace'
,
$this
->
autoloader
);
}
/**
* @depends test
_set_root_n
amespace
* @depends test
SetRootN
amespace
*/
function
test
_get_root_n
amespace
()
{
$this
->
autoloader
->
set
_root_n
amespace
(
'Foo'
);
$this
->
assertEquals
(
$this
->
autoloader
->
get
_root_n
amespace
(),
'Foo\\'
);
function
test
GetRootN
amespace
()
{
$this
->
autoloader
->
set
RootN
amespace
(
'Foo'
);
$this
->
assertEquals
(
$this
->
autoloader
->
get
RootN
amespace
(),
'Foo\\'
);
}
/**
* @depends test
_set_root_n
amespace
* @depends test
SetRootN
amespace
*/
function
test
_construct_root_n
amespace
()
{
function
test
ConstructRootN
amespace
()
{
$autoloader
=
new
Autoloader
(
PATH
,
'Foo'
);
$this
->
assertAttributeEquals
(
'Foo\\'
,
'root_namespace'
,
$autoloader
);
}
/**
* @depends test
_set_root_n
amespace
* @depends test
SetRootN
amespace
*/
function
test
_strip_root_n
amespace
()
{
$strip
=
new
ReflectionMethod
(
'webbasics\Autoloader'
,
'strip
_root_n
amespace'
);
function
test
StripRootN
amespace
()
{
$strip
=
new
ReflectionMethod
(
'webbasics\Autoloader'
,
'strip
RootN
amespace'
);
$strip
->
setAccessible
(
true
);
$this
->
autoloader
->
set
_root_n
amespace
(
'Foo'
);
$this
->
autoloader
->
set
RootN
amespace
(
'Foo'
);
$this
->
assertEquals
(
$strip
->
invoke
(
$this
->
autoloader
,
'Foo\Bar'
),
'Bar'
);
}
function
test
_set_root_d
irectory
()
{
$this
->
autoloader
->
set
_root_d
irectory
(
'tests'
);
$this
->
assertEquals
(
$this
->
autoloader
->
get
_root_d
irectory
(),
'tests/'
);
function
test
SetRootD
irectory
()
{
$this
->
autoloader
->
set
RootD
irectory
(
'tests'
);
$this
->
assertEquals
(
$this
->
autoloader
->
get
RootD
irectory
(),
'tests/'
);
}
function
test
_classname_to_f
ilename
()
{
$this
->
assertEquals
(
Autoloader
::
classname
_to_f
ilename
(
'Foo'
),
'foo'
);
$this
->
assertEquals
(
Autoloader
::
classname
_to_f
ilename
(
'FooBar'
),
'foo_bar'
);
$this
->
assertEquals
(
Autoloader
::
classname
_to_f
ilename
(
'fooBar'
),
'foo_bar'
);
$this
->
assertEquals
(
Autoloader
::
classname
_to_f
ilename
(
'FooBarBaz'
),
'foo_bar_baz'
);
function
test
ClassnameToF
ilename
()
{
$this
->
assertEquals
(
Autoloader
::
classname
ToF
ilename
(
'Foo'
),
'foo'
);
$this
->
assertEquals
(
Autoloader
::
classname
ToF
ilename
(
'FooBar'
),
'foo_bar'
);
$this
->
assertEquals
(
Autoloader
::
classname
ToF
ilename
(
'fooBar'
),
'foo_bar'
);
$this
->
assertEquals
(
Autoloader
::
classname
ToF
ilename
(
'FooBarBaz'
),
'foo_bar_baz'
);
}
/**
* @depends test
_classname_to_f
ilename
* @depends test
ClassnameToF
ilename
*/
function
test
_create_p
ath
()
{
$this
->
assertEquals
(
$this
->
autoloader
->
create
_p
ath
(
'Foo'
),
PATH
.
'foo.php'
);
$this
->
assertEquals
(
$this
->
autoloader
->
create
_p
ath
(
'\Foo'
),
PATH
.
'foo.php'
);
$this
->
assertEquals
(
$this
->
autoloader
->
create
_p
ath
(
'Foo\Bar'
),
PATH
.
'foo/bar.php'
);
$this
->
assertEquals
(
$this
->
autoloader
->
create
_p
ath
(
'Foo\Bar\Baz'
),
PATH
.
'foo/bar/baz.php'
);
$this
->
assertEquals
(
$this
->
autoloader
->
create
_p
ath
(
'FooBar\Baz'
),
PATH
.
'foo_bar/baz.php'
);
function
test
CreateP
ath
()
{
$this
->
assertEquals
(
$this
->
autoloader
->
create
P
ath
(
'Foo'
),
PATH
.
'foo.php'
);
$this
->
assertEquals
(
$this
->
autoloader
->
create
P
ath
(
'\Foo'
),
PATH
.
'foo.php'
);
$this
->
assertEquals
(
$this
->
autoloader
->
create
P
ath
(
'Foo\Bar'
),
PATH
.
'foo/bar.php'
);
$this
->
assertEquals
(
$this
->
autoloader
->
create
P
ath
(
'Foo\Bar\Baz'
),
PATH
.
'foo/bar/baz.php'
);
$this
->
assertEquals
(
$this
->
autoloader
->
create
P
ath
(
'FooBar\Baz'
),
PATH
.
'foo_bar/baz.php'
);
}
function
test
_throw_e
rrors
()
{
$this
->
assertFalse
(
$this
->
autoloader
->
get
_throw_e
rrors
());
$this
->
autoloader
->
set
_throw_e
rrors
(
true
);
$this
->
assertTrue
(
$this
->
autoloader
->
get
_throw_e
rrors
());
function
test
ThrowE
rrors
()
{
$this
->
assertFalse
(
$this
->
autoloader
->
get
ThrowE
rrors
());
$this
->
autoloader
->
set
ThrowE
rrors
(
true
);
$this
->
assertTrue
(
$this
->
autoloader
->
get
ThrowE
rrors
());
}
/**
* @depends test
_create_p
ath
* @depends test
_throw_e
rrors
* @depends test
CreateP
ath
* @depends test
ThrowE
rrors
*/
function
test
_load_class_not_f
ound
()
{
$this
->
assertFalse
(
$this
->
autoloader
->
load
_c
lass
(
'foobar'
));
function
test
LoadClassNotF
ound
()
{
$this
->
assertFalse
(
$this
->
autoloader
->
load
C
lass
(
'foobar'
));
}
/**
* @depends test
_load_class_not_f
ound
* @depends test
LoadClassNotF
ound
* @expectedException webbasics\FileNotFoundError
* @expectedExceptionMessage File "tests/_files/foobar.php" does not exist.
*/
function
test
_load_class_not_found_e
rror
()
{
$this
->
autoloader
->
set
_throw_e
rrors
(
true
);
$this
->
autoloader
->
load
_c
lass
(
'foobar'
);
function
test
LoadClassNotFoundE
rror
()
{
$this
->
autoloader
->
set
ThrowE
rrors
(
true
);
$this
->
autoloader
->
load
C
lass
(
'foobar'
);
}
/**
* @depends test
_load_class_not_f
ound
* @depends test
LoadClassNotF
ound
* @expectedException webbasics\FileNotFoundError
* @expectedExceptionMessage File "tests/_files/foobar.php" does not exist.
*/
function
test
_load_class_not_found_noerror_o
verwrite
()
{
$this
->
autoloader
->
load
_c
lass
(
'foobar'
,
true
);
function
test
LoadClassNotFoundNoerrorO
verwrite
()
{
$this
->
autoloader
->
load
C
lass
(
'foobar'
,
true
);
}
/**
* @depends test
_load_class_not_f
ound
* @depends test
LoadClassNotF
ound
*/
function
test
_load_class_not_found_error_o
verwrite
()
{
$this
->
autoloader
->
set
_throw_e
rrors
(
true
);
$this
->
assertFalse
(
$this
->
autoloader
->
load
_c
lass
(
'foobar'
,
false
));
function
test
LoadClassNotFoundErrorO
verwrite
()
{
$this
->
autoloader
->
set
ThrowE
rrors
(
true
);
$this
->
assertFalse
(
$this
->
autoloader
->
load
C
lass
(
'foobar'
,
false
));
}
/**
* @depends test
_load_class_not_f
ound
* @depends test
LoadClassNotF
ound
*/
function
test
_load_c
lass
()
{
$this
->
assertTrue
(
$this
->
autoloader
->
load
_c
lass
(
'Foo'
));
function
test
LoadC
lass
()
{
$this
->
assertTrue
(
$this
->
autoloader
->
load
C
lass
(
'Foo'
));
$this
->
assertTrue
(
class_exists
(
'Foo'
,
false
));
$this
->
assertTrue
(
$this
->
autoloader
->
load
_c
lass
(
'Foo\Bar'
));
$this
->
assertTrue
(
$this
->
autoloader
->
load
C
lass
(
'Foo\Bar'
));
$this
->
assertTrue
(
class_exists
(
'Foo\Bar'
,
false
));
}
/**
* @depends test
_load_c
lass
* @depends test
_strip_root_n
amespace
* @depends test
LoadC
lass
* @depends test
StripRootN
amespace
*/
function
test
_load_class_root_n
amespace
()
{
function
test
LoadClassRootN
amespace
()
{
$autoloader
=
new
Autoloader
(
PATH
.
'foo'
);
$autoloader
->
set
_root_n
amespace
(
'Foo'
);
$this
->
assertTrue
(
$autoloader
->
load
_c
lass
(
'Bar'
));
$autoloader
->
set
RootN
amespace
(
'Foo'
);
$this
->
assertTrue
(
$autoloader
->
load
C
lass
(
'Bar'
));
$this
->
assertTrue
(
class_exists
(
'Foo\Bar'
,
false
));
}
/**
* @depends test
_load_c
lass
* @depends test
LoadC
lass
*/
function
test
_r
egister
()
{
function
test
R
egister
()
{
$this
->
autoloader
->
register
();
$this
->
assertTrue
(
class_exists
(
'Baz'
));
}
/**
* @depends test
_r
egister
* @depends test
_throw_e
rrors
* @depends test
R
egister
* @depends test
ThrowE
rrors
*/
function
test
_register_p
repend
()
{
function
test
RegisterP
repend
()
{
$second_loader
=
new
Autoloader
(
PATH
.
'second'
);
$this
->
autoloader
->
register
();
$second_loader
->
register
(
true
);
// Prepend so that the second loader attemps to load Bar first
...
...
tests/test_base.php
View file @
3566402f
...
...
@@ -11,11 +11,11 @@ class BaseExtension extends Base {
}
class
BaseTest
extends
PHPUnit_Framework_TestCase
{
function
test
_c
reate
()
{
function
test
C
reate
()
{
$this
->
assertEquals
(
BaseExtension
::
create
(
'a'
,
'b'
),
new
BaseExtension
(
'a'
,
'b'
));
}
function
test
_a
sprintf
()
{
function
test
A
sprintf
()
{
$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_s
lash
()
{
$this
->
assertEquals
(
Base
::
path
_with_s
lash
(
'dirname'
),
'dirname/'
);
$this
->
assertEquals
(
Base
::
path
_with_s
lash
(
'dirname/'
),
'dirname/'
);
function
test
PathWithS
lash
()
{
$this
->
assertEquals
(
Base
::
path
WithS
lash
(
'dirname'
),
'dirname/'
);
$this
->
assertEquals
(
Base
::
path
WithS
lash
(
'dirname/'
),
'dirname/'
);
}
}
...
...
tests/test_collection.php
View file @
3566402f
...
...
@@ -11,11 +11,11 @@ class IdObject {
$this
->
foo
=
$foo
;
}
function
get
_i
d
()
{
function
get
I
d
()
{
return
$this
->
id
;
}
static
function
clear
_c
ounter
()
{
static
function
clear
C
ounter
()
{
self
::
$count
=
0
;
}
}
...
...
@@ -39,7 +39,7 @@ class CollectionTest extends PHPUnit_Framework_TestCase {
$this
->
set
=
set
(
array
(
1
,
2
));
}
function
test
_a
dd
()
{
function
test
A
dd
()
{
$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_e
rror
()
{
function
test
InsertE
rror
()
{
set
(
array
(
'foo'
=>
1
))
->
insert
(
2
,
'foo'
);
}
function
test
_insert_s
uccess
()
{
function
test
InsertS
uccess
()
{
$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
_a
ll
()
{
function
test
A
ll
()
{
$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_e
mpty
()
{
function
test
LastE
mpty
()
{
set
()
->
last
();
}
function
test
_l
ast
()
{
function
test
L
ast
()
{
$this
->
assertEquals
(
$this
->
set
->
last
(),
2
);
}
/**
* @expectedException OutOfBoundsException
*/
function
test
_first_e
mpty
()
{
function
test
FirstE
mpty
()
{
set
()
->
first
();
}
function
test
_f
irst
()
{
function
test
F
irst
()
{
$this
->
assertEquals
(
$this
->
set
->
first
(),
1
);
}
function
test
_c
ount
()
{
function
test
C
ount
()
{
$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_e
xists
()
{
$this
->
assertTrue
(
$this
->
set
->
index
_e
xists
(
1
));
$this
->
assertTrue
(
set
(
array
(
'foo'
=>
'bar'
))
->
index
_e
xists
(
'foo'
));
function
test
IndexE
xists
()
{
$this
->
assertTrue
(
$this
->
set
->
index
E
xists
(
1
));
$this
->
assertTrue
(
set
(
array
(
'foo'
=>
'bar'
))
->
index
E
xists
(
'foo'
));
}
function
test
_g
et
()
{
function
test
G
et
()
{
$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_i
ndex
()
{
$this
->
set
->
delete
_i
ndex
(
0
);
function
test
DeleteI
ndex
()
{
$this
->
set
->
delete
I
ndex
(
0
);
$this
->
assertEquals
(
$this
->
set
,
set
(
array
(
1
=>
2
)));
}
function
test
_d
elete
()
{
function
test
D
elete
()
{
$this
->
set
->
delete
(
1
);
$this
->
assertEquals
(
$this
->
set
,
set
(
array
(
1
=>
2
)));
}
function
assert
_set_e
quals
(
array
$expected_items
,
$set
)
{
function
assert
SetE
quals
(
array
$expected_items
,
$set
)
{
$this
->
assertAttributeEquals
(
$expected_items
,
'items'
,
$set
);
}
function
test
_u
niques
()
{
$this
->
assert
_set_e
quals
(
array
(
1
,
2
),
set
(
array
(
1
,
2
,
2
))
->
uniques
());
$this
->
assert
_set_e
quals
(
array
(
2
,
1
),
set
(
array
(
2
,
1
,
2
))
->
uniques
());
$this
->
assert
_set_e
quals
(
array
(
2
,
1
),
set
(
array
(
2
,
2
,
1
))
->
uniques
());
function
test
U
niques
()
{
$this
->
assert
SetE
quals
(
array
(
1
,
2
),
set
(
array
(
1
,
2
,
2
))
->
uniques
());
$this
->
assert
SetE
quals
(
array
(
2
,
1
),
set
(
array
(
2
,
1
,
2
))
->
uniques
());
$this
->
assert
SetE
quals
(
array
(
2
,
1
),
set
(
array
(
2
,
2
,
1
))
->
uniques
());
}
function
set
_i
tems
(
$collection
,
$items
,
$clone
)
{
$rm
=
new
ReflectionMethod
(
$collection
,
'set
_i
tems'
);
function
set
I
tems
(
$collection
,
$items
,
$clone
)
{
$rm
=
new
ReflectionMethod
(
$collection
,
'set
I
tems'
);
$rm
->
setAccessible
(
true
);
return
$rm
->
invoke
(
$collection
,
$items
,
$clone
);
}
function
test
_set_items_c
lone
()
{
$result
=
$this
->
set
_i
tems
(
$this
->
set
,
array
(
3
,
4
),
true
);
$this
->
assert
_set_e
quals
(
array
(
1
,
2
),
$this
->
set
);
$this
->
assert
_set_e
quals
(
array
(
3
,
4
),
$result
);
function
test
SetItemsC
lone
()
{
$result
=
$this
->
set
I
tems
(
$this
->
set
,
array
(
3
,
4
),
true
);
$this
->
assert
SetE
quals
(
array
(
1
,
2
),
$this
->
set
);
$this
->
assert
SetE
quals
(
array
(
3
,
4
),
$result
);
$this
->
assertNotSame
(
$this
->
set
,
$result
);
}
function
test
_set_items_no_c
lone
()
{
$result
=
$this
->
set
_i
tems
(
$this
->
set
,
array
(
3
,
4
),
false
);
function
test
SetItemsNoC
lone
()
{
$result
=
$this
->
set
I
tems
(
$this
->
set
,
array
(
3
,
4
),
false
);
$this
->
assertSame
(
$this
->
set
,
$result
);
}
/**
* @depends test
_set_items_c
lone
* @depends test
SetItemsC
lone
*/
function
test
_f
ilter
()
{
function
test
F
ilter
()
{
$smaller_than_five
=
function
(
$number
)
{
return
$number
<
5
;
};
$this
->
assert
_set_e
quals
(
array
(
2
,
4
,
1
,
4
),
set
(
array
(
2
,
7
,
4
,
7
,
1
,
8
,
4
,
5
))
->
filter
(
$smaller_than_five
));
$this
->
assert
SetE
quals
(
array
(
2
,
4
,
1
,
4
),
set
(
array
(
2
,
7
,
4
,
7
,
1
,
8
,
4
,
5
))
->
filter
(
$smaller_than_five
));
}
/**
* @depends test
_f
ilter
* @depends test
F
ilter
*/
function
test
_find_s
uccess
()
{
function
test
FindS
uccess
()
{
$items
=
array
(
array
(
'foo'
=>
'bar'
,
'bar'
=>
'baz'
),
array
(
'foo'
=>
'baz'
,
'bar'
=>
'foo'
),
std_object
(
array
(
'foo'
=>
'bar'
,
'baz'
=>
'bar'
)),
);
$this
->
assert
_set_e
quals
(
array
(
$items
[
1
]),
set
(
$items
)
->
find
(
array
(
'foo'
=>
'baz'
)));
$this
->
assert
_set_e
quals
(
array
(
$items
[
0
],
$items
[
2
]),
set
(
$items
)
->
find
(
array
(
'foo'
=>
'bar'
)));
$this
->
assert
SetE
quals
(
array
(
$items
[
1
]),
set
(
$items
)
->
find
(
array
(
'foo'
=>
'baz'
)));
$this
->
assert
SetE
quals
(
array
(
$items
[
0
],
$items
[
2
]),
set
(
$items
)
->
find
(
array
(
'foo'
=>
'bar'
)));
}
/**
* @depends test
_find_s
uccess
* @depends test
FindS
uccess
* @expectedException \UnexpectedValueException
* @expectedExceptionMessage Collection::find encountered a non-object and non-array item "foobar".
*/
function
test
_find_f
ailure
()
{
function
test
FindF
ailure
()
{
$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_s
imple
()
{
IdObject
::
clear
_c
ounter
();
function
test
GetAttributeS
imple
()
{
IdObject
::
clear
C
ounter
();
$set
=
set
(
array
(
new
IdObject
(),
new
IdObject
(),
new
IdObject
()));
$this
->
assertEquals
(
array
(
1
,
2
,
3
),
$set
->
get
_a
ttribute
(
'id'
));
$this
->
assertEquals
(
array
(
1
,
2
,
3
),
$set
->
get
A
ttribute
(
'id'
));
}
/**
* @depends test
_get_attribute_s
imple
* @depends test
GetAttributeS
imple
*/
function
test
_get_attribute_i
ndices
()
{
IdObject
::
clear
_c
ounter
();
function
test
GetAttributeI
ndices
()
{
IdObject
::
clear
C
ounter
();
$set
=
set
(
array
(
'foo'
=>
new
IdObject
(),
'bar'
=>
new
IdObject
(),
'baz'
=>
new
IdObject
()));
$this
->
assertEquals
(
array
(
'foo'
=>
1
,
'bar'
=>
2
,
'baz'
=>
3
),
$set
->
get
_a
ttribute
(
'id'
));
$this
->
assertEquals
(
array
(
'foo'
=>
1
,
'bar'
=>
2
,
'baz'
=>
3
),
$set
->
get
A
ttribute
(
'id'
));
}
/**
* @depends test
_a
ll
* @depends test
_set_items_c
lone
* @depends test
A
ll
* @depends test
SetItemsC
lone
*/
function
test
_index_b
y
()
{
IdObject
::
clear
_c
ounter
();
function
test
IndexB
y
()
{
IdObject
::
clear
C
ounter
();
$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_b
y
(
'foo'
));
$this
->
assert
SetEquals
(
array
(
'foo'
=>
$foo
,
'bar'
=>
$bar
,
'baz'
=>
$baz
),
$set
->
indexB
y
(
'foo'
));
}
/**
* @depends test
_set_items_c
lone
* @depends test
SetItemsC
lone
*/
function
test
_m
ap
()
{
function
test
M
ap
()
{
$plus_five
=
function
(
$number
)
{
return
$number
+
5
;
};
$this
->
assert
_set_e
quals
(
array
(
6
,
7
,
8
),
set
(
array
(
1
,
2
,
3
))
->
map
(
$plus_five
));
$this
->
assert
SetE
quals
(
array
(
6
,
7
,
8
),
set
(
array
(
1
,
2
,
3
))
->
map
(
$plus_five
));
}
/**
* @depends test
_set_items_c
lone
* @depends test
SetItemsC
lone
*/
function
test
_map_m
ethod
()
{
IdObject
::
clear
_c
ounter
();
function
test
MapM
ethod
()
{
IdObject
::
clear
C
ounter
();
$set
=
set
(
array
(
new
IdObject
(),
new
IdObject
(),
new
IdObject
()));
$this
->
assert
_set_equals
(
array
(
1
,
2
,
3
),
$set
->
map_method
(
'get_i
d'
));
$this
->
assert
SetEquals
(
array
(
1
,
2
,
3
),
$set
->
mapMethod
(
'getI
d'
));
}
}
...
...
tests/test_logger.php
View file @
3566402f
...
...
@@ -11,138 +11,138 @@ define('LOGFILE', 'build/temp.log');
class
LoggerTest
extends
PHPUnit_Extensions_OutputTestCase
{
function
setUp
()
{
$this
->
logger
=
new
Logger
();
$this
->
logger
->
set
_p
roperty
(
'name'
,
NAME
);
$this
->
logger
->
set
_f
ormat
(
FORMAT
);
$this
->
logger
->
set
P
roperty
(
'name'
,
NAME
);
$this
->
logger
->
set
F
ormat
(
FORMAT
);
is_dir
(
'build'
)
||
mkdir
(
'build'
);
}
function
assert
_d
umps
(
$expected
)
{
function
assert
D
umps
(
$expected
)
{
$this
->
assertEquals
(
$this
->
logger
->
dumps
(),
$expected
);
}
function
test
_set_d
irectory
()
{
$this
->
logger
->
set
_d
irectory
(
'logs'
);
function
test
SetD
irectory
()
{
$this
->
logger
->
set
D
irectory
(
'logs'
);
$this
->
assertAttributeEquals
(
'logs/'
,
'log_directory'
,
$this
->
logger
);
$this
->
logger
->
set
_d
irectory
(
'logs/'
);
$this
->
logger
->
set
D
irectory
(
'logs/'
);
$this
->
assertAttributeEquals
(
'logs/'
,
'log_directory'
,
$this
->
logger
);
}
function
test
_set_f
ormat
()
{
$this
->
logger
->
set
_f
ormat
(
'foo'
);
function
test
SetF
ormat
()
{
$this
->
logger
->
set
F
ormat
(
'foo'
);
$this
->
assertAttributeEquals
(
'foo'
,
'format'
,
$this
->
logger
);
}
function
test
_set_dump_format_s
uccess
()
{
$this
->
logger
->
set
_dump_f
ormat
(
'html'
);
function
test
SetDumpFormatS
uccess
()
{
$this
->
logger
->
set
DumpF
ormat
(
'html'
);
$this
->
assertAttributeEquals
(
'html'
,
'dump_format'
,
$this
->
logger
);
}
/**
* @expectedException InvalidArgumentException
*/
function
test
_set_dump_format_f
ailure
()
{
$this
->
logger
->
set
_dump_f
ormat
(
'foo'
);
function
test
SetDumpFormatF
ailure
()
{
$this
->
logger
->
set
DumpF
ormat
(
'foo'
);
}
function
test
_get_f
ormat
()
{
$this
->
assertEquals
(
$this
->
logger
->
get
_f
ormat
(),
FORMAT
);
function
test
GetF
ormat
()
{
$this
->
assertEquals
(
$this
->
logger
->
get
F
ormat
(),
FORMAT
);
}
function
test
_get_l
evel
()
{
$this
->
assertEquals
(
$this
->
logger
->
get
_l
evel
(),
Logger
::
WARNING
);
$this
->
assertEquals
(
$this
->
logger
->
get
_level_n
ame
(),
'WARNING'
);
function
test
GetL
evel
()
{
$this
->
assertEquals
(
$this
->
logger
->
get
L
evel
(),
Logger
::
WARNING
);
$this
->
assertEquals
(
$this
->
logger
->
get
LevelN
ame
(),
'WARNING'
);
}
/**
* @depends test
_get_l
evel
* @depends test
GetL
evel
*/
function
test
_set_l
evel
()
{
$this
->
logger
->
set
_l
evel
(
'info'
);
$this
->
assertEquals
(
$this
->
logger
->
get
_l
evel
(),
Logger
::
INFO
);
$this
->
logger
->
set
_l
evel
(
'DEBUG'
);
$this
->
assertEquals
(
$this
->
logger
->
get
_l
evel
(),
Logger
::
DEBUG
);
$this
->
logger
->
set
_l
evel
(
'WaRnInG'
);
$this
->
assertEquals
(
$this
->
logger
->
get
_l
evel
(),
Logger
::
WARNING
);
$this
->
logger
->
set
_l
evel
(
Logger
::
ERROR
);
$this
->
assertEquals
(
$this
->
logger
->
get
_l
evel
(),
Logger
::
ERROR
);
}
function
test
_f
ormat
()
{
function
test
SetL
evel
()
{
$this
->
logger
->
set
L
evel
(
'info'
);
$this
->
assertEquals
(
$this
->
logger
->
get
L
evel
(),
Logger
::
INFO
);
$this
->
logger
->
set
L
evel
(
'DEBUG'
);
$this
->
assertEquals
(
$this
->
logger
->
get
L
evel
(),
Logger
::
DEBUG
);
$this
->
logger
->
set
L
evel
(
'WaRnInG'
);
$this
->
assertEquals
(
$this
->
logger
->
get
L
evel
(),
Logger
::
WARNING
);
$this
->
logger
->
set
L
evel
(
Logger
::
ERROR
);
$this
->
assertEquals
(
$this
->
logger
->
get
L
evel
(),
Logger
::
ERROR
);
}
function
test
F
ormat
()
{
$this
->
logger
->
error
(
'test message'
);
$this
->
assert
_d
umps
(
'ERROR: test message'
);
$this
->
assert
D
umps
(
'ERROR: test message'
);
}
function
test
_set_p
roperty
()
{
$this
->
logger
->
set
_p
roperty
(
'name'
,
'Logger'
);
$this
->
assertEquals
(
$this
->
logger
->
get
_formatted_p
roperty
(
'name'
),
'Logger'
);
function
test
SetP
roperty
()
{
$this
->
logger
->
set
P
roperty
(
'name'
,
'Logger'
);
$this
->
assertEquals
(
$this
->
logger
->
get
FormattedP
roperty
(
'name'
),
'Logger'
);
}
/**
* @depends test
_f
ormat
* @depends test
F
ormat
*/
function
test
_c
lear
()
{
function
test
C
lear
()
{
$this
->
logger
->
warning
(
'test message'
);
$this
->
logger
->
clear
();
$this
->
assert
_d
umps
(
''
);
$this
->
assert
D
umps
(
''
);
}
/**
* @depends test
_set_l
evel
* @depends test
_c
lear
* @depends test
SetL
evel
* @depends test
C
lear
*/
function
test
_process_l
evel
()
{
function
test
ProcessL
evel
()
{
$this
->
logger
->
info
(
'test message'
);
$this
->
assert
_d
umps
(
''
);
$this
->
assert
D
umps
(
''
);
$this
->
logger
->
warning
(
'test message'
);
$this
->
assert
_d
umps
(
'WARNING: test message'
);
$this
->
assert
D
umps
(
'WARNING: test message'
);
$this
->
logger
->
critical
(
'test message'
);
$this
->
assert
_d
umps
(
"WARNING: test message
\n
CRITICAL: test message"
);
$this
->
assert
D
umps
(
"WARNING: test message
\n
CRITICAL: test message"
);
$this
->
logger
->
clear
();
$this
->
logger
->
set
_l
evel
(
'debug'
);
$this
->
logger
->
set
L
evel
(
'debug'
);
$this
->
logger
->
debug
(
'test message'
);
$this
->
assert
_d
umps
(
'DEBUG: test message'
);
$this
->
assert
D
umps
(
'DEBUG: test message'
);
}
function
test
_get_formatted_p
roperty
()
{
$this
->
assertEquals
(
$this
->
logger
->
get
_formatted_p
roperty
(
'name'
),
NAME
);
$this
->
assertEquals
(
$this
->
logger
->
get
_formatted_p
roperty
(
'loglevel'
),
'WARNING'
);
function
test
GetFormattedP
roperty
()
{
$this
->
assertEquals
(
$this
->
logger
->
get
FormattedP
roperty
(
'name'
),
NAME
);
$this
->
assertEquals
(
$this
->
logger
->
get
FormattedP
roperty
(
'loglevel'
),
'WARNING'
);
$this
->
assertRegExp
(
'/^\d{2}-\d{2}-\d{4}$/'
,
$this
->
logger
->
get
_formatted_p
roperty
(
'date'
));
$this
->
logger
->
get
FormattedP
roperty
(
'date'
));
$this
->
assertRegExp
(
'/^\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2}$/'
,
$this
->
logger
->
get
_formatted_p
roperty
(
'datetime'
));
$this
->
logger
->
get
FormattedP
roperty
(
'datetime'
));
$this
->
assertRegExp
(
'/^\d{2}:\d{2}:\d{2}$/'
,
$this
->
logger
->
get
_formatted_p
roperty
(
'time'
));
$this
->
logger
->
get
FormattedP
roperty
(
'time'
));
$this
->
setExpectedException
(
'\InvalidArgumentException'
);
$this
->
logger
->
get
_formatted_p
roperty
(
'foo'
);
$this
->
logger
->
get
FormattedP
roperty
(
'foo'
);
}
function
test
_dumps_property_f
ormat
()
{
function
test
DumpsPropertyF
ormat
()
{
$this
->
logger
->
warning
(
'test message'
);
$this
->
logger
->
set
_f
ormat
(
'%(name): %(level): %(message)'
);
$this
->
assert
_d
umps
(
NAME
.
': WARNING: test message'
);
$this
->
logger
->
set
F
ormat
(
'%(name): %(level): %(message)'
);
$this
->
assert
D
umps
(
NAME
.
': WARNING: test message'
);
}
/**
* @depends test
_process_l
evel
* @depends test
ProcessL
evel
*/
function
test
_dump_p
lain
()
{
function
test
DumpP
lain
()
{
$this
->
logger
->
warning
(
'test message'
);
$this
->
expectOutputString
(
'WARNING: test message'
);
$this
->
logger
->
dump
();
}
/**
* @depends test
_process_l
evel
* @depends test
ProcessL
evel
*/
function
test
_dump_h
tml
()
{
function
test
DumpH
tml
()
{
$this
->
logger
->
warning
(
'test message'
);
$this
->
logger
->
set
_dump_f
ormat
(
'html'
);
$this
->
logger
->
set
DumpF
ormat
(
'html'
);
$this
->
expectOutputString
(
'<strong>Log:</strong><br /><pre>WARNING: test message</pre>'
);
$this
->
logger
->
dump
();
}
function
test
_s
ave
()
{
function
test
S
ave
()
{
$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
_l
ogfile
()
{
function
find
L
ogfile
()
{
$files
=
scandir
(
LOGDIR
);
$this
->
assertEquals
(
3
,
count
(
$files
));
return
$files
[
2
];
}
/**
* @depends test
_s
ave
* @depends test
S
ave
*/
function
test
_dump_file_r
egular
()
{
$this
->
logger
->
set
_d
irectory
(
LOGDIR
);
$this
->
logger
->
set
_dump_f
ormat
(
'file'
);
function
test
DumpFileR
egular
()
{
$this
->
logger
->
set
D
irectory
(
LOGDIR
);
$this
->
logger
->
set
DumpF
ormat
(
'file'
);
$this
->
logger
->
warning
(
'test message'
);
$this
->
logger
->
dump
();
$filename
=
$this
->
find
_l
ogfile
();
$filename
=
$this
->
find
L
ogfile
();
$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_e
xception
()
{
$this
->
logger
->
set
_dump_f
ormat
(
'none'
);
$this
->
logger
->
handle
_e
xception
(
new
RuntimeException
(
'test message'
));
function
test
HandleE
xception
()
{
$this
->
logger
->
set
DumpF
ormat
(
'none'
);
$this
->
logger
->
handle
E
xception
(
new
RuntimeException
(
'test message'
));
$this
->
assertNotEquals
(
$this
->
logger
->
dumps
(),
''
);
}
}
...
...
tests/test_node.php
View file @
3566402f
...
...
@@ -10,90 +10,90 @@ class NodeTest extends PHPUnit_Framework_TestCase {
$this
->
root
=
new
Node
(
'test node'
);
}
function
test
_get_i
d
()
{
$this
->
assertEquals
(
$this
->
root
->
get
_i
d
(),
1
);
$this
->
assertEquals
(
Node
::
create
(
''
)
->
get
_i
d
(),
2
);
function
test
GetI
d
()
{
$this
->
assertEquals
(
$this
->
root
->
get
I
d
(),
1
);
$this
->
assertEquals
(
Node
::
create
(
''
)
->
get
I
d
(),
2
);
}
function
test
_get_n
ame
()
{
$this
->
assertEquals
(
$this
->
root
->
get
_n
ame
(),
'test node'
);
$this
->
assertEquals
(
Node
::
create
(
'second node'
)
->
get
_n
ame
(),
'second node'
);
function
test
GetN
ame
()
{
$this
->
assertEquals
(
$this
->
root
->
get
N
ame
(),
'test node'
);
$this
->
assertEquals
(
Node
::
create
(
'second node'
)
->
get
N
ame
(),
'second node'
);
}
function
test
_get_p
arent
()
{
$this
->
assertNull
(
$this
->
root
->
get
_p
arent
());
$this
->
assertSame
(
Node
::
create
(
''
,
$this
->
root
)
->
get
_p
arent
(),
$this
->
root
);
function
test
GetP
arent
()
{
$this
->
assertNull
(
$this
->
root
->
get
P
arent
());
$this
->
assertSame
(
Node
::
create
(
''
,
$this
->
root
)
->
get
P
arent
(),
$this
->
root
);
}
function
test
_i
s
()
{
function
test
I
s
()
{
$mirror
=
$this
->
root
;
$this
->
assertTrue
(
$mirror
->
is
(
$this
->
root
));
$this
->
assertFalse
(
Node
::
create
(
''
)
->
is
(
$this
->
root
));
}
function
test
_is_r
oot
()
{
$this
->
assertTrue
(
$this
->
root
->
is
_r
oot
());
$this
->
assertFalse
(
Node
::
create
(
''
,
$this
->
root
)
->
is
_r
oot
());
function
test
IsR
oot
()
{
$this
->
assertTrue
(
$this
->
root
->
is
R
oot
());
$this
->
assertFalse
(
Node
::
create
(
''
,
$this
->
root
)
->
is
R
oot
());
}
function
test
_add_c
hild
()
{
function
test
AddC
hild
()
{
$node
=
new
Node
(
''
);
$this
->
root
->
add
_c
hild
(
$node
);
$this
->
root
->
add
C
hild
(
$node
);
$this
->
assertAttributeEquals
(
array
(
$node
),
'children'
,
$this
->
root
);
$this
->
assertSame
(
$node
->
get
_p
arent
(),
$this
->
root
);
$this
->
assertSame
(
$node
->
get
P
arent
(),
$this
->
root
);
}
/**
* @depends test
_add_c
hild
* @depends test
AddC
hild
*/
function
test
_get_c
hildren
()
{
$this
->
assertEquals
(
$this
->
root
->
get
_c
hildren
(),
array
());
function
test
GetC
hildren
()
{
$this
->
assertEquals
(
$this
->
root
->
get
C
hildren
(),
array
());
$node
=
new
Node
(
''
);
$this
->
root
->
add
_c
hild
(
$node
);
$this
->
assertSame
(
$this
->
root
->
get
_c
hildren
(),
array
(
$node
));
$this
->
root
->
add
C
hild
(
$node
);
$this
->
assertSame
(
$this
->
root
->
get
C
hildren
(),
array
(
$node
));
}
function
test
_add_child_no_set_p
arent
()
{
function
test
AddChildNoSetP
arent
()
{
$node
=
new
Node
(
''
);
$this
->
root
->
add
_c
hild
(
$node
,
false
);
$this
->
root
->
add
C
hild
(
$node
,
false
);
$this
->
assertAttributeEquals
(
array
(
$node
),
'children'
,
$this
->
root
);
$this
->
assertNull
(
$node
->
get
_p
arent
());
$this
->
assertNull
(
$node
->
get
P
arent
());
}
/**
* @depends test
_add_c
hild
* @depends test
AddC
hild
*/
function
test
_is_l
eaf
()
{
function
test
IsL
eaf
()
{
$node
=
new
Node
(
''
);
$this
->
root
->
add
_c
hild
(
$node
);
$this
->
assertTrue
(
$node
->
is
_l
eaf
());
$this
->
assertFalse
(
$this
->
root
->
is
_l
eaf
());
$this
->
root
->
add
C
hild
(
$node
);
$this
->
assertTrue
(
$node
->
is
L
eaf
());
$this
->
assertFalse
(
$this
->
root
->
is
L
eaf
());
}
/**
* @depends test
_add_c
hild
* @depends test
AddC
hild
*/
function
test
_a
dd
()
{
function
test
A
dd
()
{
$node
=
$this
->
root
->
add
(
'name'
,
array
(
'foo'
=>
'bar'
));
$this
->
assertEquals
(
$node
->
get
_n
ame
(),
'name'
);
$this
->
assertEquals
(
$node
->
get
N
ame
(),
'name'
);
$this
->
assertEquals
(
$node
->
get
(
'foo'
),
'bar'
);
$this
->
assertSame
(
$node
->
get
_p
arent
(),
$this
->
root
);
$this
->
assertSame
(
$node
->
get
P
arent
(),
$this
->
root
);
}
/**
* @depends test
_a
dd
* @depends test
A
dd
*/
function
test
_remove_c
hild
()
{
function
test
RemoveC
hild
()
{
$node1
=
$this
->
root
->
add
(
'name'
,
array
(
'foo'
=>
'bar'
));
$node2
=
$this
->
root
->
add
(
'name'
,
array
(
'foo'
=>
'bar'
));
$this
->
root
->
remove
_c
hild
(
$node2
);
$this
->
root
->
remove
C
hild
(
$node2
);
$this
->
assertAttributeSame
(
array
(
$node1
),
'children'
,
$this
->
root
);
}
/**
* @depends test
_remove_c
hild
* @depends test
RemoveC
hild
*/
function
test
_remove_l
eaf
()
{
function
test
RemoveL
eaf
()
{
$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_l
eaf
* @depends test
RemoveL
eaf
*/
function
test
_remove_n
ode
()
{
function
test
RemoveN
ode
()
{
$node
=
$this
->
root
->
add
(
'node'
);
$leaf
=
$node
->
add
(
'leaf'
);
$node
->
remove
();
$this
->
assertAttributeEquals
(
array
(),
'children'
,
$this
->
root
);
$this
->
assertNull
(
$leaf
->
get
_p
arent
());
$this
->
assertNull
(
$leaf
->
get
P
arent
());
}
/**
* @depends test
_remove_c
hild
* @depends test
RemoveC
hild
* @expectedException \RuntimeException
*/
function
test
_remove_r
oot
()
{
function
test
RemoveR
oot
()
{
$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_s
ingle
()
{
function
test
SetS
ingle
()
{
$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_r
eturn
()
{
function
test
SetR
eturn
()
{
$this
->
assertSame
(
$this
->
root
->
set
(
'foo'
,
'bar'
),
$this
->
root
);
}
function
test
_set_m
ultiple
()
{
function
test
SetM
ultiple
()
{
$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_s
ingle
* @depends test
SetS
ingle
*/
function
test___set
()
{
$this
->
root
->
foo
=
'bar'
;
...
...
@@ -151,16 +151,16 @@ class NodeTest extends PHPUnit_Framework_TestCase {
}
/**
* @depends test
_set_m
ultiple
* @depends test
SetM
ultiple
*/
function
test
_get_d
irect
()
{
function
test
GetD
irect
()
{
$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_d
irect
* @depends test
GetD
irect
*/
function
test___get
()
{
$this
->
root
->
set
(
array
(
'foo'
=>
'bar'
,
'bar'
=>
'baz'
));
...
...
@@ -169,22 +169,22 @@ class NodeTest extends PHPUnit_Framework_TestCase {
}
/**
* @depends test
_set_s
ingle
* @depends test
SetS
ingle
*/
function
test
_get_a
ncestor
()
{
function
test
GetA
ncestor
()
{
$this
->
root
->
set
(
'foo'
,
'bar'
);
$node
=
$this
->
root
->
add
(
''
);
$this
->
assertEquals
(
$node
->
get
(
'foo'
),
'bar'
);
}
function
test
_get_f
ailure
()
{
function
test
GetF
ailure
()
{
$this
->
assertNull
(
$this
->
root
->
get
(
'foo'
));
}
/**
* @depends test
_get_n
ame
* @depends test
GetN
ame
*/
function
test
_f
ind
()
{
function
test
F
ind
()
{
$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_m
ultiple
* @depends test
SetM
ultiple
*/
function
test
_copy_s
imple
()
{
function
test
CopyS
imple
()
{
$copy
=
$this
->
root
->
copy
();
$this
->
assertEquals
(
$this
->
root
,
$copy
);
$this
->
assertNotSame
(
$this
->
root
,
$copy
);
}
/**
* @depends test
_copy_s
imple
* @depends test
CopyS
imple
*/
function
test
_copy_s
hallow
()
{
function
test
CopyS
hallow
()
{
$child
=
$this
->
root
->
add
(
''
);
$copy
=
$this
->
root
->
copy
();
$this
->
assertAttributeSame
(
array
(
$child
),
'children'
,
$copy
);
}
/**
* @depends test
_get_c
hildren
* @depends test
_copy_s
imple
* @depends test
GetC
hildren
* @depends test
CopyS
imple
*/
function
test
_copy_d
eep
()
{
function
test
CopyD
eep
()
{
$child
=
$this
->
root
->
add
(
'foo'
);
$copy
=
$this
->
root
->
copy
(
true
);
$copy_children
=
$copy
->
get
_c
hildren
();
$copy_children
=
$copy
->
get
C
hildren
();
$child_copy
=
reset
(
$copy_children
);
$this
->
assertNotSame
(
$copy_children
,
$this
->
root
->
get
_c
hildren
());
$this
->
assertSame
(
$child_copy
->
get
_p
arent
(),
$copy
);
$this
->
assertNotSame
(
$copy_children
,
$this
->
root
->
get
C
hildren
());
$this
->
assertSame
(
$child_copy
->
get
P
arent
(),
$copy
);
}
}
...
...
tests/test_router.php
View file @
3566402f
...
...
@@ -24,29 +24,29 @@ class RouterTest extends PHPUnit_Framework_TestCase {
));
}
function
test
_call_handler_s
uccess
()
{
$this
->
assertEquals
(
true
,
$this
->
router
->
call
_h
andler
(
'foo'
));
$this
->
assertEquals
(
'bar'
,
$this
->
router
->
call
_h
andler
(
'bar'
));
$this
->
assertEquals
(
'baz'
,
$this
->
router
->
call
_h
andler
(
'baz'
));
$this
->
assertEquals
(
'barbaz'
,
$this
->
router
->
call
_h
andler
(
'bazbar'
));
function
test
CallHandlerS
uccess
()
{
$this
->
assertEquals
(
true
,
$this
->
router
->
call
H
andler
(
'foo'
));
$this
->
assertEquals
(
'bar'
,
$this
->
router
->
call
H
andler
(
'bar'
));
$this
->
assertEquals
(
'baz'
,
$this
->
router
->
call
H
andler
(
'baz'
));
$this
->
assertEquals
(
'barbaz'
,
$this
->
router
->
call
H
andler
(
'bazbar'
));
}
function
test
_call_handler_f
ailure
()
{
$this
->
assertFalse
(
$this
->
router
->
call
_h
andler
(
'barfoo'
));
function
test
CallHandlerF
ailure
()
{
$this
->
assertFalse
(
$this
->
router
->
call
H
andler
(
'barfoo'
));
}
function
test
_call_handler_s
kip
()
{
function
test
CallHandlerS
kip
()
{
$foo
=
'foo'
;
$bar
=
function
()
use
(
&
$foo
)
{
$foo
=
'bar'
;
return
false
;
};
$baz
=
function
()
{
return
;
};
$router
=
new
Router
(
array
(
'.*'
=>
$bar
,
'baz'
=>
$baz
));
$router
->
call
_h
andler
(
'baz'
);
$router
->
call
H
andler
(
'baz'
);
$this
->
assertEquals
(
'bar'
,
$foo
);
}
function
test
_add_r
oute
()
{
$this
->
router
->
add
_r
oute
(
'(foobar)'
,
'test_handler_arg'
);
$this
->
assertEquals
(
'foobar'
,
$this
->
router
->
call
_h
andler
(
'foobar'
));
function
test
AddR
oute
()
{
$this
->
router
->
add
R
oute
(
'(foobar)'
,
'test_handler_arg'
);
$this
->
assertEquals
(
'foobar'
,
$this
->
router
->
call
H
andler
(
'foobar'
));
}
}
...
...
tests/test_template.php
View file @
3566402f
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment