3 namespace RedUNIT\Base;
5 use RedUNIT\Base as Base;
6 use RedBeanPHP\Facade as R;
11 * Tests whether this specific issue on github has been resolved.
12 * Tests whether we can use export on beans having arrays in properties.
14 * @file RedUNIT/Mysql/Issue408.php
15 * @desc Test whether we can export beans with arrays in properties
16 * (deserialized/serialized on open/update).
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 Issue408 extends Base
28 * In the past it was not possible to export beans
29 * like 'feed' (Model_Feed).
33 public function testExportIssue()
36 $feed = R::dispense( 'feed' );
42 $rows = R::getAll('SELECT * FROM feed');
43 asrt( $rows[0]['post'], '["first","second"]' );
44 $feed = $feed->fresh();
45 asrt( is_array( $feed->post ), TRUE );
46 asrt( $feed->post[0], 'first' );
47 asrt( $feed->post[1], 'second' );
49 $rows = R::getAll('SELECT * FROM feed');
50 asrt( $rows[0]['post'], '["first","second"]' );
51 $feed = R::load( 'feed', $feed->id );
52 $feed->post[] = 'third';
54 $rows = R::getAll('SELECT * FROM feed');
55 asrt( $rows[0]['post'], '["first","second","third"]' );
56 $feed = $feed->fresh();
57 asrt( is_array( $feed->post ), TRUE );
58 asrt( $feed->post[0], 'first' );
59 asrt( $feed->post[1], 'second' );
60 asrt( $feed->post[2], 'third' );
61 //now the catch: can we use export?
62 //PHP Fatal error: Call to a member function export() on a non-object
63 $feeds = R::exportAll( R::find( 'feed' ) );
64 asrt( is_array( $feeds ), TRUE );
65 $feed = reset( $feeds );
66 asrt( $feed['post'][0], 'first' );
67 asrt( $feed['post'][1], 'second' );
68 asrt( $feed['post'][2], 'third' );
70 $feedOne = R::findOne( 'feed' );
71 R::store( R::dup( $feedOne ) );
72 asrt( R::count( 'feed' ), 2 );
75 asrt( R::count( 'feed' ), 1 );
76 $feedTwo = R::findOne( 'feed' );
77 $feed = $feedTwo->export();
78 asrt( $feed['post'][0], 'first' );
79 asrt( $feed['post'][1], 'second' );
80 asrt( $feed['post'][2], 'third' );