当前位置: 首页>>代码示例>>PHP>>正文


PHP assert_true函数代码示例

本文整理汇总了PHP中assert_true函数的典型用法代码示例。如果您正苦于以下问题:PHP assert_true函数的具体用法?PHP assert_true怎么用?PHP assert_true使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了assert_true函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_http_ua_accepts

   function test_http_ua_accepts()
   {
     $env = env();

     $env['SERVER']['HTTP_ACCEPT'] = null;
     assert_true(http_ua_accepts('text/plain'));

     $env['SERVER']['HTTP_ACCEPT'] = 'text/html';
     assert_true(http_ua_accepts('html'));

     $env['SERVER']['HTTP_ACCEPT'] = 'text/*; application/json';     
     assert_true(http_ua_accepts('html'));
     assert_true(http_ua_accepts('text/html'));
     assert_true(http_ua_accepts('text/plain'));
     assert_true(http_ua_accepts('application/json'));
     
     assert_false(http_ua_accepts('image/png'));
     assert_false(http_ua_accepts('png'));
     
     assert_true(defined('TESTS_DOC_ROOT'), "Undefined 'TESTS_DOC_ROOT' constant");
     
     $response =  test_request(TESTS_DOC_ROOT.'05-content_negociation.php', 'GET', false, array(), array("Accept: image/png"));
     assert_equal("Oops", $response);
     
     $response =  test_request(TESTS_DOC_ROOT.'05-content_negociation.php', 'GET', false, array(), array("Accept: text/html"));
     assert_equal("<h1>HTML</h1>", $response);
     
     $response =  test_request(TESTS_DOC_ROOT.'05-content_negociation.php', 'GET', false, array(), array("Accept: application/json"));
     assert_equal("json", $response);
   }
开发者ID:neochrome,项目名称:limonade,代码行数:30,代码来源:http.php

示例2: test_test_assert_request

function test_test_assert_request()
{
    assert_true(defined('TESTS_DOC_ROOT'), "Undefined 'TESTS_DOC_ROOT' constant");
    $response = test_request(TESTS_DOC_ROOT . '00-empty.php', 'GET', true);
    assert_header($response, 'Content-type');
    assert_header($response, 'Content-type', 'text/html');
    assert_header($response, 'Content-Type');
    assert_header($response, 'Content-Type', 'text/html');
}
开发者ID:Energeyser,项目名称:projet_framework,代码行数:9,代码来源:tests.php

示例3: test_request_method_is_allowed

function test_request_method_is_allowed()
{
    assert_true(request_method_is_allowed("GET"));
    assert_true(request_method_is_allowed("get"));
    assert_true(request_method_is_allowed("POST"));
    assert_true(request_method_is_allowed("PUT"));
    assert_true(request_method_is_allowed("DELETE"));
    assert_true(request_method_is_allowed("HEAD"));
}
开发者ID:sniemela,项目名称:limonade,代码行数:9,代码来源:request.php

示例4: test_file_is_binary

function test_file_is_binary()
{
    assert_false(file_is_binary('my_file.txt'));
    assert_false(file_is_binary('my_file.TXT'));
    assert_false(file_is_binary('my_file.css'));
    assert_false(file_is_binary('my_file.csv'));
    assert_true(file_is_binary('my_file.jpg'));
    assert_true(file_is_binary('my_file.swf'));
}
开发者ID:karupanerura,项目名称:isucon4,代码行数:9,代码来源:file.php

示例5: test_functional_session

function test_functional_session()
{
    $response = test_request(TESTS_DOC_ROOT . '06-session.php/', 'GET', false);
    // In http://www.php.net/manual/en/function.session-name.php:
    //
    // > The session name references the session id in cookies and URLs. It
    //   should contain only alphanumeric characters; it should be short and
    //   descriptive (i.e. for users with enabled cookie warnings). If name is
    //   specified, the name of the current session is changed to its value.
    assert_true(ctype_alnum($response));
    assert_equal($response, "LIMONADE" . str_replace('.', 'x', LIMONADE));
}
开发者ID:kentana20,项目名称:isucon3,代码行数:12,代码来源:functional.php

示例6: assert_array_equals

