Yaffs site version 1.1
[yaffs-website] / vendor / gabordemooij / redbean / testing / RedUNIT / Postgres / Parambind.php
1 <?php
2
3 namespace RedUNIT\Postgres;
4
5 use RedUNIT\Postgres as Postgres;
6 use RedBeanPHP\Facade as R;
7
8 /**
9  * Parambind
10  *
11  * Tests the parameter binding functionality in RedBeanPHP.
12  * These test scenarios include for instance: NULL handling,
13  * binding parameters in LIMIT clauses and so on.
14  *
15  * @file    RedUNIT/Postgres/Parambind.php
16  * @desc    Tests\PDO parameter binding for Postgres.
17  * @author  Gabor de Mooij and the RedBeanPHP Community
18  * @license New BSD/GPLv2
19  *
20  * (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
21  * This source file is subject to the New BSD/GPLv2 License that is bundled
22  * with this source code in the file license.txt.
23  */
24 class Parambind extends Postgres
25 {
26         /**
27          * Test parameter binding.
28          *
29          * @return void
30          */
31         public function testParamBindingWithPostgres()
32         {
33                 testpack( "param binding pgsql" );
34                 $page = R::dispense( "page" );
35                 $page->name   = "abc";
36                 $page->number = 2;
37                 R::store( $page );
38                 R::exec( "insert into page (name) values(:name) ", array( ":name" => "my name" ) );
39                 R::exec( "insert into page (number) values(:one) ", array( ":one" => 1 ) );
40                 R::exec( "insert into page (number) values(:one) ", array( ":one" => "1" ) );
41                 R::exec( "insert into page (number) values(:one) ", array( ":one" => "1234" ) );
42                 R::exec( "insert into page (number) values(:one) ", array( ":one" => "-21" ) );
43                 pass();
44                 testpack( 'Test whether we can properly bind and receive NULL values' );
45                 $adapter = R::getDatabaseAdapter();
46                 asrt( $adapter->getCell( 'SELECT TEXT( :nil ) ', array( ':nil' => 'NULL' ) ), 'NULL' );
47                 asrt( $adapter->getCell( 'SELECT TEXT( :nil ) ', array( ':nil' => NULL ) ), NULL );
48                 asrt( $adapter->getCell( 'SELECT TEXT( ? ) ', array( 'NULL' ) ), 'NULL' );
49                 asrt( $adapter->getCell( 'SELECT TEXT( ? ) ', array( NULL ) ), NULL );
50         }
51 }