function assert_difference($expression, $lambda) { $expression = 'return ' . $expression . ';'; $value = eval($expression); $lambda(); assert_not_equal($value, eval($expression)); }
function test_test_simple_assertions() { assert_true(true); assert_false(false); assert_equal("aaa", "aaa"); assert_not_equal("aaas", "aaa"); }
public function test_not_equal() { assert_not_equal(1, 2); assert_not_equal(1, "2"); assert_fails(function () { assert_not_equal(1, 1); }); assert_fails(function () { assert_not_equal(1, "1"); }); }
function test_request_uri() { # TODO test with webbrick + CGIHandler (http://microjet.ath.cx/webrickguide/html/CGIHandler.html) # TODO request_uri must be also tested in a browser... assert_equal(request_uri(), "/"); $path = dirname(__FILE__) . "/helpers/show_request_uri.php"; $cmd = "php -f {$path}"; assert_equal(exec($cmd, $res), "/"); assert_equal(exec($cmd . " test", $res), "/test"); assert_equal(exec($cmd . " /test", $res), "/test"); assert_equal(exec($cmd . " /my-test/", $res), "/my-test"); assert_not_equal(exec($cmd . " /my-test/?", $res), "/my-test"); assert_not_equal(exec($cmd . " /my-test?var=1", $res), "/my-test"); }
assert_equal($params["id"], 25); $_GET = array(); }); it("does not merge params already defined by router", function () { Router::getInstance()->reset(); $_GET["controller"] = "get_application"; $_GET["user_id"] = 100; Router::prepare(function ($r) { $r->match("/blog/:action")->to(array("controller" => "application")); }); $d = Dispatcher::getInstance(); $params = $d->params_for_request("/blog/method"); assert_not_equal($params["controller"], "get_application"); assert_equal($params["action"], "method"); assert_equal($params["user_id"], 100); $_GET = array(); }); it("returns false when it cannot merge", function () { Router::getInstance()->reset(); $_GET["user_id"] = 100; Router::prepare(function ($r) { $r->match("/blog/:action")->to(array("controller" => "application")); }); $d = Dispatcher::getInstance(); $params = $d->params_for_request("/user/method"); assert_not_equal($params["controller"], "application"); assert_not_equal($params["action"], "method"); assert_not_equal($params["user_id"], 100); $_GET = array(); }); });
function test_main_define_unless_exists() { assert_false(defined('MY_SPECIAL_CONST')); define_unless_exists('MY_SPECIAL_CONST', "special value"); assert_equal(MY_SPECIAL_CONST, "special value"); define_unless_exists('MY_SPECIAL_CONST', "an other value"); assert_not_equal(MY_SPECIAL_CONST, "an other value"); assert_equal(MY_SPECIAL_CONST, "special value"); }
public function test_bar() { assert_not_equal('bar', 'foo'); }
function test_register_error_handler() { restore_error_handler(); $get_error_handler = $this->get_error_handler; $handler = $get_error_handler(); assert_equal($handler, OpenStruct::register_error_handler()); assert_equal(array('OpenStruct', 'error_handler'), $get_error_handler()); assert_not_equal($handler, $get_error_handler()); }