Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adding tests for call_if_exists()
  • Loading branch information
Fabrice Luraine committed Nov 21, 2009
1 parent ce7381d commit 397eb4b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/main.php
Expand Up @@ -91,6 +91,24 @@ function test_main_call_if_exists()
assert_empty(call_if_exists("unknown_function"));
assert_equal(call_if_exists("count", array(1,2,3)), 3);
assert_length_of(call_if_exists("array_merge", array(1,2,3), array(4,5,6)), 6);

class TestCallIfExists
{
public function test($value=1)
{
return $value * 10;
}

static public function testStatic($value=1)
{
return $value * 20;
}
}

$obj = new TestCallIfExists();
assert_equal(call_if_exists(array($obj, 'test'), 3), 30);
assert_equal(call_if_exists(array('TestCallIfExists', 'testStatic'), 3), 60);
assert_equal(call_if_exists('TestCallIfExists::testStatic', 3), 60);
}

function test_main_define_unless_exists()
Expand Down

0 comments on commit 397eb4b

Please sign in to comment.