inspect() public static method

The keys of this array will be the field names and the values will be the column types used to store their values. If no type is passed, this method returns a list of all tables in the database.
public static inspect ( string $type = NULL ) : array
$type string Type of bean (i.e. table) you want to inspect
return array
Ejemplo n.º 1
0
 /**
  * Test beautification conflicts...
  * Issue #418
  *
  * @return void
  */
 public function testBeau()
 {
     R::nuke();
     $book = R::dispense('book');
     $book->ownerId = 2;
     $book->ownerCritic = 'a';
     $book->sharedbyReader = 'b';
     $id = R::store($book);
     $columns = R::inspect('book');
     asrt(isset($columns['owner_id']), TRUE);
     asrt(isset($columns['owner_critic']), TRUE);
     asrt(isset($columns['sharedby_reader']), TRUE);
     asrt(isset($columns['ownerId']), FALSE);
     asrt(isset($columns['ownerCritic']), FALSE);
     asrt(isset($columns['sharedbyReader']), FALSE);
     R::nuke();
     $book = R::dispense('book');
     $book->xownerId = 2;
     $book->xownerCritic = 'a';
     $book->sharedbyReader = 'b';
     $id = R::store($book);
     $columns = R::inspect('book');
     asrt(isset($columns['xowner_id']), TRUE);
     asrt(isset($columns['xowner_critic']), TRUE);
     asrt(isset($columns['sharedby_reader']), TRUE);
     asrt(isset($columns['xownerId']), FALSE);
     asrt(isset($columns['xownerCritic']), FALSE);
     asrt(isset($columns['sharedbyReader']), FALSE);
 }
Ejemplo n.º 2
0
 /**
  * Test varchar 191 condition.
  *
  * @return void
  */
 public function testInnoDBIndexLimit()
 {
     R::nuke();
     $book = R::dispense('book');
     $book->text = 'abcd';
     R::store($book);
     $columns = R::inspect('book');
     asrt(isset($columns['text']), TRUE);
     asrt($columns['text'], 'varchar(191)');
     $book = $book->fresh();
     $book->text = str_repeat('x', 190);
     R::store($book);
     $columns = R::inspect('book');
     asrt(isset($columns['text']), TRUE);
     asrt($columns['text'], 'varchar(191)');
     $book = $book->fresh();
     $book->text = str_repeat('x', 191);
     R::store($book);
     $columns = R::inspect('book');
     asrt(isset($columns['text']), TRUE);
     asrt($columns['text'], 'varchar(191)');
     $book = $book->fresh();
     $book->text = str_repeat('x', 192);
     R::store($book);
     $columns = R::inspect('book');
     asrt(isset($columns['text']), TRUE);
     asrt($columns['text'], 'varchar(255)');
 }
Ejemplo n.º 3
0
 public function testDatabaseInstallation()
 {
     $this->url('index.php');
     //All Fields initially with empty
     $this->fillFields(array('hostname' => 'localhost', 'username' => 'root', 'password' => '', 'database' => 'phpback_test', 'adminemail' => '*****@*****.**', 'adminname' => 'admin', 'adminpass' => 'admin', 'adminrpass' => 'admin'));
     //Submit form
     $this->byName('install-form')->submit();
     //Should delete first intallation files
     $this->assertFileNotExists('install/index.php');
     $this->assertFileNotExists('install/install1.php');
     $this->assertFileNotExists('install/database_tables.sql');
     //Should create configuration file
     $this->assertFileExists('application/config/database.php');
     include 'application/config/database.php';
     $this->assertEquals($db['default']['username'], 'root');
     $this->assertEquals($db['default']['password'], '');
     $this->assertEquals($db['default']['database'], 'phpback_test');
     $this->assertEquals($db['default']['username'], 'root');
     $this->assertEquals($db['default']['dbdriver'], 'mysqli');
     //Should have updated database with new tables
     $this->assertEquals(RedBean::inspect(), array('_sessions', 'categories', 'comments', 'flags', 'ideas', 'logs', 'settings', 'users', 'votes'));
     //Should have created the admin user
     $adminUser = RedBean::load('users', 1);
     $this->assertEquals($adminUser->name, 'admin');
     $this->assertEquals($adminUser->email, '*****@*****.**');
     $this->assertEquals($adminUser->isadmin, '3');
     $this->assertEquals($adminUser->votes, '20');
 }
