本文整理汇总了PHP中testpack函数的典型用法代码示例。如果您正苦于以下问题:PHP testpack函数的具体用法?PHP testpack怎么用?PHP testpack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了testpack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testTypes
/**
* Test types.
* Test how RedBeanPHP OODB and OODBBean handle type and type casts.
*
* Rules:
*
* 1. before storing a bean all types are preserved except booleans (they are converted to STRINGS '0' or '1')
* 2. after store-reload all bean property values are STRINGS or NULL
* (or ARRAYS but that's only from a user perspective because these are lazy loaded)
* 3. the ID returned by store() is an INTEGER (if possible; on 32 bit systems overflowing values will be cast to STRINGS!)
*
* After loading:
* ALL VALUES EXCEPT NULL -> STRING
* NULL -> NULL
*
* @note Why not simply return bean->id in store()? Because not every driver returns the same type:
* databases without insert_id support require a separate query or a suffix returning STRINGS, not INTEGERS.
*
* @note Why not preserve types? I.e. I store integer, why do I get back a string?
* Answer: types are handled different across database platforms, would cause overhead to inspect every value for type,
* also PHP is a dynamically typed language so types should not matter that much. Another reason: due to the nature
* of RB columns in the database might change (INT -> STRING) this would cause return types to change as well which would
* cause 'cascading errors', i.e. a column gets widened and suddenly your code would break.
*
* @note Unfortunately the 32/64-bit issue cannot be tested fully. Return-strategy store() is probably the safest
* solution.
*
* @return void
*/
public function testTypes()
{
testpack('Beans can only contain STRING and NULL after reload');
R::nuke();
$bean = R::dispense('bean');
$bean->number = 123;
$bean->float = 12.3;
$bean->bool = false;
$bean->bool2 = true;
$bean->text = 'abc';
$bean->null = null;
$bean->datetime = new \DateTime('NOW', new \DateTimeZone('Europe/Amsterdam'));
$id = R::store($bean);
asrt(is_int($id), TRUE);
asrt(is_float($bean->float), TRUE);
asrt(is_integer($bean->number), TRUE);
asrt(is_string($bean->bool), TRUE);
asrt(is_string($bean->bool2), TRUE);
asrt(is_string($bean->datetime), TRUE);
asrt(is_string($bean->text), TRUE);
asrt(is_null($bean->null), TRUE);
$bean = R::load('bean', $id);
asrt(is_string($bean->id), TRUE);
asrt(is_string($bean->float), TRUE);
asrt(is_string($bean->number), TRUE);
asrt(is_string($bean->bool), TRUE);
asrt(is_string($bean->bool2), TRUE);
asrt(is_string($bean->datetime), TRUE);
asrt(is_string($bean->text), TRUE);
asrt(is_null($bean->null), TRUE);
asrt($bean->bool, '0');
asrt($bean->bool2, '1');
}
示例2: testTainted
/**
* Test tainted.
*
* @return void
*/
public function testTainted()
{
testpack('Original Tainted Tests');
$redbean = R::getRedBean();
$spoon = $redbean->dispense("spoon");
asrt($spoon->getMeta("tainted"), TRUE);
$spoon->dirty = "yes";
asrt($spoon->getMeta("tainted"), TRUE);
testpack('Tainted List test');
$note = R::dispense('note');
$note->text = 'abc';
$note->ownNote[] = R::dispense('note')->setAttr('text', 'def');
$id = R::store($note);
$note = R::load('note', $id);
asrt($note->isTainted(), FALSE);
// Shouldn't affect tainted
$note->text;
asrt($note->isTainted(), FALSE);
$note->ownNote;
asrt($note->isTainted(), TRUE);
testpack('Tainted Test Old Value');
$text = $note->old('text');
asrt($text, 'abc');
asrt($note->hasChanged('text'), FALSE);
$note->text = 'xxx';
asrt($note->hasChanged('text'), TRUE);
$text = $note->old('text');
asrt($text, 'abc');
testpack('Tainted Non-exist');
asrt($note->hasChanged('text2'), FALSE);
testpack('Misc Tainted Tests');
$bean = R::dispense('bean');
$bean->hasChanged('prop');
$bean->old('prop');
}
示例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: testNamedParamsInSnippets
/**
* Test usage of named parameters in SQL snippets.
* Issue #299 on Github.
*
* @return void
*/
public function testNamedParamsInSnippets()
{
testpack('Test whether we can use named parameters in SQL snippets.');
R::nuke();
$book = R::dispense('book');
$page = R::dispense('page');
$book->title = 'book';
$book->sharedPage[] = $page;
R::store($book);
//should not give error like: Uncaught [HY093] - SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters
$books = $page->withCondition(' title = :title ', array(':title' => 'book'))->sharedBook;
asrt(count($books), 1);
//should not give error...
$books = $page->withCondition(' title = :title ', array(':title' => 'book'))->sharedBook;
asrt(count($books), 1);
R::nuke();
$book = R::dispense('book');
$page = R::dispense('page');
$book->title = 'book';
$book->comment = 'comment';
$page->title = 'page';
$book->ownPage[] = $page;
R::store($book);
//should also not give error..
$count = $book->countOwn('page');
asrt($count, 1);
$book = $book->fresh();
//should also not give error..
$count = $book->withCondition(' title = ? ', array('page'))->countOwn('page');
asrt($count, 1);
$book = $book->fresh();
//should also not give error..
$count = $book->withCondition(' title = :title ', array(':title' => 'page'))->countOwn('page');
asrt($count, 1);
$book = $book->fresh();
$pages = $book->withCondition(' title = :title ', array(':title' => 'page'))->ownPage;
asrt(count($pages), 1);
//test with duplicate slots...
$page = reset($pages);
$page2 = R::dispense('page');
$page2->ownPage[] = $page;
R::store($page2);
$page2 = $page2->fresh();
$pages = $page2->withCondition(' title = :title ', array(':title' => 'page'))->ownPage;
asrt(count($pages), 1);
//test with find()
$books = R::getRedBean()->find('book', array('title' => array('book')), ' AND title = :title ', array(':title' => 'book'));
asrt(count($books), 1);
$books = R::getRedBean()->find('book', array('title' => array('book', 'book2'), 'comment' => array('comment', 'comment2')), ' AND title = :title ', array(':title' => 'book'));
asrt(count($books), 1);
//just check numeric works as well...
$books = R::getRedBean()->find('book', array('title' => array('book', 'book2'), 'comment' => array('comment', 'comment2')), ' AND title = ? ', array('book'));
asrt(count($books), 1);
//just extra check to verify glue works
$books = R::getRedBean()->find('book', array('title' => array('book', 'book2'), 'comment' => array('comment', 'comment2')), ' ORDER BY id ');
asrt(count($books), 1);
}
示例5: testMissingBeans
/**
* Test missing bean scenarios.
*
* @return void
*/
public function testMissingBeans()
{
testpack('deal with missing beans');
$id = R::store(R::dispense('beer'));
$bottles = R::batch('beer', array($id, $id + 1, $id + 2));
asrt(count($bottles), 3);
asrt((int) $bottles[$id]->id, (int) $id);
asrt((int) $bottles[$id + 1]->id, 0);
asrt((int) $bottles[$id + 2]->id, 0);
}
示例6: testLabels
/**
* Test basic labels.
*
* @return void
*/
public function testLabels()
{
testpack('Test Labels');
$meals = R::dispenseLabels('meal', array('meat', 'fish', 'vegetarian'));
asrt(is_array($meals), TRUE);
asrt(count($meals), 3);
foreach ($meals as $m) {
asrt($m instanceof RedBean_OODBBean, TRUE);
}
$listOfMeals = implode(',', R::gatherLabels($meals));
asrt($listOfMeals, 'fish,meat,vegetarian');
}
示例7: testIssue259
/**
* Test to make sure stash cache works with recursively opening models
* with FUSE.
*
* @return void
*/
public function testIssue259()
{
testpack('Testing Issue #259 - Stash Cache breaks model delegation in open().');
$mother = R::dispense('mother');
$mother->desc = 'I am mother';
R::store($mother);
$child = R::dispense('child');
$child->mother = $mother;
$child->desc = 'I am child';
$id = R::store($child);
R::findOne('child', ' id = ?', array($id));
R::find('child', ' id = ? ', array($id));
R::load('child', $id);
}
示例8: testImportFromAndTainted
/**
* Test import from and tainted.
*
* @return void
*/
public function testImportFromAndTainted()
{
testpack('Test importFrom() and Tainted');
$bean = R::dispense('bean');
R::store($bean);
$bean->name = 'abc';
asrt($bean->getMeta('tainted'), TRUE);
R::store($bean);
asrt($bean->getMeta('tainted'), FALSE);
$copy = R::dispense('bean');
R::store($copy);
$copy = R::load('bean', $copy->id);
asrt($copy->getMeta('tainted'), FALSE);
$copy->import(array('name' => 'xyz'));
asrt($copy->getMeta('tainted'), TRUE);
$copy->setMeta('tainted', FALSE);
asrt($copy->getMeta('tainted'), FALSE);
$copy->importFrom($bean);
asrt($copy->getMeta('tainted'), TRUE);
testpack('Test basic import() feature.');
$bean = new RedBean_OODBBean();
$bean->import(array("a" => 1, "b" => 2));
asrt($bean->a, 1);
asrt($bean->b, 2);
$bean->import(array("a" => 3, "b" => 4), "a,b");
asrt($bean->a, 3);
asrt($bean->b, 4);
$bean->import(array("a" => 5, "b" => 6), " a , b ");
asrt($bean->a, 5);
asrt($bean->b, 6);
$bean->import(array("a" => 1, "b" => 2));
testpack('Test inject() feature.');
$coffee = R::dispense('coffee');
$coffee->id = 2;
$coffee->liquid = 'black';
$cup = R::dispense('cup');
$cup->color = 'green';
// Pour coffee in cup
$cup->inject($coffee);
// Do we still have our own property?
asrt($cup->color, 'green');
// Did we pour the liquid in the cup?
asrt($cup->liquid, 'black');
// Id should not be transferred
asrt($cup->id, 0);
}
示例9: testDynamicPlugins
/**
* Test if we can dynamically extend the R-facade.
*
* @return void
*/
public function testDynamicPlugins()
{
testpack('Test dynamic plugins');
//basic behaviour
R::ext('makeTea', function () {
return 'sorry cant do that!';
});
asrt(R::makeTea(), 'sorry cant do that!');
//with parameters
R::ext('multiply', function ($a, $b) {
return $a * $b;
});
asrt(R::multiply(3, 4), 12);
//can we call R inside?
R::ext('singVersion', function () {
return R::getVersion() . ' lalala !';
});
asrt(R::singVersion(), R::getVersion() . ' lalala !');
//should also work with Facade
asrt(Facade::singVersion(), R::getVersion() . ' lalala !');
//test error handling
try {
R::ext('---', function () {
});
fail();
} catch (RedException $e) {
asrt($e->getMessage(), 'Plugin name may only contain alphanumeric characters.');
}
try {
R::__callStatic('---', function () {
});
fail();
} catch (RedException $e) {
asrt($e->getMessage(), 'Plugin name may only contain alphanumeric characters.');
}
try {
R::invalidMethod();
fail();
} catch (RedException $e) {
asrt($e->getMessage(), 'Plugin \'invalidMethod\' does not exist, add this plugin using: R::ext(\'invalidMethod\')');
}
}
示例10: testCountAndWipe
/**
* Test count and wipe.
*
* @return void
*/
public function testCountAndWipe()
{
testpack("Test count and wipe");
$page = R::dispense("page");
$page->name = "ABC";
R::store($page);
$n1 = R::count("page");
$page = R::dispense("page");
$page->name = "DEF";
R::store($page);
$n2 = R::count("page");
asrt($n1 + 1, $n2);
R::wipe("page");
asrt(R::count("page"), 0);
asrt(R::getRedBean()->count("page"), 0);
asrt(R::getRedBean()->count("kazoo"), 0);
// non existing table
R::freeze(TRUE);
asrt(R::getRedBean()->count("kazoo"), 0);
// non existing table
R::freeze(FALSE);
$page = R::dispense('page');
$page->name = 'foo';
R::store($page);
$page = R::dispense('page');
$page->name = 'bar';
R::store($page);
asrt(R::count('page', ' name = ? ', array('foo')), 1);
// Now count something that does not exist, this should return 0. (just be polite)
asrt(R::count('teapot', ' name = ? ', array('flying')), 0);
asrt(R::count('teapot'), 0);
$currentDriver = $this->currentlyActiveDriverID;
// Some drivers don't support that many error codes.
if ($currentDriver === 'mysql' || $currentDriver === 'postgres') {
try {
R::count('teaport', ' for tea ');
fail();
} catch (SQL $e) {
pass();
}
}
}
示例11: testEmptyBean
/**
* Tests whether we can store an empty bean.
* An empty bean has no properties, only ID. Normally we would
* skip the ID field in an INSERT, this test forces the driver
* to specify a value for the ID field. Different writers have to
* use different values: Mysql uses NULL to insert a new auto-generated ID,
* while Postgres has to use DEFAULT.
*/
public function testEmptyBean()
{
testpack('Test Empty Bean Storage.');
R::nuke();
$bean = R::dispense('emptybean');
$id = R::store($bean);
asrt($id > 0, TRUE);
asrt(R::count('emptybean'), 1);
$bean = R::dispense('emptybean');
$id = R::store($bean);
asrt($id > 0, TRUE);
asrt(R::count('emptybean'), 2);
//also test in frozen mode
R::freeze(TRUE);
$bean = R::dispense('emptybean');
$id = R::store($bean);
asrt($id > 0, TRUE);
asrt(R::count('emptybean'), 3);
R::freeze(FALSE);
}
示例12: testParamBindingWithPostgres
/**
* Test parameter binding.
*
* @return void
*/
public function testParamBindingWithPostgres()
{
testpack("param binding pgsql");
$page = R::dispense("page");
$page->name = "abc";
$page->number = 2;
R::store($page);
R::exec("insert into page (name) values(:name) ", array(":name" => "my name"));
R::exec("insert into page (number) values(:one) ", array(":one" => 1));
R::exec("insert into page (number) values(:one) ", array(":one" => "1"));
R::exec("insert into page (number) values(:one) ", array(":one" => "1234"));
R::exec("insert into page (number) values(:one) ", array(":one" => "-21"));
pass();
testpack('Test whether we can properly bind and receive NULL values');
$adapter = R::$adapter;
asrt($adapter->getCell('SELECT TEXT( :nil ) ', array(':nil' => 'NULL')), 'NULL');
asrt($adapter->getCell('SELECT TEXT( :nil ) ', array(':nil' => NULL)), NULL);
asrt($adapter->getCell('SELECT TEXT( ? ) ', array('NULL')), 'NULL');
asrt($adapter->getCell('SELECT TEXT( ? ) ', array(NULL)), NULL);
}
示例13: testIssue303
/**
* Test whether we have two different exception messages for
* properties and values.
*
* @return void
*/
public function testIssue303()
{
testpack('Testing Issue #303 - Test splitting bean exception property/value.');
try {
R::store(R::dispense('invalidbean')->setAttr('invalid.property', 'value'));
fail();
} catch (RedException $e) {
asrt($e->getMessage(), 'Invalid Bean property: property invalid.property');
}
try {
R::store(R::dispense('invalidbean')->setAttr('property', array()));
fail();
} catch (RedException $e) {
asrt($e->getMessage(), 'Invalid Bean value: property property');
}
try {
R::store(R::dispense('invalidbean')->setAttr('property', new \stdClass()));
fail();
} catch (RedException $e) {
asrt($e->getMessage(), 'Invalid Bean value: property property');
}
}
示例14: testParamBindWithSQLite
/**
* Test parameter binding with SQLite.
*
* @return void
*/
public function testParamBindWithSQLite()
{
$toolbox = R::$toolbox;
$adapter = $toolbox->getDatabaseAdapter();
$writer = $toolbox->getWriter();
$redbean = $toolbox->getRedBean();
$pdo = $adapter->getDatabase();
asrt((int) $adapter->getCell("SELECT 123"), 123);
asrt((int) $adapter->getCell("SELECT ?", array("987")), 987);
asrt((int) $adapter->getCell("SELECT ?+?", array("987", "2")), 989);
asrt((int) $adapter->getCell("SELECT :numberOne+:numberTwo", array(":numberOne" => 42, ":numberTwo" => 50)), 92);
$pair = $adapter->getAssoc("SELECT 'thekey','thevalue' ");
asrt(is_array($pair), TRUE);
asrt(count($pair), 1);
asrt(isset($pair["thekey"]), TRUE);
asrt($pair["thekey"], "thevalue");
testpack('Test whether we can properly bind and receive NULL values');
asrt($adapter->getCell('SELECT :nil ', array(':nil' => 'NULL')), 'NULL');
asrt($adapter->getCell('SELECT :nil ', array(':nil' => NULL)), NULL);
asrt($adapter->getCell('SELECT ? ', array('NULL')), 'NULL');
asrt($adapter->getCell('SELECT ? ', array(NULL)), NULL);
}
示例15: testMetaData
/**
* Test meta data methods.
*
* @return void
*/
public function testMetaData()
{
testpack('Test meta data');
$bean = new RedBean_OODBBean();
$bean->setMeta("this.is.a.custom.metaproperty", "yes");
asrt($bean->getMeta("this.is.a.custom.metaproperty"), "yes");
asrt($bean->getMeta("nonexistant"), NULL);
asrt($bean->getMeta("nonexistant", "abc"), "abc");
asrt($bean->getMeta("nonexistant.nested"), NULL);
asrt($bean->getMeta("nonexistant,nested", "abc"), "abc");
$bean->setMeta("test.two", "second");
asrt($bean->getMeta("test.two"), "second");
$bean->setMeta("another.little.property", "yes");
asrt($bean->getMeta("another.little.property"), "yes");
asrt($bean->getMeta("test.two"), "second");
// Copy Metadata
$bean = new RedBean_OODBBean();
$bean->setMeta("meta.meta", "123");
$bean2 = new RedBean_OODBBean();
asrt($bean2->getMeta("meta.meta"), NULL);
$bean2->copyMetaFrom($bean);
asrt($bean2->getMeta("meta.meta"), "123");
}