Yaffs site version 1.1
[yaffs-website] / vendor / gabordemooij / redbean / testing / RedUNIT / Base / Boxing.php
1 <?php
2
3 namespace RedUNIT\Base;
4
5 use RedUNIT\Base as Base;
6 use RedBeanPHP\Facade as R;
7 use RedBeanPHP\SimpleModel as SimpleModel;
8
9 /**
10  * Boxing
11  *
12  * Test boxing and unboxing of beans.
13  *
14  * @file    RedUNIT/Base/Boxing.php
15  * @desc    Tests bean boxing and unboxing functionality.
16  * @author  Gabor de Mooij and the RedBeanPHP Community
17  * @license New BSD/GPLv2
18  *
19  * (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
20  * This source file is subject to the New BSD/GPLv2 License that is bundled
21  * with this source code in the file license.txt.
22  */
23 class Boxing extends Base
24 {
25
26         /**
27          * Test boxing beans.
28          *
29          * @return void
30          */
31         public function testBoxing()
32         {
33                 R::nuke();
34                 $bean = R::dispense( 'boxedbean' )->box();
35                 R::trash( $bean );
36                 pass();
37                 $bean = R::dispense( 'boxedbean' );
38                 $bean->sharedBoxbean = R::dispense( 'boxedbean' )->box();
39                 R::store( $bean );
40                 pass();
41                 $bean = R::dispense( 'boxedbean' );
42                 $bean->ownBoxedbean = R::dispense( 'boxedbean' )->box();
43                 R::store( $bean );
44                 pass();
45                 $bean = R::dispense( 'boxedbean' );
46                 $bean->other = R::dispense( 'boxedbean' )->box();
47                 R::store( $bean );
48                 pass();
49                 $bean = R::dispense( 'boxedbean' );
50                 $bean->title = 'MyBean';
51                 $box = $bean->box();
52                 asrt( ( $box instanceof \Model_Boxedbean ), TRUE );
53                 R::store( $box );
54         }
55
56         /**
57          * Test fix for issue #512 - thanks for reporting Bernhard H.
58          * OODBBean::__toString() implementation only works with C_ERR_IGNORE
59          *
60          * @return void
61          */
62         public function testToStringIssue512()
63         {
64                 R::setErrorHandlingFUSE( \RedBeanPHP\OODBBean::C_ERR_FATAL );
65                 $boxedBean = R::dispense( 'boxedbean' );
66                 $str = (string) $boxedBean;
67                 asrt( $str, '{"id":0}' ); //no fatal error
68                 R::setErrorHandlingFUSE( FALSE );
69         }
70 }