3 namespace RedUNIT\Sqlite;
5 use RedUNIT\Sqlite as Sqlite;
6 use RedBeanPHP\Facade as R;
11 * SQLite cannot ALTER tables like other databases can.
12 * To implement fluid mode in RedBeanPHP we have to
13 * rebuild the entire table whenever we add or remove a column.
14 * This test class tests whether rebuilding tables works properly,
15 * i.e. we get the same table plus/minus some column...
17 * @file RedUNIT/Sqlite/Rebuild.php
18 * @desc Test rebuilding of tables for SQLite
19 * @author Gabor de Mooij and the RedBeanPHP Community
20 * @license New BSD/GPLv2
22 * (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
23 * This source file is subject to the New BSD/GPLv2 License that is bundled
24 * with this source code in the file license.txt.
26 class Rebuild extends Sqlite
29 * Test SQLite table rebuilding.
33 public function testRebuilder()
35 $toolbox = R::getToolBox();
36 $adapter = $toolbox->getDatabaseAdapter();
37 $writer = $toolbox->getWriter();
38 $redbean = $toolbox->getRedBean();
39 $pdo = $adapter->getDatabase();
40 $book = R::dispense( 'book' );
41 $page = R::dispense( 'page' );
42 $book->xownPage[] = $page;
43 $id = R::store( $book );
44 $book = R::load( 'book', $id );
45 asrt( count( $book->xownPage ), 1 );
46 asrt( (int) R::getCell( 'SELECT COUNT(*) FROM page' ), 1 );
48 asrt( (int) R::getCell( 'SELECT COUNT(*) FROM page' ), 0 );
49 $book = R::dispense( 'book' );
50 $page = R::dispense( 'page' );
51 $book->xownPage[] = $page;
52 $id = R::store( $book );
53 $book = R::load( 'book', $id );
54 asrt( count( $book->xownPage ), 1 );
55 asrt( (int) R::getCell( 'SELECT COUNT(*) FROM page' ), 1 );
58 $book->added = 'added';
61 asrt( (int) R::getCell( 'SELECT COUNT(*) FROM page' ), 0 );