3 namespace RedUNIT\Mysql;
5 use RedUNIT\Mysql as Mysql;
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/Mysql/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 Mysql
28 * Test BIG INT primary key support.
32 public function testBigIntSupport()
36 $createPageTableSQL = '
40 id BIGINT(20) UNSIGNED NOT NULL,
41 book_id BIGINT(20) UNSIGNED NOT NULL,
42 magazine_id BIGINT(20) UNSIGNED NOT NULL,
46 ENGINE = InnoDB DEFAULT
48 COLLATE=utf8mb4_unicode_ci
49 AUTO_INCREMENT = 1223372036854775808';
51 $createBookTableSQL = '
55 id BIGINT(20) UNSIGNED NOT NULL,
59 ENGINE = InnoDB DEFAULT
61 COLLATE=utf8mb4_unicode_ci
62 AUTO_INCREMENT = 2223372036854775808';
64 $createPagePageTableSQL = '
68 id BIGINT(20) UNSIGNED NOT NULL,
69 page_id BIGINT(20) UNSIGNED NOT NULL,
70 page2_id BIGINT(20) UNSIGNED NOT NULL,
73 ENGINE = InnoDB DEFAULT
75 COLLATE=utf8mb4_unicode_ci
76 AUTO_INCREMENT = 3223372036854775808';
78 R::exec( $createBookTableSQL );
79 R::exec( $createPageTableSQL );
80 R::exec( $createPagePageTableSQL );
84 $book1ID = '2223372036854775808';
85 $book2ID = '2223372036854775809';
86 $page1ID = '1223372036854775808';
87 $page2ID = '1223372036854775809';
88 $page3ID = '1223372036854775890';
89 $pagePage1ID = '3223372036854775808';
92 INSERT INTO book (id, title) VALUES( '$book1ID', 'book 1' );
96 INSERT INTO book (id, title) VALUES( '$book2ID', 'book 2' );
100 INSERT INTO page (id, book_id, title, magazine_id) VALUES( '$page1ID', '$book1ID', 'page 1 of book 1', '$book2ID' );
104 INSERT INTO page (id, book_id, title) VALUES( '$page2ID', '$book1ID', 'page 2 of book 1' );
108 INSERT INTO page (id, book_id, title) VALUES( '$page3ID', '$book2ID', 'page 1 of book 2' );
111 $insertPagePage1SQL = "
112 INSERT INTO page_page (id, page_id, page2_id) VALUES( '$pagePage1ID', '$page2ID', '$page3ID' );
115 R::exec( $insertBook1SQL );
116 R::exec( $insertBook2SQL );
117 R::exec( $insertPage1SQL );
118 R::exec( $insertPage2SQL );
119 R::exec( $insertPage3SQL );
120 R::exec( $insertPagePage1SQL );
122 //basic tour of basic functions....
124 $book1 = R::load( 'book', $book1ID );
126 asrt( $book1->id, $book1ID );
127 asrt( $book1->title, 'book 1' );
129 $book2 = R::load( 'book', $book2ID );
131 asrt( $book2->id, $book2ID );
132 asrt( $book2->title, 'book 2' );
134 asrt( count( $book1->ownPage ), 2 );
135 asrt( count( $book1->fresh()->with( 'LIMIT 1' )->ownPage ), 1 );
136 asrt( count( $book1->fresh()->withCondition( ' title = ? ', array('page 2 of book 1'))->ownPage ), 1 );
138 asrt( count($book2->ownPage), 1 );
139 asrt( $book2->fresh()->countOwn( 'page' ), 1 );
141 $page1 = R::load( 'page', $page1ID );
142 asrt( count( $page1->sharedPage ), 0 );
143 asrt( $page1->fetchAs( 'book' )->magazine->id, $book2ID );
145 $page2 = R::load( 'page', $page2ID );
146 asrt( count($page2->sharedPage), 1 );
147 asrt( $page2->fresh()->countShared( 'page' ), 1 );
149 $page3 = R::findOne( 'page', ' title = ? ', array( 'page 1 of book 2' ) );
150 asrt( $page3->id, $page3ID );
151 asrt( $page3->book->id, $book2ID );