3 namespace RedUNIT\Postgres;
5 use RedUNIT\Postgres as Postgres;
6 use RedBeanPHP\Facade as R;
11 * Tests handling of bigint type columns for primary key IDs,
12 * can we use bigint primary keys without issues ?
13 * These tests should be able to detect incorrect intval
16 * @file RedUNIT/Postgres/Bigint.php
17 * @desc Tests support for BIGINT primary keys.
18 * @author Gabor de Mooij and the RedBeanPHP Community
19 * @license New BSD/GPLv2
21 * (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
22 * This source file is subject to the New BSD/GPLv2 License that is bundled
23 * with this source code in the file license.txt.
25 class Bigint extends Postgres
28 * Test BIG INT primary key support.
32 public function testBigIntSupport()
36 $createPageTableSQL = '
40 id BIGSERIAL PRIMARY KEY,
42 magazine_id BIGSERIAL,
46 $createBookTableSQL = '
50 id BIGSERIAL PRIMARY KEY,
54 $createPagePageTableSQL = '
58 id BIGSERIAL PRIMARY KEY,
63 R::exec( $createBookTableSQL );
64 R::exec( $createPageTableSQL );
65 R::exec( $createPagePageTableSQL );
69 $book1ID = '2223372036854775808';
70 $book2ID = '2223372036854775809';
71 $page1ID = '1223372036854775808';
72 $page2ID = '1223372036854775809';
73 $page3ID = '1223372036854775890';
74 $pagePage1ID = '3223372036854775808';
76 R::exec("ALTER SEQUENCE book_id_seq RESTART WITH $book1ID");
77 R::exec("ALTER SEQUENCE page_id_seq RESTART WITH $page1ID");
78 R::exec("ALTER SEQUENCE page_page_id_seq RESTART WITH $pagePage1ID");
81 INSERT INTO book (title) VALUES( 'book 1' );
85 INSERT INTO book (title) VALUES( 'book 2' );
89 INSERT INTO page (id, book_id, title, magazine_id) VALUES( '$page1ID', '$book1ID', 'page 1 of book 1', '$book2ID' );
93 INSERT INTO page (id, book_id, title) VALUES( '$page2ID', '$book1ID', 'page 2 of book 1' );
97 INSERT INTO page (id, book_id, title) VALUES( '$page3ID', '$book2ID', 'page 1 of book 2' );
100 $insertPagePage1SQL = "
101 INSERT INTO page_page (id, page_id, page2_id) VALUES( '$pagePage1ID', '$page2ID', '$page3ID' );
104 R::exec( $insertBook1SQL );
105 R::exec( $insertBook2SQL );
106 R::exec( $insertPage1SQL );
107 R::exec( $insertPage2SQL );
108 R::exec( $insertPage3SQL );
109 R::exec( $insertPagePage1SQL );
111 //basic tour of basic functions....
112 $book1 = R::load( 'book', $book1ID );
114 asrt( $book1->id, $book1ID );
115 asrt( $book1->title, 'book 1' );
117 $book2 = R::load( 'book', $book2ID );
119 asrt( $book2->id, $book2ID );
120 asrt( $book2->title, 'book 2' );
122 asrt( count( $book1->ownPage ), 2 );
123 asrt( count( $book1->fresh()->with( 'LIMIT 1' )->ownPage ), 1 );
124 asrt( count( $book1->fresh()->withCondition( ' title = ? ', array('page 2 of book 1'))->ownPage ), 1 );
126 asrt( count($book2->ownPage), 1 );
127 asrt( $book2->fresh()->countOwn( 'page' ), 1 );
129 $page1 = R::load( 'page', $page1ID );
130 asrt( count( $page1->sharedPage ), 0 );
131 asrt( $page1->fetchAs( 'book' )->magazine->id, $book2ID );
133 $page2 = R::load( 'page', $page2ID );
134 asrt( count($page2->sharedPage), 1 );
135 asrt( $page2->fresh()->countShared( 'page' ), 1 );
137 $page3 = R::findOne( 'page', ' title = ? ', array( 'page 1 of book 2' ) );
138 asrt( $page3->id, $page3ID );
139 asrt( $page3->book->id, $book2ID );