Unittests
[
class tree: Unittests
] [
index: Unittests
] [
all elements
]
Todo List
Packages:
Console_Application
Console_Deamon
Console_Enviroment
Console_Exception
Example
Unittests
Source for file LoaderTest.php
Documentation is available at
LoaderTest.php
<?php
/**
* Console Library
*
* LICENSE
*
* "THE BEER-WARE LICENSE" (Revision 42):
* "Sven Strittmatter" <ausserirdisch@sven-space.de> wrote this file.
* As long as you retain this notice you can do whatever you want with
* this stuff. If we meet some day, and you think this stuff is worth it,
* you can buy me a beer in return.
*
* $Author$
* $Revisio$
*
*
@category
Console
*
@package
Unittests
*
@copyright
Copyright (c) 2009 Sven Strittmatter
*/
// Call Console_LoaderTest::main() if this source file is executed directly.
if
(
!
defined
(
'PHPUnit_MAIN_METHOD'
))
{
define
(
'PHPUnit_MAIN_METHOD'
,
'Console_LoaderTest::main'
)
;
}
/**
*
@see
TestHelper
*/
require_once
(
dirname
(
__FILE__
)
.
'/../TestHelper.php'
)
;
/**
*
@see
Console_Loader
*/
require_once
(
'Console/Loader.php'
)
;
/**
*
@category
Console
*
@package
Unittests
*
@copyright
Copyright (c) 2009 Sven Strittmatter
*/
class
Console_LoaderTest
extends
PHPUnit_Framework_TestCase
{
private
$includePath
;
private
$error
;
private
$errorHandler
;
/**
* Runs the test methods of this class.
*
*
@return
void
*/
public
static
function
main
(
)
{
require_once
(
'PHPUnit/TextUI/TestRunner.php'
)
;
$suite
=
new
PHPUnit_Framework_TestSuite
(
"Console_LoaderTest"
)
;
$result
=
PHPUnit_TextUI_TestRunner
::
run
(
$suite
)
;
}
public
function
setUp
(
)
{
// Store original include_path
$this
->
includePath
=
get_include_path
(
)
;
$this
->
error
=
null
;
$this
->
errorHandler
=
null
;
}
public
function
tearDown
(
)
{
if
(
$this
->
errorHandler
!==
null
)
{
restore_error_handler
(
)
;
}
// Retore original include_path
set_include_path
(
$this
->
includePath
)
;
}
/**
* Tests that a class can be loaded from a well-formed PHP file
*/
public
function
testLoadClass
(
)
{
try
{
Console_Loader
::
loadClass
(
'Console_Application'
)
;
if
(
!
class_exists
(
'Console_Application'
,
false
))
{
$this
->
file
(
'Loading of class should not fail!'
)
;
}
}
catch
(
Exception
$e
)
{
echo
$e
;
$this
->
fail
(
'Loading of existent class should not throw exception!'
)
;
}
}
public
function
testLoadInterface
(
)
{
try
{
Console_Loader
::
loadClass
(
'Console_Application_Interface'
)
;
if
(
!
interface_exists
(
'Console_Application_Interface'
,
false
))
{
$this
->
file
(
'Loading of class should not fail!'
)
;
}
}
catch
(
Exception
$e
)
{
$this
->
fail
(
'Loading of existent class should not throw exception!'
)
;
}
}
/**
* Tests that the security filter catches illegal characters.
*/
public
function
testThrowsExceptionOnLoadIllegalFilename
(
)
{
try
{
Console_Loader
::
loadClass
(
'/path/:to/@danger'
)
;
$this
->
fail
(
'Console_Exception was expected but never thrown.'
)
;
}
catch
(
Console_Exception
$e
)
{
$this
->
assertRegExp
(
'/Illegal character in filename: (.*)/i'
,
$e
->
getMessage
(
))
;
}
}
/**
* Tests that isReadable works
*/
public
function
testIsFileReadable
(
)
{
$this
->
assertTrue
(
Console_Loader
::
isReadable
(
__FILE__
))
;
$this
->
assertFalse
(
Console_Loader
::
isReadable
(
__FILE__ .
'.foobaar'
))
;
// test that a file in include_path gets loaded, see ZF-2985
$this
->
assertTrue
(
Console_Loader
::
isReadable
(
'Console/Application/Interface.php'
))
;
}
public
function
testThrowsExceptionOnLoadNotReadableFile
(
)
{
$this
->
setExpectedException
(
'Console_Exception'
)
;
Console_Loader
::
loadClass
(
'nonExistingFile'
)
;
}
/**
* With type either class or interface is ment!
*/
public
function
testThrowsExceptionOnRequiredFileDoesNotContainType
(
)
{
try
{
Console_Loader
::
loadClass
(
'Fixtures_BadLoadableClass'
)
;
$this
->
fail
(
'Console_Exception was expected but never thrown.'
)
;
}
catch
(
Console_Exception
$e
)
{
$this
->
assertRegExp
(
'/Class or interface \'(.*)\' was not found in the file \'(.*)\'/i'
,
$e
->
getMessage
(
))
;
}
}
public
function
testFileNameIsValid
(
)
{
$this
->
assertTrue
(
Console_Loader
::
isFileNameValid
(
'this/is/a/valid/name'
))
;
$this
->
assertTrue
(
Console_Loader
::
isFileNameValid
(
'This_Should_Be_Valid_2'
))
;
$this
->
assertFalse
(
Console_Loader
::
isFileNameValid
(
' # this is not $ valid'
))
;
}
}
// Call Console_LoaderTest::main() if this source file is executed directly.
if
(
PHPUnit_MAIN_METHOD
===
'Console_LoaderTest::main'
)
{
Console_LoaderTest
::
main
(
)
;
}
Documentation generated on Mon, 17 Aug 2009 15:52:50 +0200 by
phpDocumentor 1.4.2