本文整理汇总了PHP中R::nuke方法的典型用法代码示例。如果您正苦于以下问题:PHP R::nuke方法的具体用法?PHP R::nuke怎么用?PHP R::nuke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类R
的用法示例。
在下文中一共展示了R::nuke方法的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: testCreate
public function testCreate()
{
\R::nuke();
$this->user->create($this->email, $this->username, $this->password, $this->password);
$id = $this->user->unbox()->id;
$this->assertEquals(1, $id);
}
示例3: testExtAssoc
/**
* Test extended associations.
*
* @return void
*/
public function testExtAssoc()
{
$toolbox = R::$toolbox;
$adapter = $toolbox->getDatabaseAdapter();
$writer = $toolbox->getWriter();
$redbean = $toolbox->getRedBean();
$pdo = $adapter->getDatabase();
R::nuke();
$webpage = $redbean->dispense("webpage");
$webpage->title = "page with ads";
$ad = $redbean->dispense("ad");
$ad->title = "buy this!";
$top = $redbean->dispense("placement");
$top->position = "top";
$bottom = $redbean->dispense("placement");
$bottom->position = "bottom";
$ea = new RedBean_AssociationManager_ExtAssociationManager($toolbox);
$ea->extAssociate($ad, $webpage, $top);
$ads = $redbean->batch("ad", $ea->related($webpage, "ad"));
$adsPos = $redbean->batch("ad_webpage", $ea->related($webpage, "ad", TRUE));
asrt(count($ads), 1);
asrt(count($adsPos), 1);
$theAd = array_pop($ads);
$theAdPos = array_pop($adsPos);
asrt($theAd->title, $ad->title);
asrt($theAdPos->position, $top->position);
$ad2 = $redbean->dispense("ad");
$ad2->title = "buy this too!";
$ea->extAssociate($ad2, $webpage, $bottom);
$ads = $redbean->batch("ad", $ea->related($webpage, "ad", TRUE));
asrt(count($ads), 2);
}
示例4: prepare
/**
* @BeforeSuite
*/
public static function prepare(SuiteEvent $event)
{
// prepare system for test suite
// before it runs
$config = json_decode(file_get_contents(__DIR__ . "/../../.config/database.json"));
R::setup($config->driver . ':host=' . $config->host . ';dbname=' . $config->dbname, $config->user, $config->pass);
R::nuke();
}
示例5: tearDown
function tearDown()
{
// Must use nuke() to clear caches etc.
R::nuke();
R::close();
$this->bbs = NULL;
system("rm -rf " . self::DATA);
}
示例6: 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);
}
示例7: run
/**
* Begin testing.
* This method runs the actual test pack.
*
* @return void
*/
public function run()
{
R::nuke();
file_put_contents('/tmp/test_log.txt', '');
R::log('/tmp/test_log.txt');
$bean = R::dispense('bean');
$bean->name = TRUE;
R::store($bean);
$bean->name = 'test';
R::store($bean);
$log = file_get_contents('/tmp/test_log.txt');
asrt(strlen($log) > 0, TRUE);
echo $log;
}
示例8: testInspect
/**
* Tests the R::inspect() method on the Facade.
*
* @return void
*/
public function testInspect()
{
testpack('Test R::inspect() ');
R::nuke();
R::store(R::graph(array('type' => 'book', 'title' => 'book')));
$info = R::inspect();
asrt(count($info), 1);
asrt(strtolower($info[0]), 'book');
$info = R::inspect('book');
asrt(count($info), 2);
$keys = array_keys($info);
sort($keys);
asrt(strtolower($keys[0]), 'id');
asrt(strtolower($keys[1]), 'title');
}
示例9: testNuke
/**
* Nuclear test suite.
*
* @return void
*/
public function testNuke()
{
$bean = R::dispense('bean');
R::store($bean);
asrt(count(R::$writer->getTables()), 1);
R::nuke();
asrt(count(R::$writer->getTables()), 0);
$bean = R::dispense('bean');
R::store($bean);
asrt(count(R::$writer->getTables()), 1);
R::freeze();
R::nuke();
// No effect
asrt(count(R::$writer->getTables()), 1);
R::freeze(FALSE);
}
示例10: 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);
}
示例11: testKeywords
/**
* Test if RedBeanPHP can properly handle keywords.
*
* @return void
*/
public function testKeywords()
{
$keywords = array('anokeyword', 'znokeyword', 'group', 'DROP', 'inner', 'JOIN', 'select', 'table', 'int', 'cascade', 'float', 'CALL', 'in', 'status', 'order', 'limit', 'having', 'else', 'if', 'while', 'distinct', 'like');
R::setStrictTyping(FALSE);
RedBean_OODBBean::setFlagBeautifulColumnNames(FALSE);
foreach ($keywords as $k) {
R::nuke();
$bean = R::dispense($k);
$bean->{$k} = $k;
$id = R::store($bean);
$bean = R::load($k, $id);
$bean2 = R::dispense('other');
$bean2->name = $k;
$bean->bean = $bean2;
$bean->ownBean[] = $bean2;
$bean->sharedBean[] = $bean2;
$id = R::store($bean);
R::trash($bean);
pass();
}
RedBean_OODBBean::setFlagBeautifulColumnNames(TRUE);
R::setStrictTyping(TRUE);
}
示例12: testMySQL
/**
* MySQL specific tests.
*
* @return void
*/
public function testMySQL()
{
if ($this->currentlyActiveDriverID !== 'mysql') {
return;
}
testpack('Throw exception in case of issue with assoc constraint');
$bunny = R::dispense('bunny');
$carrot = R::dispense('carrot');
$faultyWriter = new FaultyWriter(R::$toolbox->getDatabaseAdapter());
$faultyToolbox = new RedBean_ToolBox(R::$toolbox->getRedBean(), R::$toolbox->getDatabaseAdapter(), $faultyWriter);
$faultyAssociationManager = new RedBean_AssociationManager($faultyToolbox);
$faultyWriter->setSQLState('23000');
$faultyAssociationManager->associate($bunny, $carrot);
pass();
$faultyWriter->setSQLState('42S22');
R::nuke();
try {
$faultyAssociationManager->associate($bunny, $carrot);
fail();
} catch (RedBean_Exception_SQL $exception) {
pass();
}
}
示例13: droptables
function droptables()
{
global $nukepass;
R::nuke();
if (!count($t = R::$writer->getTables())) {
$nukepass++;
} else {
echo "\nFailed to clean up database: " . print_r($t, 1);
fail();
}
return;
if ($db == 'mysql') {
R::exec('SET FOREIGN_KEY_CHECKS=0;');
}
if ($db == 'sqlite') {
R::exec('PRAGMA foreign_keys = 0 ');
}
R::exec('drop view if exists people');
R::exec('drop view if exists library2');
foreach (R::$writer->getTables() as $t) {
if ($db == 'mysql') {
R::exec("drop table `{$t}`");
}
if ($db == 'pgsql') {
R::exec("drop table \"{$t}\" cascade");
}
if ($db == 'sqlite') {
R::exec("drop table {$t} ");
}
}
if ($db == 'mysql') {
R::exec('SET FOREIGN_KEY_CHECKS=1;');
}
if ($db == 'sqlite') {
R::exec('PRAGMA foreign_keys = 1 ');
}
}
示例14: testBoxing
/**
* Test boxing beans.
*
* @return void
*/
public function testBoxing()
{
R::nuke();
$bean = R::dispense('boxedbean')->box();
R::trash($bean);
pass();
$bean = R::dispense('boxedbean');
$bean->sharedBoxbean = R::dispense('boxedbean')->box();
R::store($bean);
pass();
$bean = R::dispense('boxedbean');
$bean->ownBoxedbean = R::dispense('boxedbean')->box();
R::store($bean);
pass();
$bean = R::dispense('boxedbean');
$bean->other = R::dispense('boxedbean')->box();
R::store($bean);
pass();
$bean = R::dispense('boxedbean');
$bean->title = 'MyBean';
$box = $bean->box();
asrt($box instanceof Model_Boxedbean, TRUE);
R::store($box);
}
示例15: run
/**
* Run the actual test
*/
public function run()
{
$class = new ReflectionClass($this);
$skip = array('run', 'getTargetDrivers', 'onEvent');
// Call all methods except run automatically
foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
// Skip methods inherited from parent class
if ($method->class != $class->getName()) {
continue;
}
if (in_array($method->name, $skip)) {
continue;
}
$classname = str_replace($class->getParentClass()->getName() . '_', '', $method->class);
printtext("\n\t" . $classname . "->" . $method->name . " [" . $method->class . "->" . $method->name . "]" . " \n\t");
$call = $method->name;
$this->{$call}();
try {
R::nuke();
} catch (PDOException $e) {
// Some tests use a broken database on purpose, so an exception is ok
}
}
}