$mapJson = "{\n  \"stringMap\": {\n    \"a\": \"A\",\n    \"b\": \"B\"\n  },\n\n  \"boolMap\": {\n    \"false\": \"False\",\n    \"true\": \"True\"\n  },\n\n  \"byteMap\": {\n   \"1\": \"one\",\n    \"2\": \"two\"\n  },\n  \"doubleMap\":\n  {\n    \"0.2\": \"0.two\",\n    \"0.1\": \"0.one\"\n  },\n  \"enumMap\": {\n\n  \"1\": \"male\",\n    \"2\": \"female\"\n  }\n}";
$mapStruct->readFromJson($mapJson);
assert_array_equals($mapStruct->stringMap, $stringMap);
assert_array_equals($mapStruct->boolMap, $boolMap);
assert_array_equals($mapStruct->byteMap, $byteMap);
assert_array_equals($mapStruct->enumMap, $enumMap);
/**
 * Test mixed structure
 */
$mixedJson = "{\n  \"a\": [\n    \n  ],\n  \"b\": [\n    {\n      \"a\": 5\n\n  }\n  ],\n  \"c\": {\n   \"fire\": -191,\n    \"flame\": -8\n  },\n  \"d\": {\n\n  \n  },\n  \"e\": [\n    1, 2, 3, 4\n  ]\n}";
$mixedStruct->readFromJson($mixedJson);
assert_array_equals($mixedStruct->a, array());
assert_array_equals($mixedStruct->c, array('fire' => -191, 'flame' => -8));
$tSuperStruct = new mySuperSimpleStruct(array('a' => 5));
$tArr = array(0 => $tSuperStruct);
assert_true($mixedStruct->b == $tArr);
assert_array_equals($mixedStruct->d, array());
assert_array_equals($mixedStruct->e, array(1 => true, 2 => true, 3 => true, 4 => true));
/**
 * Test Set
 */
