本文整理汇总了PHP中pass函数的典型用法代码示例。如果您正苦于以下问题:PHP pass函数的具体用法?PHP pass怎么用?PHP pass使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pass函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBasicsDispense
/**
* Test dispense.
*
* @return void
*/
public function testBasicsDispense()
{
$redbean = R::getRedBean();
// Can we dispense a bean?
$page = $redbean->dispense("page");
// Does it have a meta type?
asrt((bool) $page->getMeta("type"), TRUE);
// Does it have an ID?
asrt(isset($page->id), TRUE);
// Type should be 'page'
asrt($page->getMeta("type"), "page");
// ID should be 0 because bean does not exist in database yet.
asrt($page->id, 0);
// Try some faulty dispense actions.
foreach (array("", ".", "-") as $value) {
try {
$redbean->dispense($value);
fail();
} catch (RedException $e) {
pass();
}
}
$bean = $redbean->dispense("testbean");
$bean["property"] = 123;
$bean["abc"] = "def";
asrt($bean["property"], 123);
asrt($bean["abc"], "def");
asrt($bean->abc, "def");
asrt(isset($bean["abd"]), FALSE);
asrt(isset($bean["abc"]), TRUE);
}
示例2: testChill
/**
* Test Chill mode.
*
* @return void
*/
public function testChill()
{
$bean = R::dispense('bean');
$bean->col1 = '1';
$bean->col2 = '2';
R::store($bean);
asrt(count(R::$writer->getColumns('bean')), 3);
$bean->col3 = '3';
R::store($bean);
asrt(count(R::$writer->getColumns('bean')), 4);
R::freeze(array('umbrella'));
$bean->col4 = '4';
R::store($bean);
asrt(count(R::$writer->getColumns('bean')), 5);
R::freeze(array('bean'));
$bean->col5 = '5';
try {
R::store($bean);
fail();
} catch (Exception $e) {
pass();
}
asrt(count(R::$writer->getColumns('bean')), 5);
R::freeze(array());
$bean->col5 = '5';
R::store($bean);
asrt(count(R::$writer->getColumns('bean')), 6);
}
示例3: testTags
/**
* Some basic tests.
*
* @return void
*/
public function testTags()
{
list($c, $d, $e, $f) = R::dispense('coffee', 4);
R::tag($c, 'strong,black');
R::tag($d, 'black');
R::tag($e, 'strong,sweet');
R::tag($f, 'black,strong');
//$x = array_intersect(R::tagged('coffee','sweet'),R::tagged('coffee','strong'));
asrt(count(R::taggedAll('coffee', 'strong,sweet')), 1);
asrt(count(R::taggedAll('coffee', 'strong')), 3);
asrt(count(R::taggedAll('coffee', '')), 0);
asrt(count(R::taggedAll('coffee', 'sweet')), 1);
asrt(count(R::taggedAll('coffee', 'sweet,strong')), 1);
asrt(count(R::taggedAll('coffee', 'black,strong')), 2);
asrt(count(R::taggedAll('coffee', array('black', 'strong'))), 2);
asrt(count(R::taggedAll('coffee', 'salty')), 0);
$blog = R::dispense('blog');
$blog->title = 'testing';
$blog->blog = 'tesing';
R::store($blog);
$blogpost = R::load("blog", 1);
$post = R::dispense("post");
$post->message = "hello";
R::tag($post, "lousy,smart");
asrt(implode(',', R::tag($post)), "lousy,smart");
R::tag($post, "clever,smart");
$tagz = implode(',', R::tag($post));
asrt($tagz == "smart,clever" || $tagz == "clever,smart", TRUE);
R::tag($blog, array("smart", "interesting"));
asrt(implode(',', R::tag($blog)), "smart,interesting");
try {
R::tag($blog, array("smart", "interesting", "lousy!"));
pass();
} catch (RedBean_Exception $e) {
fail();
}
asrt(implode(',', R::tag($blog)), "smart,interesting,lousy!");
R::untag($blog, array("smart", "interesting"));
asrt(implode(",", R::tag($blog)), "lousy!");
asrt(R::hasTag($blog, array("lousy!")), TRUE);
asrt(R::hasTag($blog, array("lousy!", "smart")), TRUE);
asrt(R::hasTag($blog, array("lousy!", "smart"), TRUE), FALSE);
R::tag($blog, FALSE);
asrt(count(R::tag($blog)), 0);
R::tag($blog, array("funny", "comic"));
asrt(count(R::tag($blog)), 2);
R::addTags($blog, array("halloween"));
asrt(count(R::tag($blog)), 3);
asrt(R::hasTag($blog, array("funny", "commic", "halloween"), TRUE), FALSE);
R::unTag($blog, "funny");
R::addTags($blog, "horror");
asrt(count(R::tag($blog)), 3);
asrt(R::hasTag($blog, array("horror", "commic", "halloween"), TRUE), FALSE);
//no double tags
R::addTags($blog, "horror");
asrt(R::hasTag($blog, array("horror", "commic", "halloween"), TRUE), FALSE);
asrt(R::hasTag($blog, "horror,commic,halloween", TRUE), FALSE);
asrt(count(R::tag($blog)), 3);
testpack("fetch tagged items");
}
示例4: testPlaysNiceWithPreExitsingSchema
/**
* Test integration with pre-existing schemas.
*
* @return void
*/
public function testPlaysNiceWithPreExitsingSchema()
{
$toolbox = R::$toolbox;
$adapter = $toolbox->getDatabaseAdapter();
$writer = $toolbox->getWriter();
$redbean = $toolbox->getRedBean();
$pdo = $adapter->getDatabase();
$a = new RedBean_AssociationManager($toolbox);
$page = $redbean->dispense("page");
$page->name = "John's page";
$idpage = $redbean->store($page);
$page2 = $redbean->dispense("page");
$page2->name = "John's second page";
$idpage2 = $redbean->store($page2);
$a->associate($page, $page2);
$adapter->exec("ALTER TABLE " . $writer->esc('page') . "\n\t\tCHANGE " . $writer->esc('name') . " " . $writer->esc('name') . "\n\t\tVARCHAR( 254 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL ");
$page = $redbean->dispense("page");
$page->name = "Just Another Page In a Table";
$cols = $writer->getColumns("page");
asrt($cols["name"], "varchar(254)");
//$pdo->SethMode(1);
$redbean->store($page);
pass();
// No crash?
$cols = $writer->getColumns("page");
asrt($cols["name"], "varchar(254)");
//must still be same
}
示例5: testDump
/**
* Test dump().
*
* @return void
*/
public function testDump()
{
$beans = R::dispense('bean', 2);
$beans[0]->name = 'hello';
$beans[1]->name = 'world';
$array = R::dump($beans);
asrt(is_array($array), TRUE);
foreach ($array as $item) {
asrt(is_string($item), TRUE);
}
$beans[1]->name = 'world, and a very long string that should be shortened';
$array = R::dump($beans);
asrt(is_array($array), TRUE);
asrt(strpos($array[1], '...'), 35);
//just to get 100% test cov, we dont need to test this
dmp($beans);
pass();
//test wrong input
asrt(is_array(R::dump(NULL)), TRUE);
asrt(count(R::dump(NULL)), 0);
asrt(is_array(R::dump('')), TRUE);
asrt(count(R::dump('')), 0);
asrt(is_array(R::dump(1)), TRUE);
asrt(count(R::dump(1)), 0);
asrt(is_array(R::dump(TRUE)), TRUE);
asrt(count(R::dump(FALSE)), 0);
}
示例6: test_unset
function test_unset()
{
$a = [1, 2, 3];
assert(count($a) === 3);
unset($a[0]);
assert(count($a) === 2);
pass(__FUNCTION__);
}
示例7: TypeColumn
/**
* Test meta column type.
*
* @return void
*/
public function TypeColumn()
{
$book = R::dispense('book');
$page = R::dispense('page');
$page->book = $book;
R::store($page);
pass();
asrt($page->getMeta('cast.book_id'), 'id');
}
示例8: loggedIn
function loggedIn()
{
global $app;
if ($_COOKIE['login'] == pass($app['password']) or $app['password'] == '') {
return true;
} else {
return false;
}
}
示例9: testInvalidDB
/**
* Github issue #458, selectDatabase causes PHP notice undefined index
* if database key not found.
*
* @return void
*/
public function testInvalidDB()
{
try {
R::selectDatabase('idontexist');
fail();
} catch (RedException $exception) {
pass();
}
}
示例10: enable_json_api
function enable_json_api($path)
{
request($path, function () {
header("Content-Type: application/json");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true");
pass();
});
}
示例11: testUTF8
/**
* Test UTF8 handling.
*
* @return void
*/
public function testUTF8()
{
$str = '𠜎ὃ𠻗𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜';
$bean = R::dispense('bean');
$bean->bla = $str;
R::store($bean);
$bean = R::load('bean', $bean->id);
asrt($bean->bla, $str);
pass();
}
示例12: test_is
function test_is($result, $expected, $explanation)
{
if ($result === $expected) {
pass($explanation);
} else {
fail($explanation);
diag("Got '{$result}'");
diag("Expected '{$expected}'");
}
}
示例13: testVaria
/**
* Various tests for OCI.
*
* @return void
*/
public function testVaria()
{
$toolbox = R::$toolbox;
$adapter = $toolbox->getDatabaseAdapter();
$writer = $toolbox->getWriter();
$redbean = $toolbox->getRedBean();
$pdo = $adapter->getDatabase();
$page = $redbean->dispense("page");
try {
$adapter->exec("an invalid query");
fail();
} catch (RedBean_Exception_SQL $e) {
pass();
}
asrt((int) $adapter->getCell("SELECT 123 FROM DUAL"), 123);
$page->aname = "my page";
$id = (int) $redbean->store($page);
asrt((int) $page->id, 1);
asrt((int) $pdo->GetCell("SELECT count(*) FROM page"), 1);
asrt($pdo->GetCell("SELECT aname FROM page WHERE ROWNUM<=1"), "my page");
asrt((int) $id, 1);
$page = $redbean->load("page", 1);
asrt($page->aname, "my page");
asrt((bool) $page->getMeta("type"), TRUE);
asrt(isset($page->id), TRUE);
asrt($page->getMeta("type"), "page");
asrt((int) $page->id, $id);
R::nuke();
$rooms = R::dispense('room', 2);
$rooms[0]->kind = 'suite';
$rooms[1]->kind = 'classic';
$rooms[0]->number = 6;
$rooms[1]->number = 7;
R::store($rooms[0]);
R::store($rooms[1]);
$rooms = R::getAssoc('SELECT ' . R::$writer->esc('number') . ', kind FROM room ORDER BY kind ASC');
foreach ($rooms as $key => $room) {
asrt($key === 6 || $key === 7, TRUE);
asrt($room == 'classic' || $room == 'suite', TRUE);
}
$rooms = R::$adapter->getAssoc('SELECT kind FROM room');
foreach ($rooms as $key => $room) {
asrt($room == 'classic' || $room == 'suite', TRUE);
asrt($room, $key);
}
$rooms = R::getAssoc('SELECT ' . R::$writer->esc('number') . ', kind FROM rooms2 ORDER BY kind ASC');
asrt(count($rooms), 0);
asrt(is_array($rooms), TRUE);
$date = R::dispense('mydate');
$date->date = '2012-12-12 20:50';
$date->time = '12:15';
$id = R::store($date);
$ok = R::load('mydate', 1);
}
示例14: testLargeNum
/**
* Test for issue #386.
* Can we use large numbers in LIMIT ?
*
* @return void
*/
public function testLargeNum()
{
$number = R::dispense('number');
$number->name = 'big number';
R::store($number);
//This should not cause an error... (some people use LIMIT 0, HUGE to simulate OFFSET on MYSQL).
$beans = R::findAll('number', ' LIMIT ? ', array(PHP_INT_MAX));
asrt(is_array($beans), TRUE);
asrt(count($beans), 1);
pass();
}
示例15: testFUSE
/**
* Test FUSE and model formatting.
*
* @todo move tagging tests to tag tester.
*
* @return void
*/
public function testFUSE()
{
$toolbox = R::$toolbox;
$adapter = $toolbox->getDatabaseAdapter();
$blog = R::dispense('blog');
$blog->title = 'testing';
$blog->blog = 'tesing';
R::store($blog);
$blogpost = R::load("blog", 1);
$post = R::dispense("post");
$post->message = "hello";
R::associate($blog, $post);
$a = R::getAll("select * from blog ");
RedBean_ModelHelper::setModelFormatter(new mymodelformatter());
$w = R::dispense("weirdo");
asrt($w->blah(), "yes!");
R::tag($post, "lousy,smart");
asrt(implode(',', R::tag($post)), "lousy,smart");
R::tag($post, "clever,smart");
$tagz = implode(',', R::tag($post));
asrt($tagz == "smart,clever" || $tagz == "clever,smart", TRUE);
R::tag($blog, array("smart", "interesting"));
asrt(implode(',', R::tag($blog)), "smart,interesting");
try {
R::tag($blog, array("smart", "interesting", "lousy!"));
pass();
} catch (RedBean_Exception $e) {
fail();
}
asrt(implode(',', R::tag($blog)), "smart,interesting,lousy!");
asrt(implode(",", R::tag($blog)), "smart,interesting,lousy!");
R::untag($blog, array("smart", "interesting"));
asrt(implode(",", R::tag($blog)), "lousy!");
asrt(R::hasTag($blog, array("lousy!")), TRUE);
asrt(R::hasTag($blog, array("lousy!", "smart")), TRUE);
asrt(R::hasTag($blog, array("lousy!", "smart"), TRUE), FALSE);
R::tag($blog, FALSE);
asrt(count(R::tag($blog)), 0);
R::tag($blog, array("funny", "comic"));
asrt(count(R::tag($blog)), 2);
R::addTags($blog, array("halloween"));
asrt(count(R::tag($blog)), 3);
asrt(R::hasTag($blog, array("funny", "commic", "halloween"), TRUE), FALSE);
R::unTag($blog, array("funny"));
R::addTags($blog, "horror");
asrt(count(R::tag($blog)), 3);
asrt(R::hasTag($blog, array("horror", "commic", "halloween"), TRUE), FALSE);
// No double tags
R::addTags($blog, "horror");
asrt(R::hasTag($blog, array("horror", "commic", "halloween"), TRUE), FALSE);
asrt(count(R::tag($blog)), 3);
}