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';
...
@@ -16,7 +16,7 @@ require_once 'base.php';
* Simple example: all classes are located in the 'classes' directory.
* Simple example: all classes are located in the 'classes' directory.
* <code>
* <code>
* $loader = new Autoloader('classes');
* $loader = new Autoloader('classes');
* $loader->load
_c
lass('FooBar'); // Includes file 'classes/foo_bar.php'
* $loader->load
C
lass('FooBar'); // Includes file 'classes/foo_bar.php'
* </code>
* </code>
*
*
* An Autoloader instance can register itself to the SPL autoload stack, so
* An Autoloader instance can register itself to the SPL autoload stack, so
...
@@ -85,9 +85,9 @@ class Autoloader extends Base {
...
@@ -85,9 +85,9 @@ class Autoloader extends Base {
* @param bool $throw Whether to throw an exception when a class file does not exist.
* @param bool $throw Whether to throw an exception when a class file does not exist.
*/
*/
function
__construct
(
$root_directory
,
$root_namespace
=
'\\'
,
$throw
=
false
)
{
function
__construct
(
$root_directory
,
$root_namespace
=
'\\'
,
$throw
=
false
)
{
$this
->
set
_root_d
irectory
(
$root_directory
);
$this
->
set
RootD
irectory
(
$root_directory
);
$this
->
set
_root_n
amespace
(
$root_namespace
);
$this
->
set
RootN
amespace
(
$root_namespace
);
$this
->
set
_throw_e
rrors
(
$throw
);
$this
->
set
ThrowE
rrors
(
$throw
);
}
}
/**
/**
...
@@ -95,7 +95,7 @@ class Autoloader extends Base {
...
@@ -95,7 +95,7 @@ class Autoloader extends Base {
*
*
* @param bool $throw Whether to throw exceptions.
* @param bool $throw Whether to throw exceptions.
*/
*/
function
set
_throw_e
rrors
(
$throw
)
{
function
set
ThrowE
rrors
(
$throw
)
{
$this
->
throw_errors
=
!!
$throw
;
$this
->
throw_errors
=
!!
$throw
;
}
}
...
@@ -104,7 +104,7 @@ class Autoloader extends Base {
...
@@ -104,7 +104,7 @@ class Autoloader extends Base {
*
*
* @return bool
* @return bool
*/
*/
function
get
_throw_e
rrors
()
{
function
get
ThrowE
rrors
()
{
return
$this
->
throw_errors
;
return
$this
->
throw_errors
;
}
}
...
@@ -113,8 +113,8 @@ class Autoloader extends Base {
...
@@ -113,8 +113,8 @@ class Autoloader extends Base {
*
*
* @param string $directory The new root directory.
* @param string $directory The new root directory.
*/
*/
function
set
_root_d
irectory
(
$directory
)
{
function
set
RootD
irectory
(
$directory
)
{
$this
->
root_directory
=
self
::
path
_with_s
lash
(
$directory
);
$this
->
root_directory
=
self
::
path
WithS
lash
(
$directory
);
}
}
/**
/**
...
@@ -122,7 +122,7 @@ class Autoloader extends Base {
...
@@ -122,7 +122,7 @@ class Autoloader extends Base {
*
*
* @return string
* @return string
*/
*/
function
get
_root_d
irectory
()
{
function
get
RootD
irectory
()
{
return
$this
->
root_directory
;
return
$this
->
root_directory
;
}
}
...
@@ -131,9 +131,9 @@ class Autoloader extends Base {
...
@@ -131,9 +131,9 @@ class Autoloader extends Base {
*
*
* @param string $namespace The new root namespace.
* @param string $namespace The new root namespace.
*/
*/
function
set
_root_n
amespace
(
$namespace
)
{
function
set
RootN
amespace
(
$namespace
)
{
// Assert that the namespace ends with a backslash
// Assert that the namespace ends with a backslash
if
(
$namespace
[
strlen
(
$namespace
)
-
1
]
!=
'\\'
)
if
(
$namespace
[
strlen
(
$namespace
)
-
1
]
!=
'\\'
)
$namespace
.=
'\\'
;
$namespace
.=
'\\'
;
$this
->
root_namespace
=
$namespace
;
$this
->
root_namespace
=
$namespace
;
...
@@ -144,7 +144,7 @@ class Autoloader extends Base {
...
@@ -144,7 +144,7 @@ class Autoloader extends Base {
*
*
* @return string
* @return string
*/
*/
function
get
_root_n
amespace
()
{
function
get
RootN
amespace
()
{
return
$this
->
root_namespace
;
return
$this
->
root_namespace
;
}
}
...
@@ -157,7 +157,7 @@ class Autoloader extends Base {
...
@@ -157,7 +157,7 @@ class Autoloader extends Base {
* @param string $classname The class name to convert.
* @param string $classname The class name to convert.
* @return string
* @return string
*/
*/
static
function
classname
_to_f
ilename
(
$classname
)
{
static
function
classname
ToF
ilename
(
$classname
)
{
return
strtolower
(
preg_replace
(
'/(?<=.)([A-Z])/'
,
'_\\1'
,
$classname
));
return
strtolower
(
preg_replace
(
'/(?<=.)([A-Z])/'
,
'_\\1'
,
$classname
));
}
}
...
@@ -167,7 +167,7 @@ class Autoloader extends Base {
...
@@ -167,7 +167,7 @@ class Autoloader extends Base {
* @param string $classname The name of the class to strip the namespace from.
* @param string $classname The name of the class to strip the namespace from.
* @return string The stripped class name.
* @return string The stripped class name.
*/
*/
private
function
strip
_root_n
amespace
(
$classname
)
{
private
function
strip
RootN
amespace
(
$classname
)
{
$begin
=
substr
(
$classname
,
0
,
strlen
(
$this
->
root_namespace
));
$begin
=
substr
(
$classname
,
0
,
strlen
(
$this
->
root_namespace
));
if
(
$begin
==
$this
->
root_namespace
)
if
(
$begin
==
$this
->
root_namespace
)
...
@@ -184,9 +184,9 @@ class Autoloader extends Base {
...
@@ -184,9 +184,9 @@ class Autoloader extends Base {
*
*
* @param string $classname The name of the class to create the file path of.
* @param string $classname The name of the class to create the file path of.
*/
*/
function
create
_p
ath
(
$classname
)
{
function
create
P
ath
(
$classname
)
{
$namespaces
=
array_filter
(
explode
(
'\\'
,
$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
;
$path
=
$this
->
root_directory
;
if
(
count
(
$dirs
)
>
1
)
if
(
count
(
$dirs
)
>
1
)
...
@@ -207,9 +207,9 @@ class Autoloader extends Base {
...
@@ -207,9 +207,9 @@ class Autoloader extends Base {
* @return bool
* @return bool
* @throws FileNotFoundError If the class file does not exist.
* @throws FileNotFoundError If the class file does not exist.
*/
*/
function
load
_c
lass
(
$classname
,
$throw
=
null
)
{
function
load
C
lass
(
$classname
,
$throw
=
null
)
{
$classname
=
$this
->
strip
_root_n
amespace
(
$classname
);
$classname
=
$this
->
strip
RootN
amespace
(
$classname
);
$path
=
$this
->
create
_p
ath
(
$classname
);
$path
=
$this
->
create
P
ath
(
$classname
);
if
(
!
file_exists
(
$path
))
{
if
(
!
file_exists
(
$path
))
{
if
(
$throw
||
(
$throw
===
null
&&
$this
->
throw_errors
))
if
(
$throw
||
(
$throw
===
null
&&
$this
->
throw_errors
))
...
@@ -229,7 +229,7 @@ class Autoloader extends Base {
...
@@ -229,7 +229,7 @@ class Autoloader extends Base {
* the stack, instead of appending it.
* the stack, instead of appending it.
*/
*/
function
register
(
$prepend
=
false
)
{
function
register
(
$prepend
=
false
)
{
spl_autoload_register
(
array
(
$this
,
'load
_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 {
...
@@ -61,7 +61,7 @@ abstract class Base {
* @param string $directory The directory to append a slash to.
* @param string $directory The directory to append a slash to.
* @return string
* @return string
*/
*/
static
function
path
_with_s
lash
(
$directory
)
{
static
function
path
WithS
lash
(
$directory
)
{
return
$directory
[
strlen
(
$directory
)
-
1
]
==
'/'
?
$directory
:
$directory
.
'/'
;
return
$directory
[
strlen
(
$directory
)
-
1
]
==
'/'
?
$directory
:
$directory
.
'/'
;
}
}
}
}
...
...
collection.php
View file @
3566402f
...
@@ -16,25 +16,25 @@ require_once 'base.php';
...
@@ -16,25 +16,25 @@ require_once 'base.php';
*
*
* Example 1: Index a list based on its values and extract a single attribute.
* Example 1: Index a list based on its values and extract a single attribute.
* <code>
* <code>
* class Book extends
PHP
ActiveRecord\Model {
* class Book extends ActiveRecord\Model {
* static $attr_accessible = array('id', 'name');
* static $attr_accessible = array('id', 'name');
* }
* }
*
*
* // Index all book names by their id.
* // Index all book names by their id.
* $books = Book::all(); // Find a list of books
* $books = Book::all(); // Find a list of books
* $collection = new Collection($books); // Put the list in a collection
* $collection = new Collection($books); // Put the list in a collection
* $indexed = $collection->index
_b
y('id'); // Create indexes for all books
* $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 = $indexed->get
A
ttribute('name'); // Get the values of a single attribute
* // $names now contains something like array(1 => 'Some book', 2 => 'Another book')
* // $names now contains something like array(1 => 'Some book', 2 => 'Another book')
*
*
* // Same as above:
* // Same as above:
* $names = Collection::create(Book::all())->index
_by('id')->get_a
ttribute('name');
* $names = Collection::create(Book::all())->index
By('id')->getA
ttribute('name');
* </code>
* </code>
*
*
* Example 2: Execute a method for each item in a list.
* Example 2: Execute a method for each item in a list.
* <code>
* <code>
* // Delete all books
* // Delete all books
* Collection::create(Book::all())->map
_m
ethod('delete');
* Collection::create(Book::all())->map
M
ethod('delete');
* </code>
* </code>
*
*
* @package WebBasics
* @package WebBasics
...
@@ -138,7 +138,7 @@ class Collection extends Base {
...
@@ -138,7 +138,7 @@ class Collection extends Base {
* @param int|string $index The index to check existance of.
* @param int|string $index The index to check existance of.
* @return bool Whether the index exists.
* @return bool Whether the index exists.
*/
*/
function
index
_e
xists
(
$index
)
{
function
index
E
xists
(
$index
)
{
return
isset
(
$this
->
items
[
$index
]);
return
isset
(
$this
->
items
[
$index
]);
}
}
...
@@ -157,7 +157,7 @@ class Collection extends Base {
...
@@ -157,7 +157,7 @@ class Collection extends Base {
*
*
* @param int|string $index The index to the item to delete.
* @param int|string $index The index to the item to delete.
*/
*/
function
delete
_i
ndex
(
$index
)
{
function
delete
I
ndex
(
$index
)
{
unset
(
$this
->
items
[
$index
]);
unset
(
$this
->
items
[
$index
]);
}
}
...
@@ -167,7 +167,7 @@ class Collection extends Base {
...
@@ -167,7 +167,7 @@ class Collection extends Base {
* @param mixed $item The item to delete.
* @param mixed $item The item to delete.
*/
*/
function
delete
(
$item
)
{
function
delete
(
$item
)
{
$this
->
delete
_i
ndex
(
array_search
(
$item
,
$this
->
items
));
$this
->
delete
I
ndex
(
array_search
(
$item
,
$this
->
items
));
}
}
/**
/**
...
@@ -178,7 +178,7 @@ class Collection extends Base {
...
@@ -178,7 +178,7 @@ class Collection extends Base {
* object's item set and not create a new object.
* object's item set and not create a new object.
* @return Collection A collection with the new item set.
* @return Collection A collection with the new item set.
*/
*/
private
function
set
_i
tems
(
array
$items
,
$clone
=
true
)
{
private
function
set
I
tems
(
array
$items
,
$clone
=
true
)
{
if
(
$clone
)
if
(
$clone
)
return
new
self
(
$items
);
return
new
self
(
$items
);
...
@@ -194,7 +194,7 @@ class Collection extends Base {
...
@@ -194,7 +194,7 @@ class Collection extends Base {
* @return Collection A collection without duplicates.
* @return Collection A collection without duplicates.
*/
*/
function
uniques
(
$clone
=
false
)
{
function
uniques
(
$clone
=
false
)
{
return
$this
->
set
_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 {
...
@@ -207,7 +207,7 @@ class Collection extends Base {
* @return Collection A collection with the filtered set of items.
* @return Collection A collection with the filtered set of items.
*/
*/
function
filter
(
$callback
,
$clone
=
true
)
{
function
filter
(
$callback
,
$clone
=
true
)
{
return
$this
->
set
_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 {
...
@@ -227,13 +227,13 @@ class Collection extends Base {
return
$this
->
filter
(
function
(
$item
)
use
(
$conditions
)
{
return
$this
->
filter
(
function
(
$item
)
use
(
$conditions
)
{
if
(
is_object
(
$item
))
{
if
(
is_object
(
$item
))
{
// Object, match property values
// Object, match property values
foreach
(
$conditions
as
$property
=>
$value
)
foreach
(
$conditions
as
$property
=>
$value
)
if
(
$item
->
{
$property
}
!=
$value
)
if
(
$item
->
{
$property
}
!=
$value
)
return
false
;
return
false
;
}
elseif
(
is_array
(
$item
))
{
}
elseif
(
is_array
(
$item
))
{
// Array item, match array values
// Array item, match array values
foreach
(
$conditions
as
$property
=>
$value
)
foreach
(
$conditions
as
$property
=>
$value
)
if
(
$item
[
$property
]
!=
$value
)
if
(
$item
[
$property
]
!=
$value
)
return
false
;
return
false
;
}
else
{
}
else
{
// Other, incompatible type -> throw exception
// Other, incompatible type -> throw exception
...
@@ -254,7 +254,7 @@ class Collection extends Base {
...
@@ -254,7 +254,7 @@ class Collection extends Base {
* @param string $attribute The name of the attribute to get the value of.
* @param string $attribute The name of the attribute to get the value of.
* @return array The original item keys, pointing to single attribute values.
* @return array The original item keys, pointing to single attribute values.
*/
*/
function
get
_a
ttribute
(
$attribute
)
{
function
get
A
ttribute
(
$attribute
)
{
return
array_map
(
function
(
$item
)
use
(
$attribute
)
{
return
array_map
(
function
(
$item
)
use
(
$attribute
)
{
return
$item
->
{
$attribute
};
return
$item
->
{
$attribute
};
},
$this
->
items
);
},
$this
->
items
);
...
@@ -269,13 +269,13 @@ class Collection extends Base {
...
@@ -269,13 +269,13 @@ class Collection extends Base {
* @param bool $clone Whether to create a new object, or overwrite the current item set.
* @param bool $clone Whether to create a new object, or overwrite the current item set.
* @return Collection A collection object with the values of the attribute used as indices.
* @return Collection A collection object with the values of the attribute used as indices.
*/
*/
function
index
_b
y
(
$attribute
,
$clone
=
true
)
{
function
index
B
y
(
$attribute
,
$clone
=
true
)
{
$indexed
=
array
();
$indexed
=
array
();
foreach
(
$this
->
items
as
$item
)
foreach
(
$this
->
items
as
$item
)
$indexed
[
$item
->
$attribute
]
=
$item
;
$indexed
[
$item
->
$attribute
]
=
$item
;
return
$this
->
set
_i
tems
(
$indexed
,
$clone
);
return
$this
->
set
I
tems
(
$indexed
,
$clone
);
}
}
/**
/**
...
@@ -286,7 +286,7 @@ class Collection extends Base {
...
@@ -286,7 +286,7 @@ class Collection extends Base {
* @return Collection A collection with return values of the callback calls.
* @return Collection A collection with return values of the callback calls.
*/
*/
function
map
(
$callback
,
$clone
=
true
)
{
function
map
(
$callback
,
$clone
=
true
)
{
return
$this
->
set
_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 {
...
@@ -299,13 +299,13 @@ class Collection extends Base {
* @param bool $clone Whether to create a new object, or overwrite the current item set.
* @param bool $clone Whether to create a new object, or overwrite the current item set.
* @return Collection A collection with return values of the method calls.
* @return Collection A collection with return values of the method calls.
*/
*/
function
map
_m
ethod
(
$method_name
,
array
$args
=
array
(),
$clone
=
true
)
{
function
map
M
ethod
(
$method_name
,
array
$args
=
array
(),
$clone
=
true
)
{
$items
=
array
();
$items
=
array
();
foreach
(
$this
->
items
as
$item
)
foreach
(
$this
->
items
as
$item
)
$items
[]
=
call_user_func_array
(
array
(
$item
,
$method_name
),
$args
);
$items
[]
=
call_user_func_array
(
array
(
$item
,
$method_name
),
$args
);
return
$this
->
set
_i
tems
(
$items
);
return
$this
->
set
I
tems
(
$items
);
}
}
}
}
...
...
logger.php
View file @
3566402f
...
@@ -35,34 +35,34 @@ class Logger extends Base {
...
@@ -35,34 +35,34 @@ class Logger extends Base {
private
$dump_format
=
'plain'
;
private
$dump_format
=
'plain'
;
private
$log_directory
=
''
;
private
$log_directory
=
''
;
function
set
_d
irectory
(
$directory
)
{
function
set
D
irectory
(
$directory
)
{
$this
->
log_directory
=
self
::
path
_with_s
lash
(
$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
))
if
(
!
in_array
(
$format
,
self
::
$allowed_dump_formats
))
throw
new
\InvalidArgumentException
(
sprintf
(
''
,
$format
));
throw
new
\InvalidArgumentException
(
sprintf
(
''
,
$format
));
$this
->
dump_format
=
$format
;
$this
->
dump_format
=
$format
;
}
}
function
set
_f
ormat
(
$format
)
{
function
set
F
ormat
(
$format
)
{
$this
->
format
=
(
string
)
$format
;
$this
->
format
=
(
string
)
$format
;
}
}
function
get
_f
ormat
()
{
function
get
F
ormat
()
{
return
$this
->
format
;
return
$this
->
format
;
}
}
function
get
_l
evel
()
{
function
get
L
evel
()
{
return
$this
->
level
;
return
$this
->
level
;
}
}
function
get
_level_n
ame
()
{
function
get
LevelN
ame
()
{
return
self
::
$level_names
[
$this
->
level
];
return
self
::
$level_names
[
$this
->
level
];
}
}
function
set
_l
evel
(
$level
)
{
function
set
L
evel
(
$level
)
{
if
(
is_string
(
$level
))
{
if
(
is_string
(
$level
))
{
$level
=
strtoupper
(
$level
);
$level
=
strtoupper
(
$level
);
...
@@ -78,7 +78,7 @@ class Logger extends Base {
...
@@ -78,7 +78,7 @@ class Logger extends Base {
$this
->
level
=
$level
;
$this
->
level
=
$level
;
}
}
function
set
_p
roperty
(
$name
,
$value
)
{
function
set
P
roperty
(
$name
,
$value
)
{
$this
->
properties
[
$name
]
=
(
string
)
$value
;
$this
->
properties
[
$name
]
=
(
string
)
$value
;
}
}
...
@@ -133,7 +133,7 @@ class Logger extends Base {
...
@@ -133,7 +133,7 @@ class Logger extends Base {
if
(
$name
==
'level'
)
if
(
$name
==
'level'
)
return
Logger
::
$level_names
[
$level
];
return
Logger
::
$level_names
[
$level
];
return
$logger
->
get
_formatted_p
roperty
(
$matches
[
1
]);
return
$logger
->
get
FormattedP
roperty
(
$matches
[
1
]);
},
},
$this
->
format
$this
->
format
);
);
...
@@ -169,7 +169,7 @@ class Logger extends Base {
...
@@ -169,7 +169,7 @@ class Logger extends Base {
file_put_contents
(
$this
->
log_directory
.
$path
,
$this
->
dumps
());
file_put_contents
(
$this
->
log_directory
.
$path
,
$this
->
dumps
());
}
}
function
handle
_e
xception
(
\Exception
$e
)
{
function
handle
E
xception
(
\Exception
$e
)
{
if
(
$e
===
null
)
if
(
$e
===
null
)
return
;
return
;
...
@@ -179,17 +179,17 @@ class Logger extends Base {
...
@@ -179,17 +179,17 @@ class Logger extends Base {
$this
->
dump
(
'error'
);
$this
->
dump
(
'error'
);
}
}
function
set
_as_exception_h
andler
()
{
function
set
AsExceptionH
andler
()
{
set_exception_handler
(
array
(
$this
,
'handle_exception'
));
set_exception_handler
(
array
(
$this
,
'handle_exception'
));
}
}
function
get
_formatted_p
roperty
(
$property
)
{
function
get
FormattedP
roperty
(
$property
)
{
if
(
isset
(
$this
->
properties
[
$property
]))
if
(
isset
(
$this
->
properties
[
$property
]))
return
$this
->
properties
[
$property
];
return
$this
->
properties
[
$property
];
switch
(
$property
)
{
switch
(
$property
)
{
case
'loglevel'
:
case
'loglevel'
:
return
$this
->
get
_level_n
ame
();
return
$this
->
get
LevelN
ame
();
case
'date'
:
case
'date'
:
return
strftime
(
'%d-%m-%Y'
);
return
strftime
(
'%d-%m-%Y'
);
case
'time'
:
case
'time'
:
...
...
node.php
View file @
3566402f
...
@@ -88,7 +88,7 @@ class Node extends Base {
...
@@ -88,7 +88,7 @@ class Node extends Base {
*
*
* @return int The node's id.
* @return int The node's id.
*/
*/
function
get
_i
d
()
{
function
get
I
d
()
{
return
$this
->
id
;
return
$this
->
id
;
}
}
...
@@ -97,7 +97,7 @@ class Node extends Base {
...
@@ -97,7 +97,7 @@ class Node extends Base {
*
*
* @return string The node's name.
* @return string The node's name.
*/
*/
function
get
_n
ame
()
{
function
get
N
ame
()
{
return
$this
->
name
;
return
$this
->
name
;
}
}
...
@@ -106,7 +106,7 @@ class Node extends Base {
...
@@ -106,7 +106,7 @@ class Node extends Base {
*
*
* @return Node|null The parent node if any, NULL otherwise.
* @return Node|null The parent node if any, NULL otherwise.
*/
*/
function
get
_p
arent
()
{
function
get
P
arent
()
{
return
$this
->
parent_node
;
return
$this
->
parent_node
;
}
}
...
@@ -115,7 +115,7 @@ class Node extends Base {
...
@@ -115,7 +115,7 @@ class Node extends Base {
*
*
* @return array A list of child nodes.
* @return array A list of child nodes.
*/
*/
function
get
_c
hildren
()
{
function
get
C
hildren
()
{
return
$this
->
children
;
return
$this
->
children
;
}
}
...
@@ -126,7 +126,7 @@ class Node extends Base {
...
@@ -126,7 +126,7 @@ class Node extends Base {
* @return bool Whether the nodes have the same unique id.
* @return bool Whether the nodes have the same unique id.
*/
*/
function
is
(
Node
$node
)
{
function
is
(
Node
$node
)
{
return
$node
->
get
_i
d
()
==
$this
->
id
;
return
$node
->
get
I
d
()
==
$this
->
id
;
}
}
/**
/**
...
@@ -136,7 +136,7 @@ class Node extends Base {
...
@@ -136,7 +136,7 @@ class Node extends Base {
*
*
* @return bool Whether this node is the root node.
* @return bool Whether this node is the root node.
*/
*/
function
is
_r
oot
()
{
function
is
R
oot
()
{
return
$this
->
parent_node
===
null
;
return
$this
->
parent_node
===
null
;
}
}
...
@@ -147,7 +147,7 @@ class Node extends Base {
...
@@ -147,7 +147,7 @@ class Node extends Base {
*
*
* @return bool Whether this node is a leaf node.
* @return bool Whether this node is a leaf node.
*/
*/
function
is
_l
eaf
()
{
function
is
L
eaf
()
{
return
!
count
(
$this
->
children
);
return
!
count
(
$this
->
children
);
}
}
...
@@ -158,9 +158,9 @@ class Node extends Base {
...
@@ -158,9 +158,9 @@ class Node extends Base {
* @param bool $set_parent Whether to set this node as the child's parent
* @param bool $set_parent Whether to set this node as the child's parent
* (defaults to TRUE).
* (defaults to TRUE).
*/
*/
function
add
_c
hild
(
Node
&
$node
,
$set_parent
=
true
)
{
function
add
C
hild
(
Node
&
$node
,
$set_parent
=
true
)
{
$this
->
children
[]
=
$node
;
$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 {
...
@@ -172,7 +172,7 @@ class Node extends Base {
*/
*/
function
add
(
$name
,
array
$data
=
array
())
{
function
add
(
$name
,
array
$data
=
array
())
{
$node
=
new
self
(
$name
,
$this
);
$node
=
new
self
(
$name
,
$this
);
$this
->
add
_c
hild
(
$node
,
false
);
$this
->
add
C
hild
(
$node
,
false
);
return
$node
->
set
(
$data
);
return
$node
->
set
(
$data
);
}
}
...
@@ -182,7 +182,7 @@ class Node extends Base {
...
@@ -182,7 +182,7 @@ class Node extends Base {
*
*
* @param Node &$child The node to remove.
* @param Node &$child The node to remove.
*/
*/
function
remove
_c
hild
(
Node
&
$child
)
{
function
remove
C
hild
(
Node
&
$child
)
{
foreach
(
$this
->
children
as
$i
=>
$node
)
foreach
(
$this
->
children
as
$i
=>
$node
)
$node
->
is
(
$child
)
&&
array_splice
(
$this
->
children
,
$i
,
1
);
$node
->
is
(
$child
)
&&
array_splice
(
$this
->
children
,
$i
,
1
);
}
}
...
@@ -194,13 +194,13 @@ class Node extends Base {
...
@@ -194,13 +194,13 @@ class Node extends Base {
* @return Node This node.
* @return Node This node.
*/
*/
function
remove
()
{
function
remove
()
{
if
(
$this
->
is
_r
oot
())
if
(
$this
->
is
R
oot
())
throw
new
\RuntimeException
(
'Cannot remove the root node of a tree.'
);
throw
new
\RuntimeException
(
'Cannot remove the root node of a tree.'
);
$this
->
parent_node
->
remove
_c
hild
(
$this
);
$this
->
parent_node
->
remove
C
hild
(
$this
);
foreach
(
$this
->
children
as
$child
)
foreach
(
$this
->
children
as
$child
)
$child
->
set
_p
arent
(
null
);
$child
->
set
P
arent
(
null
);
return
$this
;
return
$this
;
}
}
...
@@ -214,9 +214,9 @@ class Node extends Base {
...
@@ -214,9 +214,9 @@ class Node extends Base {
* @param Node|null $parent The parent node to set.
* @param Node|null $parent The parent node to set.
* @return Node This node.
* @return Node This node.
*/
*/
function
set
_p
arent
(
$parent
)
{
function
set
P
arent
(
$parent
)
{
if
(
$this
->
parent_node
!==
null
)
if
(
$this
->
parent_node
!==
null
)
$this
->
parent_node
->
remove
_c
hild
(
$this
);
$this
->
parent_node
->
remove
C
hild
(
$this
);
$this
->
parent_node
=
&
$parent
;
$this
->
parent_node
=
&
$parent
;
...
@@ -292,7 +292,7 @@ class Node extends Base {
...
@@ -292,7 +292,7 @@ class Node extends Base {
*/
*/
function
find
(
$name
)
{
function
find
(
$name
)
{
$has_name
=
function
(
$child
)
use
(
$name
)
{
$has_name
=
function
(
$child
)
use
(
$name
)
{
return
$child
->
get
_n
ame
()
==
$name
;
return
$child
->
get
N
ame
()
==
$name
;
};
};
return
array_values
(
array_filter
(
$this
->
children
,
$has_name
));
return
array_values
(
array_filter
(
$this
->
children
,
$has_name
));
...
@@ -314,9 +314,9 @@ class Node extends Base {
...
@@ -314,9 +314,9 @@ class Node extends Base {
foreach
(
$this
->
children
as
$child
)
{
foreach
(
$this
->
children
as
$child
)
{
if
(
$deep
)
{
if
(
$deep
)
{
$child_copy
=
$child
->
copy
(
true
);
$child_copy
=
$child
->
copy
(
true
);
$copy
->
add
_c
hild
(
$child_copy
);
$copy
->
add
C
hild
(
$child_copy
);
}
else
{
}
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';
...
@@ -28,8 +28,8 @@ require_once 'base.php';
* '/home' => 'home',
* '/home' => 'home',
* '/contact' => 'contact'
* '/contact' => 'contact'
* ));
* ));
* $response = $router->call
_h
andler('/home'); // 'This is the home 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('/contact'); // 'This is the contact page.'
* </code>
* </code>
*
*
* You can use regular expression patterns to specify an URL. Any matches are
* You can use regular expression patterns to specify an URL. Any matches are
...
@@ -42,8 +42,8 @@ require_once 'base.php';
...
@@ -42,8 +42,8 @@ require_once 'base.php';
* $router = new Router(array(
* $router = new Router(array(
* '/(home|contact)' => 'page'
* '/(home|contact)' => 'page'
* ));
* ));
* $response = $router->call
_h
andler('/home'); // 'This is the home 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('/contact'); // 'This is the contact page.'
* </code>
* </code>
*
*
* @package WebBasics
* @package WebBasics
...
@@ -70,7 +70,7 @@ class Router extends Base {
...
@@ -70,7 +70,7 @@ class Router extends Base {
*/
*/
function
__construct
(
array
$routes
=
array
())
{
function
__construct
(
array
$routes
=
array
())
{
foreach
(
$routes
as
$pattern
=>
$handler
)
foreach
(
$routes
as
$pattern
=>
$handler
)
$this
->
add
_r
oute
(
$pattern
,
$handler
);
$this
->
add
R
oute
(
$pattern
,
$handler
);
}
}
/**
/**
...
@@ -87,7 +87,7 @@ class Router extends Base {
...
@@ -87,7 +87,7 @@ class Router extends Base {
* @param mixed $handler The handler function to call when $pattern is matched.
* @param mixed $handler The handler function to call when $pattern is matched.
* @throws \InvalidArgumentException If $handler is not callable.
* @throws \InvalidArgumentException If $handler is not callable.
*/
*/
function
add
_r
oute
(
$pattern
,
$handler
)
{
function
add
R
oute
(
$pattern
,
$handler
)
{
if
(
!
is_callable
(
$handler
))
if
(
!
is_callable
(
$handler
))
throw
new
\InvalidArgumentException
(
sprintf
(
'Handler for patterns "%s" is not callable.'
,
$pattern
));
throw
new
\InvalidArgumentException
(
sprintf
(
'Handler for patterns "%s" is not callable.'
,
$pattern
));
...
@@ -107,7 +107,7 @@ class Router extends Base {
...
@@ -107,7 +107,7 @@ class Router extends Base {
* @return mixed FALSE if no pattern was matched, the return value of the
* @return mixed FALSE if no pattern was matched, the return value of the
* corresponding handler function otherwise.
* corresponding handler function otherwise.
*/
*/
function
call
_h
andler
(
$url
)
{
function
call
H
andler
(
$url
)
{
foreach
(
$this
->
routes
as
$pattern
=>
$handler
)
{
foreach
(
$this
->
routes
as
$pattern
=>
$handler
)
{
if
(
preg_match
(
$pattern
,
$url
,
$matches
))
{
if
(
preg_match
(
$pattern
,
$url
,
$matches
))
{
array_shift
(
$matches
);
array_shift
(
$matches
);
...
...
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 {
...
@@ -10,139 +10,139 @@ class AutoloaderTest extends PHPUnit_Framework_TestCase {
$this
->
autoloader
=
new
Autoloader
(
PATH
);
$this
->
autoloader
=
new
Autoloader
(
PATH
);
}
}
function
test
_set_root_n
amespace
()
{
function
test
SetRootN
amespace
()
{
$this
->
assertAttributeEquals
(
'\\'
,
'root_namespace'
,
$this
->
autoloader
);
$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
->
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
);
$this
->
assertAttributeEquals
(
'Foo\\'
,
'root_namespace'
,
$this
->
autoloader
);
}
}
/**
/**
* @depends test
_set_root_n
amespace
* @depends test
SetRootN
amespace
*/
*/
function
test
_get_root_n
amespace
()
{
function
test
GetRootN
amespace
()
{
$this
->
autoloader
->
set
_root_n
amespace
(
'Foo'
);
$this
->
autoloader
->
set
RootN
amespace
(
'Foo'
);
$this
->
assertEquals
(
$this
->
autoloader
->
get
_root_n
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'
);
$autoloader
=
new
Autoloader
(
PATH
,
'Foo'
);
$this
->
assertAttributeEquals
(
'Foo\\'
,
'root_namespace'
,
$autoloader
);
$this
->
assertAttributeEquals
(
'Foo\\'
,
'root_namespace'
,
$autoloader
);
}
}
/**
/**
* @depends test
_set_root_n
amespace
* @depends test
SetRootN
amespace
*/
*/
function
test
_strip_root_n
amespace
()
{
function
test
StripRootN
amespace
()
{
$strip
=
new
ReflectionMethod
(
'webbasics\Autoloader'
,
'strip
_root_n
amespace'
);
$strip
=
new
ReflectionMethod
(
'webbasics\Autoloader'
,
'strip
RootN
amespace'
);
$strip
->
setAccessible
(
true
);
$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'
);
$this
->
assertEquals
(
$strip
->
invoke
(
$this
->
autoloader
,
'Foo\Bar'
),
'Bar'
);
}
}
function
test
_set_root_d
irectory
()
{
function
test
SetRootD
irectory
()
{
$this
->
autoloader
->
set
_root_d
irectory
(
'tests'
);
$this
->
autoloader
->
set
RootD
irectory
(
'tests'
);
$this
->
assertEquals
(
$this
->
autoloader
->
get
_root_d
irectory
(),
'tests/'
);
$this
->
assertEquals
(
$this
->
autoloader
->
get
RootD
irectory
(),
'tests/'
);
}
}
function
test
_classname_to_f
ilename
()
{
function
test
ClassnameToF
ilename
()
{
$this
->
assertEquals
(
Autoloader
::
classname
_to_f
ilename
(
'Foo'
),
'foo'
);
$this
->
assertEquals
(
Autoloader
::
classname
ToF
ilename
(
'Foo'
),
'foo'
);
$this
->
assertEquals
(
Autoloader
::
classname
_to_f
ilename
(
'FooBar'
),
'foo_bar'
);
$this
->
assertEquals
(
Autoloader
::
classname
ToF
ilename
(
'FooBar'
),
'foo_bar'
);
$this
->
assertEquals
(
Autoloader
::
classname
_to_f
ilename
(
'fooBar'
),
'foo_bar'
);
$this
->
assertEquals
(
Autoloader
::
classname
ToF
ilename
(
'fooBar'
),
'foo_bar'
);
$this
->
assertEquals
(
Autoloader
::
classname
_to_f
ilename
(
'FooBarBaz'
),
'foo_bar_baz'
);
$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
()
{
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'
),
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'
),
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
(
'Foo\Bar\Baz'
),
PATH
.
'foo/bar/baz.php'
);
$this
->
assertEquals
(
$this
->
autoloader
->
create
_p
ath
(
'FooBar\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
()
{
function
test
ThrowE
rrors
()
{
$this
->
assertFalse
(
$this
->
autoloader
->
get
_throw_e
rrors
());
$this
->
assertFalse
(
$this
->
autoloader
->
get
ThrowE
rrors
());
$this
->
autoloader
->
set
_throw_e
rrors
(
true
);
$this
->
autoloader
->
set
ThrowE
rrors
(
true
);
$this
->
assertTrue
(
$this
->
autoloader
->
get
_throw_e
rrors
());
$this
->
assertTrue
(
$this
->
autoloader
->
get
ThrowE
rrors
());
}
}
/**
/**
* @depends test
_create_p
ath
* @depends test
CreateP
ath
* @depends test
_throw_e
rrors
* @depends test
ThrowE
rrors
*/
*/
function
test
_load_class_not_f
ound
()
{
function
test
LoadClassNotF
ound
()
{
$this
->
assertFalse
(
$this
->
autoloader
->
load
_c
lass
(
'foobar'
));
$this
->
assertFalse
(
$this
->
autoloader
->
load
C
lass
(
'foobar'
));
}
}
/**
/**
* @depends test
_load_class_not_f
ound
* @depends test
LoadClassNotF
ound
* @expectedException webbasics\FileNotFoundError
* @expectedException webbasics\FileNotFoundError
* @expectedExceptionMessage File "tests/_files/foobar.php" does not exist.
* @expectedExceptionMessage File "tests/_files/foobar.php" does not exist.
*/
*/
function
test
_load_class_not_found_e
rror
()
{
function
test
LoadClassNotFoundE
rror
()
{
$this
->
autoloader
->
set
_throw_e
rrors
(
true
);
$this
->
autoloader
->
set
ThrowE
rrors
(
true
);
$this
->
autoloader
->
load
_c
lass
(
'foobar'
);
$this
->
autoloader
->
load
C
lass
(
'foobar'
);
}
}
/**
/**
* @depends test
_load_class_not_f
ound
* @depends test
LoadClassNotF
ound
* @expectedException webbasics\FileNotFoundError
* @expectedException webbasics\FileNotFoundError
* @expectedExceptionMessage File "tests/_files/foobar.php" does not exist.
* @expectedExceptionMessage File "tests/_files/foobar.php" does not exist.
*/
*/
function
test
_load_class_not_found_noerror_o
verwrite
()
{
function
test
LoadClassNotFoundNoerrorO
verwrite
()
{
$this
->
autoloader
->
load
_c
lass
(
'foobar'
,
true
);
$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
()
{
function
test
LoadClassNotFoundErrorO
verwrite
()
{
$this
->
autoloader
->
set
_throw_e
rrors
(
true
);
$this
->
autoloader
->
set
ThrowE
rrors
(
true
);
$this
->
assertFalse
(
$this
->
autoloader
->
load
_c
lass
(
'foobar'
,
false
));
$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
()
{
function
test
LoadC
lass
()
{
$this
->
assertTrue
(
$this
->
autoloader
->
load
_c
lass
(
'Foo'
));
$this
->
assertTrue
(
$this
->
autoloader
->
load
C
lass
(
'Foo'
));
$this
->
assertTrue
(
class_exists
(
'Foo'
,
false
));
$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
));
$this
->
assertTrue
(
class_exists
(
'Foo\Bar'
,
false
));
}
}
/**
/**
* @depends test
_load_c
lass
* @depends test
LoadC
lass
* @depends test
_strip_root_n
amespace
* @depends test
StripRootN
amespace
*/
*/
function
test
_load_class_root_n
amespace
()
{
function
test
LoadClassRootN
amespace
()
{
$autoloader
=
new
Autoloader
(
PATH
.
'foo'
);
$autoloader
=
new
Autoloader
(
PATH
.
'foo'
);
$autoloader
->
set
_root_n
amespace
(
'Foo'
);
$autoloader
->
set
RootN
amespace
(
'Foo'
);
$this
->
assertTrue
(
$autoloader
->
load
_c
lass
(
'Bar'
));
$this
->
assertTrue
(
$autoloader
->
load
C
lass
(
'Bar'
));
$this
->
assertTrue
(
class_exists
(
'Foo\Bar'
,
false
));
$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
->
autoloader
->
register
();
$this
->
assertTrue
(
class_exists
(
'Baz'
));
$this
->
assertTrue
(
class_exists
(
'Baz'
));
}
}
/**
/**
* @depends test
_r
egister
* @depends test
R
egister
* @depends test
_throw_e
rrors
* @depends test
ThrowE
rrors
*/
*/
function
test
_register_p
repend
()
{
function
test
RegisterP
repend
()
{
$second_loader
=
new
Autoloader
(
PATH
.
'second'
);
$second_loader
=
new
Autoloader
(
PATH
.
'second'
);
$this
->
autoloader
->
register
();
$this
->
autoloader
->
register
();
$second_loader
->
register
(
true
);
// Prepend so that the second loader attemps to load Bar first
$second_loader
->
register
(
true
);
// Prepend so that the second loader attemps to load Bar first
...
...
tests/test_base.php
View file @
3566402f
...
@@ -11,11 +11,11 @@ class BaseExtension extends Base {
...
@@ -11,11 +11,11 @@ class BaseExtension extends Base {
}
}
class
BaseTest
extends
PHPUnit_Framework_TestCase
{
class
BaseTest
extends
PHPUnit_Framework_TestCase
{
function
test
_c
reate
()
{
function
test
C
reate
()
{
$this
->
assertEquals
(
BaseExtension
::
create
(
'a'
,
'b'
),
new
BaseExtension
(
'a'
,
'b'
));
$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'
,
array
(
'foo'
=>
'bar'
)),
'bar baz'
);
$this
->
assertEquals
(
webbasics\asprintf
(
'%(foo) baz %(foo)'
,
$this
->
assertEquals
(
webbasics\asprintf
(
'%(foo) baz %(foo)'
,
array
(
'foo'
=>
'bar'
)),
'bar baz bar'
);
array
(
'foo'
=>
'bar'
)),
'bar baz bar'
);
...
@@ -23,9 +23,9 @@ class BaseTest extends PHPUnit_Framework_TestCase {
...
@@ -23,9 +23,9 @@ class BaseTest extends PHPUnit_Framework_TestCase {
array
(
'foo'
=>
'bar'
,
'bar'
=>
'foobar'
)),
'foobar baz bar'
);
array
(
'foo'
=>
'bar'
,
'bar'
=>
'foobar'
)),
'foobar baz bar'
);
}
}
function
test
_path_with_s
lash
()
{
function
test
PathWithS
lash
()
{
$this
->
assertEquals
(
Base
::
path
_with_s
lash
(
'dirname'
),
'dirname/'
);
$this
->
assertEquals
(
Base
::
path
WithS
lash
(
'dirname'
),
'dirname/'
);
$this
->
assertEquals
(
Base
::
path
_with_s
lash
(
'dirname/'
),
'dirname/'
);
$this
->
assertEquals
(
Base
::
path
WithS
lash
(
'dirname/'
),
'dirname/'
);
}
}
}
}
...
...
tests/test_collection.php
View file @
3566402f
...
@@ -11,11 +11,11 @@ class IdObject {
...
@@ -11,11 +11,11 @@ class IdObject {
$this
->
foo
=
$foo
;
$this
->
foo
=
$foo
;
}
}
function
get
_i
d
()
{
function
get
I
d
()
{
return
$this
->
id
;
return
$this
->
id
;
}
}
static
function
clear
_c
ounter
()
{
static
function
clear
C
ounter
()
{
self
::
$count
=
0
;
self
::
$count
=
0
;
}
}
}
}
...
@@ -39,7 +39,7 @@ class CollectionTest extends PHPUnit_Framework_TestCase {
...
@@ -39,7 +39,7 @@ class CollectionTest extends PHPUnit_Framework_TestCase {
$this
->
set
=
set
(
array
(
1
,
2
));
$this
->
set
=
set
(
array
(
1
,
2
));
}
}
function
test
_a
dd
()
{
function
test
A
dd
()
{
$this
->
set
->
add
(
3
);
$this
->
set
->
add
(
3
);
$this
->
assertEquals
(
$this
->
set
,
set
(
array
(
1
,
2
,
3
)));
$this
->
assertEquals
(
$this
->
set
,
set
(
array
(
1
,
2
,
3
)));
}
}
...
@@ -47,18 +47,18 @@ class CollectionTest extends PHPUnit_Framework_TestCase {
...
@@ -47,18 +47,18 @@ class CollectionTest extends PHPUnit_Framework_TestCase {
/**
/**
* @expectedException InvalidArgumentException
* @expectedException InvalidArgumentException
*/
*/
function
test
_insert_e
rror
()
{
function
test
InsertE
rror
()
{
set
(
array
(
'foo'
=>
1
))
->
insert
(
2
,
'foo'
);
set
(
array
(
'foo'
=>
1
))
->
insert
(
2
,
'foo'
);
}
}
function
test
_insert_s
uccess
()
{
function
test
InsertS
uccess
()
{
$this
->
set
->
insert
(
4
,
1
);
$this
->
set
->
insert
(
4
,
1
);
$this
->
assertEquals
(
$this
->
set
,
set
(
array
(
1
,
4
,
2
)));
$this
->
assertEquals
(
$this
->
set
,
set
(
array
(
1
,
4
,
2
)));
$this
->
set
->
insert
(
5
,
0
);
$this
->
set
->
insert
(
5
,
0
);
$this
->
assertEquals
(
$this
->
set
,
set
(
array
(
5
,
1
,
4
,
2
)));
$this
->
assertEquals
(
$this
->
set
,
set
(
array
(
5
,
1
,
4
,
2
)));
}
}
function
test
_a
ll
()
{
function
test
A
ll
()
{
$this
->
assertEquals
(
set
()
->
all
(),
array
());
$this
->
assertEquals
(
set
()
->
all
(),
array
());
$this
->
assertEquals
(
set
(
array
())
->
all
(),
array
());
$this
->
assertEquals
(
set
(
array
())
->
all
(),
array
());
$this
->
assertEquals
(
set
(
array
(
1
))
->
all
(),
array
(
1
));
$this
->
assertEquals
(
set
(
array
(
1
))
->
all
(),
array
(
1
));
...
@@ -68,108 +68,108 @@ class CollectionTest extends PHPUnit_Framework_TestCase {
...
@@ -68,108 +68,108 @@ class CollectionTest extends PHPUnit_Framework_TestCase {
/**
/**
* @expectedException OutOfBoundsException
* @expectedException OutOfBoundsException
*/
*/
function
test
_last_e
mpty
()
{
function
test
LastE
mpty
()
{
set
()
->
last
();
set
()
->
last
();
}
}
function
test
_l
ast
()
{
function
test
L
ast
()
{
$this
->
assertEquals
(
$this
->
set
->
last
(),
2
);
$this
->
assertEquals
(
$this
->
set
->
last
(),
2
);
}
}
/**
/**
* @expectedException OutOfBoundsException
* @expectedException OutOfBoundsException
*/
*/
function
test
_first_e
mpty
()
{
function
test
FirstE
mpty
()
{
set
()
->
first
();
set
()
->
first
();
}
}
function
test
_f
irst
()
{
function
test
F
irst
()
{
$this
->
assertEquals
(
$this
->
set
->
first
(),
1
);
$this
->
assertEquals
(
$this
->
set
->
first
(),
1
);
}
}
function
test
_c
ount
()
{
function
test
C
ount
()
{
$this
->
assertEquals
(
set
()
->
count
(),
0
);
$this
->
assertEquals
(
set
()
->
count
(),
0
);
$this
->
assertEquals
(
set
(
array
())
->
count
(),
0
);
$this
->
assertEquals
(
set
(
array
())
->
count
(),
0
);
$this
->
assertEquals
(
set
(
array
(
1
))
->
count
(),
1
);
$this
->
assertEquals
(
set
(
array
(
1
))
->
count
(),
1
);
$this
->
assertEquals
(
set
(
array
(
1
,
2
))
->
count
(),
2
);
$this
->
assertEquals
(
set
(
array
(
1
,
2
))
->
count
(),
2
);
}
}
function
test
_index_e
xists
()
{
function
test
IndexE
xists
()
{
$this
->
assertTrue
(
$this
->
set
->
index
_e
xists
(
1
));
$this
->
assertTrue
(
$this
->
set
->
index
E
xists
(
1
));
$this
->
assertTrue
(
set
(
array
(
'foo'
=>
'bar'
))
->
index
_e
xists
(
'foo'
));
$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
(
0
),
1
);
$this
->
assertEquals
(
$this
->
set
->
get
(
1
),
2
);
$this
->
assertEquals
(
$this
->
set
->
get
(
1
),
2
);
$this
->
assertEquals
(
set
(
array
(
'foo'
=>
'bar'
))
->
get
(
'foo'
),
'bar'
);
$this
->
assertEquals
(
set
(
array
(
'foo'
=>
'bar'
))
->
get
(
'foo'
),
'bar'
);
}
}
function
test
_delete_i
ndex
()
{
function
test
DeleteI
ndex
()
{
$this
->
set
->
delete
_i
ndex
(
0
);
$this
->
set
->
delete
I
ndex
(
0
);
$this
->
assertEquals
(
$this
->
set
,
set
(
array
(
1
=>
2
)));
$this
->
assertEquals
(
$this
->
set
,
set
(
array
(
1
=>
2
)));
}
}
function
test
_d
elete
()
{
function
test
D
elete
()
{
$this
->
set
->
delete
(
1
);
$this
->
set
->
delete
(
1
);
$this
->
assertEquals
(
$this
->
set
,
set
(
array
(
1
=>
2
)));
$this
->
assertEquals
(
$this
->
set
,
set
(
array
(
1
=>
2
)));
}
}
function
assert
_set_e
quals
(
array
$expected_items
,
$set
)
{
function
assert
SetE
quals
(
array
$expected_items
,
$set
)
{
$this
->
assertAttributeEquals
(
$expected_items
,
'items'
,
$set
);
$this
->
assertAttributeEquals
(
$expected_items
,
'items'
,
$set
);
}
}
function
test
_u
niques
()
{
function
test
U
niques
()
{
$this
->
assert
_set_e
quals
(
array
(
1
,
2
),
set
(
array
(
1
,
2
,
2
))
->
uniques
());
$this
->
assert
SetE
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
SetE
quals
(
array
(
2
,
1
),
set
(
array
(
2
,
1
,
2
))
->
uniques
());
$this
->
assert
_set_e
quals
(
array
(
2
,
1
),
set
(
array
(
2
,
2
,
1
))
->
uniques
());
$this
->
assert
SetE
quals
(
array
(
2
,
1
),
set
(
array
(
2
,
2
,
1
))
->
uniques
());
}
}
function
set
_i
tems
(
$collection
,
$items
,
$clone
)
{
function
set
I
tems
(
$collection
,
$items
,
$clone
)
{
$rm
=
new
ReflectionMethod
(
$collection
,
'set
_i
tems'
);
$rm
=
new
ReflectionMethod
(
$collection
,
'set
I
tems'
);
$rm
->
setAccessible
(
true
);
$rm
->
setAccessible
(
true
);
return
$rm
->
invoke
(
$collection
,
$items
,
$clone
);
return
$rm
->
invoke
(
$collection
,
$items
,
$clone
);
}
}
function
test
_set_items_c
lone
()
{
function
test
SetItemsC
lone
()
{
$result
=
$this
->
set
_i
tems
(
$this
->
set
,
array
(
3
,
4
),
true
);
$result
=
$this
->
set
I
tems
(
$this
->
set
,
array
(
3
,
4
),
true
);
$this
->
assert
_set_e
quals
(
array
(
1
,
2
),
$this
->
set
);
$this
->
assert
SetE
quals
(
array
(
1
,
2
),
$this
->
set
);
$this
->
assert
_set_e
quals
(
array
(
3
,
4
),
$result
);
$this
->
assert
SetE
quals
(
array
(
3
,
4
),
$result
);
$this
->
assertNotSame
(
$this
->
set
,
$result
);
$this
->
assertNotSame
(
$this
->
set
,
$result
);
}
}
function
test
_set_items_no_c
lone
()
{
function
test
SetItemsNoC
lone
()
{
$result
=
$this
->
set
_i
tems
(
$this
->
set
,
array
(
3
,
4
),
false
);
$result
=
$this
->
set
I
tems
(
$this
->
set
,
array
(
3
,
4
),
false
);
$this
->
assertSame
(
$this
->
set
,
$result
);
$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
;
};
$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
(
$items
=
array
(
array
(
'foo'
=>
'bar'
,
'bar'
=>
'baz'
),
array
(
'foo'
=>
'bar'
,
'bar'
=>
'baz'
),
array
(
'foo'
=>
'baz'
,
'bar'
=>
'foo'
),
array
(
'foo'
=>
'baz'
,
'bar'
=>
'foo'
),
std_object
(
array
(
'foo'
=>
'bar'
,
'baz'
=>
'bar'
)),
std_object
(
array
(
'foo'
=>
'bar'
,
'baz'
=>
'bar'
)),
);
);
$this
->
assert
_set_e
quals
(
array
(
$items
[
1
]),
set
(
$items
)
->
find
(
array
(
'foo'
=>
'baz'
)));
$this
->
assert
SetE
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
[
0
],
$items
[
2
]),
set
(
$items
)
->
find
(
array
(
'foo'
=>
'bar'
)));
}
}
/**
/**
* @depends test
_find_s
uccess
* @depends test
FindS
uccess
* @expectedException \UnexpectedValueException
* @expectedException \UnexpectedValueException
* @expectedExceptionMessage Collection::find encountered a non-object and non-array item "foobar".
* @expectedExceptionMessage Collection::find encountered a non-object and non-array item "foobar".
*/
*/
function
test
_find_f
ailure
()
{
function
test
FindF
ailure
()
{
$items
=
array
(
$items
=
array
(
array
(
'foo'
=>
'bar'
,
'bar'
=>
'baz'
),
array
(
'foo'
=>
'bar'
,
'bar'
=>
'baz'
),
'foobar'
,
'foobar'
,
...
@@ -177,47 +177,47 @@ class CollectionTest extends PHPUnit_Framework_TestCase {
...
@@ -177,47 +177,47 @@ class CollectionTest extends PHPUnit_Framework_TestCase {
set
(
$items
)
->
find
(
array
(
'foo'
=>
'bar'
));
set
(
$items
)
->
find
(
array
(
'foo'
=>
'bar'
));
}
}
function
test
_get_attribute_s
imple
()
{
function
test
GetAttributeS
imple
()
{
IdObject
::
clear
_c
ounter
();
IdObject
::
clear
C
ounter
();
$set
=
set
(
array
(
new
IdObject
(),
new
IdObject
(),
new
IdObject
()));
$set
=
set
(
array
(
new
IdObject
(),
new
IdObject
(),
new
IdObject
()));
$this
->
assertEquals
(
array
(
1
,
2
,
3
),
$set
->
get
_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
()
{
function
test
GetAttributeI
ndices
()
{
IdObject
::
clear
_c
ounter
();
IdObject
::
clear
C
ounter
();
$set
=
set
(
array
(
'foo'
=>
new
IdObject
(),
'bar'
=>
new
IdObject
(),
'baz'
=>
new
IdObject
()));
$set
=
set
(
array
(
'foo'
=>
new
IdObject
(),
'bar'
=>
new
IdObject
(),
'baz'
=>
new
IdObject
()));
$this
->
assertEquals
(
array
(
'foo'
=>
1
,
'bar'
=>
2
,
'baz'
=>
3
),
$set
->
get
_a
ttribute
(
'id'
));
$this
->
assertEquals
(
array
(
'foo'
=>
1
,
'bar'
=>
2
,
'baz'
=>
3
),
$set
->
get
A
ttribute
(
'id'
));
}
}
/**
/**
* @depends test
_a
ll
* @depends test
A
ll
* @depends test
_set_items_c
lone
* @depends test
SetItemsC
lone
*/
*/
function
test
_index_b
y
()
{
function
test
IndexB
y
()
{
IdObject
::
clear
_c
ounter
();
IdObject
::
clear
C
ounter
();
$set
=
set
(
array
(
new
IdObject
(
'foo'
),
new
IdObject
(
'bar'
),
new
IdObject
(
'baz'
)));
$set
=
set
(
array
(
new
IdObject
(
'foo'
),
new
IdObject
(
'bar'
),
new
IdObject
(
'baz'
)));
list
(
$foo
,
$bar
,
$baz
)
=
$set
->
all
();
list
(
$foo
,
$bar
,
$baz
)
=
$set
->
all
();
$this
->
assert
_set_equals
(
array
(
'foo'
=>
$foo
,
'bar'
=>
$bar
,
'baz'
=>
$baz
),
$set
->
index_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
;
};
$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
()
{
function
test
MapM
ethod
()
{
IdObject
::
clear
_c
ounter
();
IdObject
::
clear
C
ounter
();
$set
=
set
(
array
(
new
IdObject
(),
new
IdObject
(),
new
IdObject
()));
$set
=
set
(
array
(
new
IdObject
(),
new
IdObject
(),
new
IdObject
()));
$this
->
assert
_set_equals
(
array
(
1
,
2
,
3
),
$set
->
map_method
(
'get_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');
...
@@ -11,138 +11,138 @@ define('LOGFILE', 'build/temp.log');
class
LoggerTest
extends
PHPUnit_Extensions_OutputTestCase
{
class
LoggerTest
extends
PHPUnit_Extensions_OutputTestCase
{
function
setUp
()
{
function
setUp
()
{
$this
->
logger
=
new
Logger
();
$this
->
logger
=
new
Logger
();
$this
->
logger
->
set
_p
roperty
(
'name'
,
NAME
);
$this
->
logger
->
set
P
roperty
(
'name'
,
NAME
);
$this
->
logger
->
set
_f
ormat
(
FORMAT
);
$this
->
logger
->
set
F
ormat
(
FORMAT
);
is_dir
(
'build'
)
||
mkdir
(
'build'
);
is_dir
(
'build'
)
||
mkdir
(
'build'
);
}
}
function
assert
_d
umps
(
$expected
)
{
function
assert
D
umps
(
$expected
)
{
$this
->
assertEquals
(
$this
->
logger
->
dumps
(),
$expected
);
$this
->
assertEquals
(
$this
->
logger
->
dumps
(),
$expected
);
}
}
function
test
_set_d
irectory
()
{
function
test
SetD
irectory
()
{
$this
->
logger
->
set
_d
irectory
(
'logs'
);
$this
->
logger
->
set
D
irectory
(
'logs'
);
$this
->
assertAttributeEquals
(
'logs/'
,
'log_directory'
,
$this
->
logger
);
$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
);
$this
->
assertAttributeEquals
(
'logs/'
,
'log_directory'
,
$this
->
logger
);
}
}
function
test
_set_f
ormat
()
{
function
test
SetF
ormat
()
{
$this
->
logger
->
set
_f
ormat
(
'foo'
);
$this
->
logger
->
set
F
ormat
(
'foo'
);
$this
->
assertAttributeEquals
(
'foo'
,
'format'
,
$this
->
logger
);
$this
->
assertAttributeEquals
(
'foo'
,
'format'
,
$this
->
logger
);
}
}
function
test
_set_dump_format_s
uccess
()
{
function
test
SetDumpFormatS
uccess
()
{
$this
->
logger
->
set
_dump_f
ormat
(
'html'
);
$this
->
logger
->
set
DumpF
ormat
(
'html'
);
$this
->
assertAttributeEquals
(
'html'
,
'dump_format'
,
$this
->
logger
);
$this
->
assertAttributeEquals
(
'html'
,
'dump_format'
,
$this
->
logger
);
}
}
/**
/**
* @expectedException InvalidArgumentException
* @expectedException InvalidArgumentException
*/
*/
function
test
_set_dump_format_f
ailure
()
{
function
test
SetDumpFormatF
ailure
()
{
$this
->
logger
->
set
_dump_f
ormat
(
'foo'
);
$this
->
logger
->
set
DumpF
ormat
(
'foo'
);
}
}
function
test
_get_f
ormat
()
{
function
test
GetF
ormat
()
{
$this
->
assertEquals
(
$this
->
logger
->
get
_f
ormat
(),
FORMAT
);
$this
->
assertEquals
(
$this
->
logger
->
get
F
ormat
(),
FORMAT
);
}
}
function
test
_get_l
evel
()
{
function
test
GetL
evel
()
{
$this
->
assertEquals
(
$this
->
logger
->
get
_l
evel
(),
Logger
::
WARNING
);
$this
->
assertEquals
(
$this
->
logger
->
get
L
evel
(),
Logger
::
WARNING
);
$this
->
assertEquals
(
$this
->
logger
->
get
_level_n
ame
(),
'WARNING'
);
$this
->
assertEquals
(
$this
->
logger
->
get
LevelN
ame
(),
'WARNING'
);
}
}
/**
/**
* @depends test
_get_l
evel
* @depends test
GetL
evel
*/
*/
function
test
_set_l
evel
()
{
function
test
SetL
evel
()
{
$this
->
logger
->
set
_l
evel
(
'info'
);
$this
->
logger
->
set
L
evel
(
'info'
);
$this
->
assertEquals
(
$this
->
logger
->
get
_l
evel
(),
Logger
::
INFO
);
$this
->
assertEquals
(
$this
->
logger
->
get
L
evel
(),
Logger
::
INFO
);
$this
->
logger
->
set
_l
evel
(
'DEBUG'
);
$this
->
logger
->
set
L
evel
(
'DEBUG'
);
$this
->
assertEquals
(
$this
->
logger
->
get
_l
evel
(),
Logger
::
DEBUG
);
$this
->
assertEquals
(
$this
->
logger
->
get
L
evel
(),
Logger
::
DEBUG
);
$this
->
logger
->
set
_l
evel
(
'WaRnInG'
);
$this
->
logger
->
set
L
evel
(
'WaRnInG'
);
$this
->
assertEquals
(
$this
->
logger
->
get
_l
evel
(),
Logger
::
WARNING
);
$this
->
assertEquals
(
$this
->
logger
->
get
L
evel
(),
Logger
::
WARNING
);
$this
->
logger
->
set
_l
evel
(
Logger
::
ERROR
);
$this
->
logger
->
set
L
evel
(
Logger
::
ERROR
);
$this
->
assertEquals
(
$this
->
logger
->
get
_l
evel
(),
Logger
::
ERROR
);
$this
->
assertEquals
(
$this
->
logger
->
get
L
evel
(),
Logger
::
ERROR
);
}
}
function
test
_f
ormat
()
{
function
test
F
ormat
()
{
$this
->
logger
->
error
(
'test message'
);
$this
->
logger
->
error
(
'test message'
);
$this
->
assert
_d
umps
(
'ERROR: test message'
);
$this
->
assert
D
umps
(
'ERROR: test message'
);
}
}
function
test
_set_p
roperty
()
{
function
test
SetP
roperty
()
{
$this
->
logger
->
set
_p
roperty
(
'name'
,
'Logger'
);
$this
->
logger
->
set
P
roperty
(
'name'
,
'Logger'
);
$this
->
assertEquals
(
$this
->
logger
->
get
_formatted_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
->
warning
(
'test message'
);
$this
->
logger
->
clear
();
$this
->
logger
->
clear
();
$this
->
assert
_d
umps
(
''
);
$this
->
assert
D
umps
(
''
);
}
}
/**
/**
* @depends test
_set_l
evel
* @depends test
SetL
evel
* @depends test
_c
lear
* @depends test
C
lear
*/
*/
function
test
_process_l
evel
()
{
function
test
ProcessL
evel
()
{
$this
->
logger
->
info
(
'test message'
);
$this
->
logger
->
info
(
'test message'
);
$this
->
assert
_d
umps
(
''
);
$this
->
assert
D
umps
(
''
);
$this
->
logger
->
warning
(
'test message'
);
$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
->
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
->
clear
();
$this
->
logger
->
set
_l
evel
(
'debug'
);
$this
->
logger
->
set
L
evel
(
'debug'
);
$this
->
logger
->
debug
(
'test message'
);
$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
()
{
function
test
GetFormattedP
roperty
()
{
$this
->
assertEquals
(
$this
->
logger
->
get
_formatted_p
roperty
(
'name'
),
NAME
);
$this
->
assertEquals
(
$this
->
logger
->
get
FormattedP
roperty
(
'name'
),
NAME
);
$this
->
assertEquals
(
$this
->
logger
->
get
_formatted_p
roperty
(
'loglevel'
),
'WARNING'
);
$this
->
assertEquals
(
$this
->
logger
->
get
FormattedP
roperty
(
'loglevel'
),
'WARNING'
);
$this
->
assertRegExp
(
'/^\d{2}-\d{2}-\d{4}$/'
,
$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
->
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
->
assertRegExp
(
'/^\d{2}:\d{2}:\d{2}$/'
,
$this
->
logger
->
get
_formatted_p
roperty
(
'time'
));
$this
->
logger
->
get
FormattedP
roperty
(
'time'
));
$this
->
setExpectedException
(
'\InvalidArgumentException'
);
$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
->
warning
(
'test message'
);
$this
->
logger
->
set
_f
ormat
(
'%(name): %(level): %(message)'
);
$this
->
logger
->
set
F
ormat
(
'%(name): %(level): %(message)'
);
$this
->
assert
_d
umps
(
NAME
.
': WARNING: test 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
->
logger
->
warning
(
'test message'
);
$this
->
expectOutputString
(
'WARNING: test message'
);
$this
->
expectOutputString
(
'WARNING: test message'
);
$this
->
logger
->
dump
();
$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
->
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
->
expectOutputString
(
'<strong>Log:</strong><br /><pre>WARNING: test message</pre>'
);
$this
->
logger
->
dump
();
$this
->
logger
->
dump
();
}
}
function
test
_s
ave
()
{
function
test
S
ave
()
{
$this
->
logger
->
warning
(
'test message'
);
$this
->
logger
->
warning
(
'test message'
);
$this
->
logger
->
save
(
LOGFILE
);
$this
->
logger
->
save
(
LOGFILE
);
$this
->
assertStringEqualsFile
(
LOGFILE
,
'WARNING: test message'
);
$this
->
assertStringEqualsFile
(
LOGFILE
,
'WARNING: test message'
);
...
@@ -152,30 +152,30 @@ class LoggerTest extends PHPUnit_Extensions_OutputTestCase {
...
@@ -152,30 +152,30 @@ class LoggerTest extends PHPUnit_Extensions_OutputTestCase {
unlink
(
LOGFILE
);
unlink
(
LOGFILE
);
}
}
function
find
_l
ogfile
()
{
function
find
L
ogfile
()
{
$files
=
scandir
(
LOGDIR
);
$files
=
scandir
(
LOGDIR
);
$this
->
assertEquals
(
3
,
count
(
$files
));
$this
->
assertEquals
(
3
,
count
(
$files
));
return
$files
[
2
];
return
$files
[
2
];
}
}
/**
/**
* @depends test
_s
ave
* @depends test
S
ave
*/
*/
function
test
_dump_file_r
egular
()
{
function
test
DumpFileR
egular
()
{
$this
->
logger
->
set
_d
irectory
(
LOGDIR
);
$this
->
logger
->
set
D
irectory
(
LOGDIR
);
$this
->
logger
->
set
_dump_f
ormat
(
'file'
);
$this
->
logger
->
set
DumpF
ormat
(
'file'
);
$this
->
logger
->
warning
(
'test message'
);
$this
->
logger
->
warning
(
'test message'
);
$this
->
logger
->
dump
();
$this
->
logger
->
dump
();
$filename
=
$this
->
find
_l
ogfile
();
$filename
=
$this
->
find
L
ogfile
();
$this
->
assertStringEqualsFile
(
LOGDIR
.
$filename
,
'WARNING: test message'
);
$this
->
assertStringEqualsFile
(
LOGDIR
.
$filename
,
'WARNING: test message'
);
unlink
(
LOGDIR
.
$filename
);
unlink
(
LOGDIR
.
$filename
);
$this
->
assertRegExp
(
'/^log_\d{2}-\d{2}-\d{4}_\d{2}-\d{2}-\d{2}.log$/'
,
$filename
);
$this
->
assertRegExp
(
'/^log_\d{2}-\d{2}-\d{4}_\d{2}-\d{2}-\d{2}.log$/'
,
$filename
);
}
}
function
test
_handle_e
xception
()
{
function
test
HandleE
xception
()
{
$this
->
logger
->
set
_dump_f
ormat
(
'none'
);
$this
->
logger
->
set
DumpF
ormat
(
'none'
);
$this
->
logger
->
handle
_e
xception
(
new
RuntimeException
(
'test message'
));
$this
->
logger
->
handle
E
xception
(
new
RuntimeException
(
'test message'
));
$this
->
assertNotEquals
(
$this
->
logger
->
dumps
(),
''
);
$this
->
assertNotEquals
(
$this
->
logger
->
dumps
(),
''
);
}
}
}
}
...
...
tests/test_node.php
View file @
3566402f
...
@@ -10,90 +10,90 @@ class NodeTest extends PHPUnit_Framework_TestCase {
...
@@ -10,90 +10,90 @@ class NodeTest extends PHPUnit_Framework_TestCase {
$this
->
root
=
new
Node
(
'test node'
);
$this
->
root
=
new
Node
(
'test node'
);
}
}
function
test
_get_i
d
()
{
function
test
GetI
d
()
{
$this
->
assertEquals
(
$this
->
root
->
get
_i
d
(),
1
);
$this
->
assertEquals
(
$this
->
root
->
get
I
d
(),
1
);
$this
->
assertEquals
(
Node
::
create
(
''
)
->
get
_i
d
(),
2
);
$this
->
assertEquals
(
Node
::
create
(
''
)
->
get
I
d
(),
2
);
}
}
function
test
_get_n
ame
()
{
function
test
GetN
ame
()
{
$this
->
assertEquals
(
$this
->
root
->
get
_n
ame
(),
'test node'
);
$this
->
assertEquals
(
$this
->
root
->
get
N
ame
(),
'test node'
);
$this
->
assertEquals
(
Node
::
create
(
'second node'
)
->
get
_n
ame
(),
'second node'
);
$this
->
assertEquals
(
Node
::
create
(
'second node'
)
->
get
N
ame
(),
'second node'
);
}
}
function
test
_get_p
arent
()
{
function
test
GetP
arent
()
{
$this
->
assertNull
(
$this
->
root
->
get
_p
arent
());
$this
->
assertNull
(
$this
->
root
->
get
P
arent
());
$this
->
assertSame
(
Node
::
create
(
''
,
$this
->
root
)
->
get
_p
arent
(),
$this
->
root
);
$this
->
assertSame
(
Node
::
create
(
''
,
$this
->
root
)
->
get
P
arent
(),
$this
->
root
);
}
}
function
test
_i
s
()
{
function
test
I
s
()
{
$mirror
=
$this
->
root
;
$mirror
=
$this
->
root
;
$this
->
assertTrue
(
$mirror
->
is
(
$this
->
root
));
$this
->
assertTrue
(
$mirror
->
is
(
$this
->
root
));
$this
->
assertFalse
(
Node
::
create
(
''
)
->
is
(
$this
->
root
));
$this
->
assertFalse
(
Node
::
create
(
''
)
->
is
(
$this
->
root
));
}
}
function
test
_is_r
oot
()
{
function
test
IsR
oot
()
{
$this
->
assertTrue
(
$this
->
root
->
is
_r
oot
());
$this
->
assertTrue
(
$this
->
root
->
is
R
oot
());
$this
->
assertFalse
(
Node
::
create
(
''
,
$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
(
''
);
$node
=
new
Node
(
''
);
$this
->
root
->
add
_c
hild
(
$node
);
$this
->
root
->
add
C
hild
(
$node
);
$this
->
assertAttributeEquals
(
array
(
$node
),
'children'
,
$this
->
root
);
$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
()
{
function
test
GetC
hildren
()
{
$this
->
assertEquals
(
$this
->
root
->
get
_c
hildren
(),
array
());
$this
->
assertEquals
(
$this
->
root
->
get
C
hildren
(),
array
());
$node
=
new
Node
(
''
);
$node
=
new
Node
(
''
);
$this
->
root
->
add
_c
hild
(
$node
);
$this
->
root
->
add
C
hild
(
$node
);
$this
->
assertSame
(
$this
->
root
->
get
_c
hildren
(),
array
(
$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
(
''
);
$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
->
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
(
''
);
$node
=
new
Node
(
''
);
$this
->
root
->
add
_c
hild
(
$node
);
$this
->
root
->
add
C
hild
(
$node
);
$this
->
assertTrue
(
$node
->
is
_l
eaf
());
$this
->
assertTrue
(
$node
->
is
L
eaf
());
$this
->
assertFalse
(
$this
->
root
->
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'
));
$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
->
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'
));
$node1
=
$this
->
root
->
add
(
'name'
,
array
(
'foo'
=>
'bar'
));
$node2
=
$this
->
root
->
add
(
'name'
,
array
(
'foo'
=>
'bar'
));
$node2
=
$this
->
root
->
add
(
'name'
,
array
(
'foo'
=>
'bar'
));
$this
->
root
->
remove
_c
hild
(
$node2
);
$this
->
root
->
remove
C
hild
(
$node2
);
$this
->
assertAttributeSame
(
array
(
$node1
),
'children'
,
$this
->
root
);
$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'
));
$node1
=
$this
->
root
->
add
(
'name'
,
array
(
'foo'
=>
'bar'
));
$node2
=
$this
->
root
->
add
(
'name'
,
array
(
'foo'
=>
'bar'
));
$node2
=
$this
->
root
->
add
(
'name'
,
array
(
'foo'
=>
'bar'
));
$node1
->
remove
();
$node1
->
remove
();
...
@@ -101,39 +101,39 @@ class NodeTest extends PHPUnit_Framework_TestCase {
...
@@ -101,39 +101,39 @@ class NodeTest extends PHPUnit_Framework_TestCase {
}
}
/**
/**
* @depends test
_remove_l
eaf
* @depends test
RemoveL
eaf
*/
*/
function
test
_remove_n
ode
()
{
function
test
RemoveN
ode
()
{
$node
=
$this
->
root
->
add
(
'node'
);
$node
=
$this
->
root
->
add
(
'node'
);
$leaf
=
$node
->
add
(
'leaf'
);
$leaf
=
$node
->
add
(
'leaf'
);
$node
->
remove
();
$node
->
remove
();
$this
->
assertAttributeEquals
(
array
(),
'children'
,
$this
->
root
);
$this
->
assertAttributeEquals
(
array
(),
'children'
,
$this
->
root
);
$this
->
assertNull
(
$leaf
->
get
_p
arent
());
$this
->
assertNull
(
$leaf
->
get
P
arent
());
}
}
/**
/**
* @depends test
_remove_c
hild
* @depends test
RemoveC
hild
* @expectedException \RuntimeException
* @expectedException \RuntimeException
*/
*/
function
test
_remove_r
oot
()
{
function
test
RemoveR
oot
()
{
$node1
=
$this
->
root
->
add
(
'name'
,
array
(
'foo'
=>
'bar'
));
$node1
=
$this
->
root
->
add
(
'name'
,
array
(
'foo'
=>
'bar'
));
$node2
=
$this
->
root
->
add
(
'name'
,
array
(
'foo'
=>
'bar'
));
$node2
=
$this
->
root
->
add
(
'name'
,
array
(
'foo'
=>
'bar'
));
$this
->
root
->
remove
();
$this
->
root
->
remove
();
$this
->
assertAttributeSame
(
array
(
$node2
),
'children'
,
$this
->
root
);
$this
->
assertAttributeSame
(
array
(
$node2
),
'children'
,
$this
->
root
);
}
}
function
test
_set_s
ingle
()
{
function
test
SetS
ingle
()
{
$this
->
root
->
set
(
'foo'
,
'bar'
);
$this
->
root
->
set
(
'foo'
,
'bar'
);
$this
->
assertAttributeEquals
(
array
(
'foo'
=>
'bar'
),
'variables'
,
$this
->
root
);
$this
->
assertAttributeEquals
(
array
(
'foo'
=>
'bar'
),
'variables'
,
$this
->
root
);
$this
->
root
->
set
(
'bar'
,
'baz'
);
$this
->
root
->
set
(
'bar'
,
'baz'
);
$this
->
assertAttributeEquals
(
array
(
'foo'
=>
'bar'
,
'bar'
=>
'baz'
),
'variables'
,
$this
->
root
);
$this
->
assertAttributeEquals
(
array
(
'foo'
=>
'bar'
,
'bar'
=>
'baz'
),
'variables'
,
$this
->
root
);
}
}
function
test
_set_r
eturn
()
{
function
test
SetR
eturn
()
{
$this
->
assertSame
(
$this
->
root
->
set
(
'foo'
,
'bar'
),
$this
->
root
);
$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
->
root
->
set
(
array
(
'foo'
=>
'bar'
));
$this
->
assertAttributeEquals
(
array
(
'foo'
=>
'bar'
),
'variables'
,
$this
->
root
);
$this
->
assertAttributeEquals
(
array
(
'foo'
=>
'bar'
),
'variables'
,
$this
->
root
);
$this
->
root
->
set
(
array
(
'bar'
=>
'baz'
));
$this
->
root
->
set
(
array
(
'bar'
=>
'baz'
));
...
@@ -141,7 +141,7 @@ class NodeTest extends PHPUnit_Framework_TestCase {
...
@@ -141,7 +141,7 @@ class NodeTest extends PHPUnit_Framework_TestCase {
}
}
/**
/**
* @depends test
_set_s
ingle
* @depends test
SetS
ingle
*/
*/
function
test___set
()
{
function
test___set
()
{
$this
->
root
->
foo
=
'bar'
;
$this
->
root
->
foo
=
'bar'
;
...
@@ -151,16 +151,16 @@ class NodeTest extends PHPUnit_Framework_TestCase {
...
@@ -151,16 +151,16 @@ class NodeTest extends PHPUnit_Framework_TestCase {
}
}
/**
/**
* @depends test
_set_m
ultiple
* @depends test
SetM
ultiple
*/
*/
function
test
_get_d
irect
()
{
function
test
GetD
irect
()
{
$this
->
root
->
set
(
array
(
'foo'
=>
'bar'
,
'bar'
=>
'baz'
));
$this
->
root
->
set
(
array
(
'foo'
=>
'bar'
,
'bar'
=>
'baz'
));
$this
->
assertEquals
(
$this
->
root
->
get
(
'foo'
),
'bar'
);
$this
->
assertEquals
(
$this
->
root
->
get
(
'foo'
),
'bar'
);
$this
->
assertEquals
(
$this
->
root
->
get
(
'bar'
),
'baz'
);
$this
->
assertEquals
(
$this
->
root
->
get
(
'bar'
),
'baz'
);
}
}
/**
/**
* @depends test
_get_d
irect
* @depends test
GetD
irect
*/
*/
function
test___get
()
{
function
test___get
()
{
$this
->
root
->
set
(
array
(
'foo'
=>
'bar'
,
'bar'
=>
'baz'
));
$this
->
root
->
set
(
array
(
'foo'
=>
'bar'
,
'bar'
=>
'baz'
));
...
@@ -169,22 +169,22 @@ class NodeTest extends PHPUnit_Framework_TestCase {
...
@@ -169,22 +169,22 @@ class NodeTest extends PHPUnit_Framework_TestCase {
}
}
/**
/**
* @depends test
_set_s
ingle
* @depends test
SetS
ingle
*/
*/
function
test
_get_a
ncestor
()
{
function
test
GetA
ncestor
()
{
$this
->
root
->
set
(
'foo'
,
'bar'
);
$this
->
root
->
set
(
'foo'
,
'bar'
);
$node
=
$this
->
root
->
add
(
''
);
$node
=
$this
->
root
->
add
(
''
);
$this
->
assertEquals
(
$node
->
get
(
'foo'
),
'bar'
);
$this
->
assertEquals
(
$node
->
get
(
'foo'
),
'bar'
);
}
}
function
test
_get_f
ailure
()
{
function
test
GetF
ailure
()
{
$this
->
assertNull
(
$this
->
root
->
get
(
'foo'
));
$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'
);
$node1
=
$this
->
root
->
add
(
'foo'
);
$node2
=
$this
->
root
->
add
(
'bar'
);
$node2
=
$this
->
root
->
add
(
'bar'
);
$node3
=
$this
->
root
->
add
(
'foo'
);
$node3
=
$this
->
root
->
add
(
'foo'
);
...
@@ -192,34 +192,34 @@ class NodeTest extends PHPUnit_Framework_TestCase {
...
@@ -192,34 +192,34 @@ class NodeTest extends PHPUnit_Framework_TestCase {
}
}
/**
/**
* @depends test
_set_m
ultiple
* @depends test
SetM
ultiple
*/
*/
function
test
_copy_s
imple
()
{
function
test
CopyS
imple
()
{
$copy
=
$this
->
root
->
copy
();
$copy
=
$this
->
root
->
copy
();
$this
->
assertEquals
(
$this
->
root
,
$copy
);
$this
->
assertEquals
(
$this
->
root
,
$copy
);
$this
->
assertNotSame
(
$this
->
root
,
$copy
);
$this
->
assertNotSame
(
$this
->
root
,
$copy
);
}
}
/**
/**
* @depends test
_copy_s
imple
* @depends test
CopyS
imple
*/
*/
function
test
_copy_s
hallow
()
{
function
test
CopyS
hallow
()
{
$child
=
$this
->
root
->
add
(
''
);
$child
=
$this
->
root
->
add
(
''
);
$copy
=
$this
->
root
->
copy
();
$copy
=
$this
->
root
->
copy
();
$this
->
assertAttributeSame
(
array
(
$child
),
'children'
,
$copy
);
$this
->
assertAttributeSame
(
array
(
$child
),
'children'
,
$copy
);
}
}
/**
/**
* @depends test
_get_c
hildren
* @depends test
GetC
hildren
* @depends test
_copy_s
imple
* @depends test
CopyS
imple
*/
*/
function
test
_copy_d
eep
()
{
function
test
CopyD
eep
()
{
$child
=
$this
->
root
->
add
(
'foo'
);
$child
=
$this
->
root
->
add
(
'foo'
);
$copy
=
$this
->
root
->
copy
(
true
);
$copy
=
$this
->
root
->
copy
(
true
);
$copy_children
=
$copy
->
get
_c
hildren
();
$copy_children
=
$copy
->
get
C
hildren
();
$child_copy
=
reset
(
$copy_children
);
$child_copy
=
reset
(
$copy_children
);
$this
->
assertNotSame
(
$copy_children
,
$this
->
root
->
get
_c
hildren
());
$this
->
assertNotSame
(
$copy_children
,
$this
->
root
->
get
C
hildren
());
$this
->
assertSame
(
$child_copy
->
get
_p
arent
(),
$copy
);
$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 {
...
@@ -24,29 +24,29 @@ class RouterTest extends PHPUnit_Framework_TestCase {
));
));
}
}
function
test
_call_handler_s
uccess
()
{
function
test
CallHandlerS
uccess
()
{
$this
->
assertEquals
(
true
,
$this
->
router
->
call
_h
andler
(
'foo'
));
$this
->
assertEquals
(
true
,
$this
->
router
->
call
H
andler
(
'foo'
));
$this
->
assertEquals
(
'bar'
,
$this
->
router
->
call
_h
andler
(
'bar'
));
$this
->
assertEquals
(
'bar'
,
$this
->
router
->
call
H
andler
(
'bar'
));
$this
->
assertEquals
(
'baz'
,
$this
->
router
->
call
_h
andler
(
'baz'
));
$this
->
assertEquals
(
'baz'
,
$this
->
router
->
call
H
andler
(
'baz'
));
$this
->
assertEquals
(
'barbaz'
,
$this
->
router
->
call
_h
andler
(
'bazbar'
));
$this
->
assertEquals
(
'barbaz'
,
$this
->
router
->
call
H
andler
(
'bazbar'
));
}
}
function
test
_call_handler_f
ailure
()
{
function
test
CallHandlerF
ailure
()
{
$this
->
assertFalse
(
$this
->
router
->
call
_h
andler
(
'barfoo'
));
$this
->
assertFalse
(
$this
->
router
->
call
H
andler
(
'barfoo'
));
}
}
function
test
_call_handler_s
kip
()
{
function
test
CallHandlerS
kip
()
{
$foo
=
'foo'
;
$foo
=
'foo'
;
$bar
=
function
()
use
(
&
$foo
)
{
$foo
=
'bar'
;
return
false
;
};
$bar
=
function
()
use
(
&
$foo
)
{
$foo
=
'bar'
;
return
false
;
};
$baz
=
function
()
{
return
;
};
$baz
=
function
()
{
return
;
};
$router
=
new
Router
(
array
(
'.*'
=>
$bar
,
'baz'
=>
$baz
));
$router
=
new
Router
(
array
(
'.*'
=>
$bar
,
'baz'
=>
$baz
));
$router
->
call
_h
andler
(
'baz'
);
$router
->
call
H
andler
(
'baz'
);
$this
->
assertEquals
(
'bar'
,
$foo
);
$this
->
assertEquals
(
'bar'
,
$foo
);
}
}
function
test
_add_r
oute
()
{
function
test
AddR
oute
()
{
$this
->
router
->
add
_r
oute
(
'(foobar)'
,
'test_handler_arg'
);
$this
->
router
->
add
R
oute
(
'(foobar)'
,
'test_handler_arg'
);
$this
->
assertEquals
(
'foobar'
,
$this
->
router
->
call
_h
andler
(
'foobar'
));
$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