$setJson1 = "{\n  \"a\": [\n    8, 16, 4, 15\n  ]\n}";
$setStruct->readFromJson($setJson1);
assert_array_equals($setStruct->a, array(4 => true, 8 => true, 15 => true, 16 => true));
$setJson2 = "{\n  \"a\": [\n    \n  ]\n}";
$setStruct->readFromJson($setJson2);
assert_array_equals($setStruct->a, array());
$setJson3 = "{\n  \"a\": [\n    1, 2, 1099511627775\n  ]\n}";
test_exception($setStruct, $setJson3);
/**
 * Test for simple structure
开发者ID:jamescarr,项目名称:fbthrift,代码行数:31,代码来源:SimpleJSONToThriftTest.php

示例7: context

        context("nested in a context", function () {
            setup(function () {
                transient()->setup3 = true;
            });
            should("have called all three setups", function () {
                assert_equals(true, transient()->setup1);
                assert_equals(true, transient()->setup2);
                assert_equals(true, transient()->setup3);
            });
            should("have the proper test description", function () {
                assert_equals("a context nested in a context nested in a context should have the proper test description", Smoothie::instance()->test_description());
            });
        });
    });
    should("have ran teardown", function () {
        assert_true($GLOBALS['I_RAN_TEARDOWN']);
    });
    context("with no setup", function () {
        should("work", function () {
            assert_true(true);
        });
    });
    // TODO
    should("cause a failure", function () {
        assert_equals(1, 2);
    });
    // TODO
    should("cause an error", function () {
        throw new \Exception("exception!");
    });
});
开发者ID:kla,项目名称:smoothie,代码行数:31,代码来源:ContextTest.php

示例8: test_main_url_for

   function test_main_url_for()
   {
     assert_equal(url_for(''), '/');
     assert_equal(url_for('/'), '/');
     assert_equal(url_for('test'), '/test');
     assert_equal(url_for('mañana'), '/'.rawurlencode("mañana"));
     assert_equal(url_for('test', 1, 2), '/test/1/2');
     assert_equal(url_for('one', 'two', 'three'), '/one/two/three');
     assert_equal(url_for('one', 0, 'three'), '/one/0/three');
     assert_equal(url_for('one', '', 'three'), '/one/three');
     assert_equal(url_for('one', null, 'three'), '/one/three');
     assert_equal(url_for('my/hash#test'), '/my/hash#test');
     
     $site_url = 'http://www.limonade-php.net';
     assert_true((bool) filter_var_url($site_url));
     assert_true((bool) filter_var_url('http://example.com'));
     assert_true((bool) filter_var_url('http://example.com:2000/'));
     assert_true((bool) filter_var_url('https://www.example.com:2000'));
     assert_true((bool) filter_var_url('http://test.example.com/?var1=true&var2=34'));
     assert_false(filter_var_url('not an url'));
     
     assert_equal(url_for($site_url), $site_url);
     //var_dump(url_for($site_url, 'examples'));
     assert_equal(url_for($site_url, 'examples'), $site_url.'/examples');
     $ssite_url = 'https://www.limonade-php.net';
     assert_equal(url_for($ssite_url), $ssite_url);
     
     option('base_uri', '?');
     $url = url_for('test', array('p1' => 'lorem', 'p2' => 'ipsum'));
     assert_equal($url,'?/test&amp;p1=lorem&amp;p2=ipsum');
     $url = url_for('test', array(0 => 'lorem', 'p2' => 1));
     assert_equal($url,'?/test&amp;0=lorem&amp;p2=1');
     $url = url_for('test', array('p1' => 'mañana'));
     assert_equal($url,'?/test&amp;p1='.rawurlencode("mañana"));

     option('base_uri', '/api');
     $url = url_for('test', array('p1' => 'lorem', 'p2' => 'ipsum'));
     assert_equal($url,'/api/test?p1=lorem&amp;p2=ipsum');
	 }
开发者ID:reith2004,项目名称:limonade,代码行数:39,代码来源:main.php

示例9: test_main_benchmark

function test_main_benchmark()
{
    $bench = benchmark();
    assert_true(is_array($bench));
    assert_true(array_key_exists('execution_time', $bench));
    if (function_exists('memory_get_usage')) {
        assert_true(defined('LIM_START_MEMORY'));
        assert_true(array_key_exists('start_memory', $bench));
        assert_equal(LIM_START_MEMORY, $bench['start_memory']);
    }
}
开发者ID:Energeyser,项目名称:projet_framework,代码行数:11,代码来源:main.php

示例10: test_main_require_once_dir

function test_main_require_once_dir()
{
    $root = dirname(dirname(__FILE__));
    ob_start();
    assert_empty(require_once_dir($root));
    $files = require_once_dir($root, "AUTHORS");
    assert_empty(ob_get_contents());
    ob_clean();
    assert_length_of($files, 1);
    assert_match('/AUTHORS$/', $files[0]);
    ob_start();
    $files = require_once_dir($root, "CHANGES", false);
    assert_not_empty(ob_get_contents());
    ob_clean();
    $lib = $root . '/lib';
    $limonade = $lib . '/limonade';
    $files = require_once_dir($limonade);
    assert_not_empty($files);
    $tests_lib = $root . '/tests/data/lib0';
    $libs = array('a', 'b', 'c');
    foreach ($libs as $lib) {
        assert_false(defined('TEST_LIB_' . strtoupper($lib)));
    }
    $files = require_once_dir($tests_lib);
    assert_not_empty($files);
    assert_length_of($files, 3);
    foreach ($libs as $lib) {
        assert_true(defined('TEST_LIB_' . strtoupper($lib)));
    }
    assert_empty(require_once_dir($root . '/tests/data/'));
    assert_true(is_array(require_once_dir($root . '/tests/data/')));
    assert_empty(require_once_dir($root . '/tests/data/unknown_dir'));
    assert_true(is_array(require_once_dir($root . '/tests/data/unknown_dir')));
}
开发者ID:robotmay,项目名称:limonade,代码行数:34,代码来源:main.php

示例11: test_main_url_for

function test_main_url_for()
{
    assert_equal(url_for(''), '/');
    assert_equal(url_for('/'), '/');
    assert_equal(url_for('test'), '/test');
    assert_equal(url_for('mañana'), '/' . rawurlencode("mañana"));
    assert_equal(url_for('test', 1, 2), '/test/1/2');
    assert_equal(url_for('one', 'two', 'three'), '/one/two/three');
    assert_equal(url_for('my/hash#test'), '/my/hash#test');
    $site_url = 'http://www.limonade-php.net';
    assert_true((bool) filter_var_url($site_url));
    assert_equal(url_for($site_url), $site_url);
    //var_dump(url_for($site_url, 'examples'));
    assert_equal(url_for($site_url, 'examples'), $site_url . '/examples');
    $ssite_url = 'https://www.limonade-php.net';
    assert_equal(url_for($ssite_url), $ssite_url);
    $url = url_for('test', array('p1' => 'lorem', 'p2' => 'ipsum'));
    assert_equal($url, '/test&amp;p1=lorem&amp;p2=ipsum');
    $url = url_for('test', array(0 => 'lorem', 'p2' => 1));
    assert_equal($url, '/test&amp;0=lorem&amp;p2=1');
    $url = url_for('test', array('p1' => 'mañana'));
    assert_equal($url, '/test&amp;p1=' . rawurlencode("mañana"));
}
开发者ID:ArnaudD,项目名称:limonade,代码行数:23,代码来源:main.php

示例12: write_to_read

write_to_read($w, $r);
assert_true(!isset($r->im_default));
// Optional gets written (when set)
$w = new Tricky2();
$r = new Tricky2();
write_to_read($w, $r);
assert_true(!isset($r->im_optional));
// Require gets written (when set)
$w = new Tricky3();
$r = new Tricky3();
try {
    write_to_read($w, $r);
    assert_true(false, "Expected exception because field is required");
} catch (Exception $ex) {
}
assert_true(!isset($r->im_required));
/////////////////////////////////
// Mixing Default & Optional & Required
/////////////////////////////////
// Default <-> Optional
$w = new Tricky1();
$r = new Tricky2();
$w->im_default = 0;
$r->im_optional = 10;
write_to_read($w, $r);
assert_equals(0, $r->im_optional);
assert_equals(0, $w->im_default);
write_to_read($r, $w);
assert_equals(0, $r->im_optional);
assert_equals(0, $w->im_default);
// Default <-> Required
开发者ID:davidnasar,项目名称:fbthrift,代码行数:31,代码来源:TestOptionalRequired.php

示例13: test_get_fixtures_for_all_tables

 function test_get_fixtures_for_all_tables()
 {
     $dbh = TestDB::get_instance();
     $data = $dbh->get_test_data();
     $fixtures = new SimpleFixtures($dbh);
     $fixtures->enqueue('users', $data['users'], array('auto_id' => false, 'auto_ref' => false));
     $fixtures->enqueue('user_friends', $data['user_friends'], array('auto_id' => false, 'auto_ref' => false));
     $retrieved_data = $fixtures->get('*');
     assert_true(isset($retrieved_data['users'])) and assert_equal($retrieved_data['users'], $data['users']);
     assert_true(isset($retrieved_data['user_friends'])) and assert_equal($retrieved_data['user_friends'], $data['user_friends']);
 }
开发者ID:a-ludi,项目名称:community-service-manager,代码行数:11,代码来源:class-simple-fixtures.php

示例14: assert_equals

            assert_equals("/your regex/", $smoothie->filter);
        });
        should("accept --filter", function () {
            $smoothie = new Smoothie(array("--filter", "your regex"));
            assert_equals("/your regex/", $smoothie->filter);
        });
        should("add slashes if missing", function () {
            $smoothie = new Smoothie(array("-n", "your regex"));
            assert_equals("/your regex/", $smoothie->filter);
        });
        should("not add slahes if already there", function () {
            $smoothie = new Smoothie(array("-n", "/your regex/"));
            assert_equals("/your regex/", $smoothie->filter);
        });
        should("return true if no filter was set", function () {
            $smoothie = new Smoothie();
            assert_true($smoothie->passes_filter("my awesome test"));
        });
        context("tests with passes_filter()", function () {
            setup(function () {
                transient()->smoothie = new Smoothie(array("-n", "/my awesome test/"));
            });
            should("return true if filter was set and passes", function () {
                assert_true(transient()->smoothie->passes_filter("this is my awesome test that is awesome"));
            });
            should("return false if filter was set and does not pass", function () {
                assert_false(transient()->smoothie->passes_filter("blah"));
            });
        });
    });
});
开发者ID:kla,项目名称:smoothie,代码行数:31,代码来源:SmoothieTest.php

示例15: test_is_property_set

 function test_is_property_set()
 {
     $c = new TestActiveData();
     assert_true($c->is_set('foo'));
     assert_false($c->is_set('bar'));
 }
开发者ID:a-ludi,项目名称:community-service-manager,代码行数:6,代码来源:class-active-data.php


注:本文中的assert_true函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。