Yaffs site version 1.1
[yaffs-website] / vendor / gabordemooij / redbean / testing / RedUNIT / Mysql / Issue411.php
1 <?php
2
3 namespace RedUNIT\Mysql;
4
5 use RedUNIT\Mysql as Mysql;
6 use RedBeanPHP\Facade as R;
7
8 /**
9  * Issue 411
10  *
11  * InnoDB has a maximum index length of 767 bytes, so with utf8mb4
12  * you can only store 191 characters. This means that when you
13  * subsequently add an index to the column you get a
14  * (not-so-obvious) MySQL-error.  That's why we limit the varchar to
15  * 191 chars and then switch to TEXT type.
16  *
17  * @file    RedUNIT/Mysql/Issue411.php
18  * @desc    Tests intermediate varchar 191 type for MySQL utf8mb4.
19  * @author  Gabor de Mooij and the RedBeanPHP Community
20  * @license New BSD/GPLv2
21  *
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.
25  */
26 class Issue411 extends Mysql
27 {
28
29         /**
30          * Test varchar 191 condition.
31          *
32          * @return void
33          */
34         public function testInnoDBIndexLimit()
35         {
36                 R::nuke();
37                 $book = R::dispense( 'book' );
38                 $book->text = 'abcd';
39                 R::store( $book );
40                 $columns = R::inspect( 'book' );
41                 asrt( isset( $columns['text'] ), TRUE );
42                 asrt( $columns['text'], 'varchar(191)' );
43                 $book = $book->fresh();
44                 $book->text = str_repeat( 'x', 190 );
45                 R::store( $book );
46                 $columns = R::inspect( 'book' );
47                 asrt( isset( $columns['text'] ), TRUE );
48                 asrt( $columns['text'], 'varchar(191)' );
49                 $book = $book->fresh();
50                 $book->text = str_repeat( 'x', 191 );
51                 R::store( $book );
52                 $columns = R::inspect( 'book' );
53                 asrt( isset( $columns['text'] ), TRUE );
54                 asrt( $columns['text'], 'varchar(191)' );
55                 $book = $book->fresh();
56                 $book->text = str_repeat( 'x', 192 );
57                 R::store( $book );
58                 $columns = R::inspect( 'book' );
59                 asrt( isset( $columns['text'] ), TRUE );
60                 asrt( $columns['text'], 'varchar(255)' );
61         }
62 }
63