3 namespace RedUNIT\Base;
5 use RedUNIT\Base as Base;
6 use RedBeanPHP\Facade as R;
11 * Tests 'chill' mode. In this mode some bean types are frozen,
12 * their schemas cannot be modified while others are fluid and
13 * can still be adjusted.
15 * @file RedUNIT/Base/Chill.php
16 * @desc Tests chill list functionality, i.e. freezing a subset of all types.
17 * @author Gabor de Mooij and the RedBeanPHP Community
18 * @license New BSD/GPLv2
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.
24 class Chill extends Base
31 public function testChill()
33 $bean = R::dispense( 'bean' );
40 asrt( count( R::getWriter()->getColumns( 'bean' ) ), 3 );
46 asrt( count( R::getWriter()->getColumns( 'bean' ) ), 4 );
48 R::freeze( array( 'umbrella' ) );
54 asrt( count( R::getWriter()->getColumns( 'bean' ) ), 5 );
56 R::freeze( array( 'bean' ) );
63 } catch (\Exception $e ) {
67 asrt( count( R::getWriter()->getColumns( 'bean' ) ), 5 );
75 asrt( count( R::getWriter()->getColumns( 'bean' ) ), 6 );
79 * Test whether we cannot add unique constraints on chilled tables,
80 * otherwise you cannot avoid this from happening when adding beans to the
81 * shared list :) -- this is almost a theoretical issue however we want it
82 * to work according to specifications!
86 public function testDontAddUniqueConstraintForChilledBeanTypes()
89 $person = R::dispense( 'person' );
90 $role = R::dispense( 'role' );
91 $person->sharedRole[] = $role;
93 $person->sharedRole[] = R::dispense( 'role' );
95 $bean = R::getRedBean()->dispense('person_role');
96 $bean->personId = $person->id;
97 $bean->roleId = $role->id;
101 } catch(\Exception $e) {
104 asrt(R::count('person_role'), 2);
107 $link = R::getRedBean()->dispense('person_role');
108 $person = R::dispense( 'person' );
109 $role = R::dispense( 'role' );
110 $link->person = $person;
113 R::freeze(array('person_role'));
114 $person->sharedRole[] = R::dispense( 'role' );
116 $bean = R::getRedBean()->dispense('person_role');
117 $bean->personId = $person->id;
118 $bean->roleId = $role->id;
122 } catch(\Exception $e) {
125 asrt(R::count('person_role'), 3);
126 R::freeze( array() ); //set freeze to FALSE and clear CHILL LIST!
130 * Test whether we can set and reset the chill list and check the contents
135 public function testChillTest()
137 R::freeze( array( 'beer' ) );
138 $oodb = R::getRedBean();
139 asrt( $oodb->isChilled( 'beer' ), TRUE );
140 asrt( $oodb->isChilled( 'wine' ), FALSE );
142 $oodb = R::getRedBean();
143 asrt( $oodb->isChilled( 'beer' ), TRUE );
144 asrt( $oodb->isChilled( 'wine' ), FALSE );
146 $oodb = R::getRedBean();
147 asrt( $oodb->isChilled( 'beer' ), TRUE );
148 asrt( $oodb->isChilled( 'wine' ), FALSE );
149 R::freeze( array() );
150 $oodb = R::getRedBean();
151 asrt( $oodb->isChilled( 'beer' ), FALSE );
152 asrt( $oodb->isChilled( 'wine' ), FALSE );