More tidying.
[yaffs-website] / vendor / gabordemooij / redbean / testing / RedUNIT / Mysql / Setget.php
1 <?php
2
3 namespace RedUNIT\Mysql;
4
5 use RedUNIT\Mysql as Mysql;
6 use RedBeanPHP\Facade as R;
7
8 /**
9  * Setget
10  *
11  * This class has been designed to test set/get operations
12  * for a specific Query Writer / Adapter. Since RedBeanPHP
13  * creates columns based on values it's essential that you
14  * get back the 'same' value as you put in - or - if that's
15  * not the case, that there are at least very clear rules
16  * about what to expect. Examples of possible issues tested in
17  * this class include:
18  *
19  * - Test whether booleans are returned correctly (they will become integers)
20  * - Test whether large numbers are preserved
21  * - Test whether floating point numbers are preserved
22  * - Test whether date/time values are preserved
23  * and so on...
24  *
25  * @file    RedUNIT/Mysql/Setget.php
26  * @desc    Tests whether values are stored correctly.
27  * @author  Gabor de Mooij and the RedBeanPHP Community
28  * @license New BSD/GPLv2
29  *
30  * (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
31  * This source file is subject to the New BSD/GPLv2 License that is bundled
32  * with this source code in the file license.txt.
33  */
34 class Setget extends Mysql
35 {
36         /**
37          * Tests R::getInsertID convenience method.
38          *
39          * @return void
40          */
41         public function testGetInsertID()
42         {
43                 R::nuke();
44                 $id = R::store( R::dispense( 'book' ) );
45                 $id2 = R::getInsertID();
46                 asrt( $id, $id2 );
47         }
48
49         /**
50          * Test numbers.
51          *
52          * @return void
53          */
54         public function testNumbers()
55         {
56                 asrt( setget( "-1" ), "-1" );
57                 asrt( setget( -1 ), "-1" );
58
59                 asrt( setget( "-0.25" ), "-0.25" );
60                 asrt( setget( -0.25 ), "-0.25" );
61
62                 asrt( setget( "1.0" ), "1" );
63                 asrt( setget( 1.0 ), "1" );
64
65                 asrt( setget( "3.20" ), "3.20" );
66                 asrt( setget( "13.20" ), "13.20" );
67                 asrt( setget( "134.20" ), "134.20" );
68                 asrt( setget( 3.21 ), '3.21' );
69
70                 asrt( setget( "0.12345678" ), "0.12345678" );
71                 asrt( setget( 0.12345678 ), "0.12345678" );
72
73                 asrt( setget( "-0.12345678" ), "-0.12345678" );
74                 asrt( setget( -0.12345678 ), "-0.12345678" );
75
76                 asrt( setget( "2147483647" ), "2147483647" );
77                 asrt( setget( 2147483647 ), "2147483647" );
78
79                 asrt( setget( -2147483647 ), "-2147483647" );
80                 asrt( setget( "-2147483647" ), "-2147483647" );
81
82                 asrt( setget( -4294967295 ), "-4294967295" );
83                 asrt( setget( "-4294967295" ), "-4294967295" );
84
85                 asrt( setget( 4294967295 ), "4294967295" );
86                 asrt( setget( "4294967295" ), "4294967295" );
87
88                 asrt( setget( "2147483648" ), "2147483648" );
89                 asrt( setget( "-2147483648" ), "-2147483648" );
90
91                 asrt( setget( "199936710040730" ), "199936710040730" );
92                 asrt( setget( "-199936710040730" ), "-199936710040730" );
93
94                 //Architecture dependent... only test this if you are sure what arch
95                 //asrt(setget("2147483647123456"),"2.14748364712346e+15");
96                 //asrt(setget(2147483647123456),"2.14748364712e+15");
97         }
98
99         /**
100          * Test dates.
101          *
102          * @return void
103          */
104         public function testDates()
105         {
106                 asrt( setget( "2010-10-11" ), "2010-10-11" );
107                 asrt( setget( "2010-10-11 12:10" ), "2010-10-11 12:10" );
108                 asrt( setget( "2010-10-11 12:10:11" ), "2010-10-11 12:10:11" );
109                 asrt( setget( "x2010-10-11 12:10:11" ), "x2010-10-11 12:10:11" );
110         }
111
112         /**
113          * Test strings.
114          *
115          * @return void
116          */
117         public function testStrings()
118         {
119                 asrt( setget( "a" ), "a" );
120                 asrt( setget( "." ), "." );
121                 asrt( setget( "\"" ), "\"" );
122                 asrt( setget( "just some text" ), "just some text" );
123         }
124
125         /**
126          * Test booleans.
127          *
128          * @return void
129          */
130         public function testBool()
131         {
132                 asrt( setget( TRUE ), "1" );
133                 asrt( setget( FALSE ), "0" );
134
135                 asrt( setget( "TRUE" ), "TRUE" );
136                 asrt( setget( "FALSE" ), "FALSE" );
137         }
138
139         /**
140          * Test NULL.
141          *
142          * @return void
143          */
144         public function testNull()
145         {
146                 asrt( setget( "NULL" ), "NULL" );
147                 asrt( setget( "NULL" ), "NULL" );
148
149                 asrt( setget( "0123" ), "0123" );
150                 asrt( setget( "0000123" ), "0000123" );
151
152                 asrt( setget( NULL ), NULL );
153
154                 asrt( ( setget( 0 ) == 0 ), TRUE );
155                 asrt( ( setget( 1 ) == 1 ), TRUE );
156
157                 asrt( ( setget( TRUE ) == TRUE ), TRUE );
158                 asrt( ( setget( FALSE ) == FALSE ), TRUE );
159         }
160 }