Ejemplo n.º 4
0
 /**
  * Test self referential N-M relations (page_page).
  * 
  * @return void
  */
 public function testSelfReferential()
 {
     $page = R::dispense('page')->setAttr('title', 'a');
     $page->sharedPage[] = R::dispense('page')->setAttr('title', 'b');
     R::store($page);
     $page = $page->fresh();
     $page = reset($page->sharedPage);
     asrt($page->title, 'b');
     $tables = array_flip(R::inspect());
     asrt(isset($tables['page_page']), true);
     $columns = R::inspect('page_page');
     asrt(isset($columns['page2_id']), true);
 }
Ejemplo n.º 5
0
 /**
  * Tests the R::inspect() method on the Facade.
  *
  * @return void
  */
 public function testInspect()
 {
     testpack('Test R::inspect() ');
     R::nuke();
     R::store(R::dispense('book')->setAttr('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');
 }
Ejemplo n.º 6
0
 /**
  * Test prettier tables using via().
  */
 public function testViaPrettification()
 {
     R::nuke();
     R::renameAssociation('tbl_author_tbl_friend', 'tbl_author_friend');
     $author = R::xdispense(AUTHOR);
     $author->name = 'Mr. Quill';
     $friend = R::xdispense(FRIEND);
     $friend->name = 'Muse';
     $author->{FRIENDLIST}[] = $friend;
     $id = R::store($author);
     //print_r(R::inspect()); exit;
     $author = R::load(AUTHOR, $id);
     $tables = array_flip(R::inspect());
     asrt(isset($tables['tbl_author_friend']), TRUE);
     asrt(isset($tables['tbl_author_tbl_friend']), FALSE);
     asrt(count($author->{FRIENDLIST}), 1);
     AQueryWriter::clearRenames();
 }
Ejemplo n.º 7
0
 /**
  * Test Facade bind function method.
  * Test for MySQL WKT spatial format.
  */
 public function testFunctionFilters()
 {
     R::nuke();
     R::bindFunc('read', 'location.point', 'asText');
     R::bindFunc('write', 'location.point', 'GeomFromText');
     R::store(R::dispense('location'));
     R::freeze(true);
     try {
         R::find('location');
         fail();
     } catch (SQL $exception) {
         pass();
     }
     R::freeze(false);
     try {
         R::find('location');
         pass();
     } catch (SQL $exception) {
         fail();
     }
     $location = R::dispense('location');
     $location->point = 'POINT(14 6)';
     R::store($location);
     $columns = R::inspect('location');
     asrt($columns['point'], 'point');
     $location = $location->fresh();
     asrt($location->point, 'POINT(14 6)');
     R::nuke();
     $location = R::dispense('location');
     $location->point = 'LINESTRING(0 0,1 1,2 2)';
     R::store($location);
     $columns = R::inspect('location');
     asrt($columns['point'], 'linestring');
     $location->bustcache = 2;
     R::store($location);
     $location = $location->fresh();
     asrt($location->point, 'LINESTRING(0 0,1 1,2 2)');
     R::nuke();
     $location = R::dispense('location');
     $location->point = 'POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7,5 5))';
     R::store($location);
     $columns = R::inspect('location');
     asrt($columns['point'], 'polygon');
     $location->bustcache = 4;
     R::store($location);
     $location = $location->fresh();
     asrt($location->point, 'POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7,5 5))');
     R::bindFunc('read', 'location.point', NULL);
     $location->bustcache = 1;
     R::store($location);
     $location = $location->fresh();
     asrt($location->point === 'POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7,5 5))', FALSE);
     $filters = AQueryWriter::getSQLFilters();
     asrt(is_array($filters), TRUE);
     asrt(count($filters), 2);
     asrt(isset($filters[QueryWriter::C_SQLFILTER_READ]), TRUE);
     asrt(isset($filters[QueryWriter::C_SQLFILTER_WRITE]), TRUE);
     R::bindFunc('read', 'place.point', 'asText');
     R::bindFunc('write', 'place.point', 'GeomFromText');
     R::bindFunc('read', 'place.line', 'asText');
     R::bindFunc('write', 'place.line', 'GeomFromText');
     R::nuke();
     $place = R::dispense('place');
     $place->point = 'POINT(13.2 666.6)';
     $place->line = 'LINESTRING(9.2 0,3 1.33)';
     R::store($place);
     $columns = R::inspect('place');
     asrt($columns['point'], 'point');
     asrt($columns['line'], 'linestring');
     $place = R::findOne('place');
     asrt($place->point, 'POINT(13.2 666.6)');
     asrt($place->line, 'LINESTRING(9.2 0,3 1.33)');
     R::bindFunc('read', 'place.point', NULL);
     R::bindFunc('write', 'place.point', NULL);
     R::bindFunc('read', 'place.line', NULL);
     R::bindFunc('write', 'place.line', NULL);
 }
Ejemplo n.º 8
0
 /**
  * Tests whether we can update or unset a parent bean
  * with an alias without having to use fetchAs and
  * without loading the aliased bean causing table-not-found
  * errors.
  */
 public function testUpdatingParentBeansWithAliases()
 {
     testpack('Test updating parent beans with aliases');
     R::nuke();
     $trans = R::dispense('transaction');
     $seller = R::dispense('user');
     $trans->seller = $seller;
     $id = R::store($trans);
     R::freeze(true);
     $trans = R::load('transaction', $id);
     //should not try to load seller, should not require fetchAs().
     try {
         $trans->seller = R::dispense('user');
         pass();
     } catch (Exception $e) {
         fail();
     }
     $trans = R::load('transaction', $id);
     //same for unset...
     try {
         unset($trans->seller);
         pass();
     } catch (Exception $e) {
         fail();
     }
     R::freeze(false);
     $account = R::dispense('user');
     asrt(count($account->alias('seller')->ownTransaction), 0);
     $account->alias('seller')->ownTransaction = R::dispense('transaction', 10);
     $account->alias('boo');
     //try to trick me...
     $id = R::store($account);
     R::freeze(true);
     $account = R::load('user', $id);
     asrt(count($account->alias('seller')->ownTransaction), 10);
     //you cannot unset a list
     unset($account->alias('seller')->ownTransaction);
     $id = R::store($account);
     $account = R::load('user', $id);
     asrt(count($account->alias('seller')->ownTransaction), 10);
     $account->alias('seller')->ownTransaction = array();
     $id = R::store($account);
     $account = R::load('user', $id);
     asrt(count($account->alias('seller')->ownTransaction), 0);
     asrt(count($account->ownTransaction), 0);
     R::freeze(false);
     //but also make sure we don't cause extra column issue #335
     R::nuke();
     $building = R::dispense('building');
     $village = R::dispense('village');
     $building->village = $village;
     R::store($building);
     $building = $building->fresh();
     $building->village = NULL;
     R::store($building);
     $building = $building->fresh();
     $columns = R::inspect('building');
     asrt(isset($columns['village']), false);
     asrt(isset($building->village), false);
     R::nuke();
     $building = R::dispense('building');
     $village = R::dispense('village');
     $building->village = $village;
     R::store($building);
     $building = $building->fresh();
     unset($building->village);
     R::store($building);
     $building = $building->fresh();
     $columns = R::inspect('building');
     asrt(isset($columns['village']), false);
     asrt(isset($building->village), false);
     $building = R::dispense('building');
     $village = R::dispense('village');
     $building->village = $village;
     R::store($building);
     $building = $building->fresh();
     $building->village = false;
     R::store($building);
     $building = $building->fresh();
     $columns = R::inspect('building');
     asrt(isset($columns['village']), false);
     asrt(isset($building->village), false);
 }
Ejemplo n.º 9
0
 public static function filter($table, $info)
 {
     if (false !== ($list = R::inspect($type))) {
         $fields = array();
         foreach ($list as $key => $record) {
             $fields[] = $key;
         }
         return array_values(array_intersect($fields, array_keys($info)));
     }
     return array();
 }