Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

more test helpers

  • Loading branch information...
commit 4db4419638019a4782723f21d8b79227efdfbea6 1 parent ca089e0
@c9s authored
Showing with 31 additions and 15 deletions.
  1. +31 −15 src/PHPUnit/TestMore.php
View
46 src/PHPUnit/TestMore.php
@@ -10,27 +10,36 @@
if( ! defined('DEBUG_BACKTRACE_PROVIDE_OBJECT') )
define( 'DEBUG_BACKTRACE_PROVIDE_OBJECT' , true );
+
+function get_testcase_object()
+{
+ $objs = debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT );
+ foreach($objs as $o) {
+ if ( array_key_exists('object', $o) && $o['object'] instanceof PHPUnit_Framework_TestCase ) {
+ return $o['object'];
+ }
+ }
+ return NULL;
+}
+
function ok( $v , $msg = null )
{
- $stacks = debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT );
- $testobj = $stacks[1]['object'];
- $testobj->assertTrue( $v ? true : false , $msg );
+ $test = get_testcase_object();
+ $test->assertTrue( $v ? true : false , $msg );
return $v ? true : false;
}
function not_ok( $v , $msg = null )
{
- $stacks = debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT );
- $testobj = $stacks[1]['object'];
- $testobj->assertFalse( $v ? true : false , $msg );
+ $test = get_testcase_object();
+ $test->assertFalse( $v ? true : false , $msg );
return $v ? true : false;
}
function is( $expected , $v , $msg = null )
{
- $stacks = debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT );
- $testobj = $stacks[1]['object'];
- $testobj->assertEquals( $expected , $v , $msg );
+ $test = get_testcase_object();
+ $test->assertEquals( $expected , $v , $msg );
return $expected === $v ? true : false;
}
@@ -113,16 +122,24 @@ function file_ok( $path , $msg = null ) {
$testobj->assertTrue( is_file( $path ) , $msg );
}
-function class_ok( $val , $msg = null ) {
+function class_ok( $val , $msg = null )
+{
$stacks = debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT );
$testobj = $stacks[1]['object'];
$testobj->assertTrue( class_exists( $val ) , $msg );
}
-function path_ok( $path , $msg = null ) {
- $stacks = debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT );
- $testobj = $stacks[1]['object'];
- $testobj->assertFileExists($path , $msg );
+function path_ok( $path , $msg = null )
+{
+ $test = get_testcase_object();
+ $test->assertFileExists($path , $msg );
+}
+
+function dir_ok($path, $msg = null)
+{
+ $test = get_testcase_object();
+ $test->assertFileExists($path , $msg , "Directory $path exists." );
+ $test->assertTrue( is_dir($path) , "Path $path is a directory." );
}
function dump($e)
@@ -132,4 +149,3 @@ function dump($e)
}
-
Please sign in to comment.
Something went wrong with that request. Please try again.