From db8c69be6d4a89950459d7d04b1e02f53607c19a Mon Sep 17 00:00:00 2001 From: Gabor de Mooij Date: Fri, 2 Jan 2015 11:00:28 -0500 Subject: [PATCH] Non-beans in lists wont cause export to fail anymore. Close #408. --- RedBeanPHP/OODBBean.php | 1 + testing/RedUNIT/Base/Issue408.php | 79 +++++++++++++++++++++++++++++++ testing/cli/runtests.php | 1 + testing/helpers/classes.php | 11 +++++ 4 files changed, 92 insertions(+) create mode 100644 testing/RedUNIT/Base/Issue408.php diff --git a/RedBeanPHP/OODBBean.php b/RedBeanPHP/OODBBean.php index ba10e916a..2655611b7 100755 --- a/RedBeanPHP/OODBBean.php +++ b/RedBeanPHP/OODBBean.php @@ -434,6 +434,7 @@ public function export( $meta = FALSE, $parents = FALSE, $onlyMe = FALSE, $filte $vn = array(); foreach ( $value as $i => $b ) { + if ( !( $b instanceof OODBBean ) ) continue; $vn[] = $b->export( $meta, FALSE, FALSE, $filters ); $value = $vn; } diff --git a/testing/RedUNIT/Base/Issue408.php b/testing/RedUNIT/Base/Issue408.php new file mode 100644 index 000000000..629a8d9e5 --- /dev/null +++ b/testing/RedUNIT/Base/Issue408.php @@ -0,0 +1,79 @@ +post = array( + 'first', + 'second' + ); + R::store( $feed ); + $rows = R::getAll('SELECT * FROM feed'); + asrt( $rows[0]['post'], '["first","second"]' ); + $feed = $feed->fresh(); + asrt( is_array( $feed->post ), TRUE ); + asrt( $feed->post[0], 'first' ); + asrt( $feed->post[1], 'second' ); + R::store( $feed ); + $rows = R::getAll('SELECT * FROM feed'); + asrt( $rows[0]['post'], '["first","second"]' ); + $feed = R::load( 'feed', $feed->id ); + $feed->post[] = 'third'; + R::store( $feed ); + $rows = R::getAll('SELECT * FROM feed'); + asrt( $rows[0]['post'], '["first","second","third"]' ); + $feed = $feed->fresh(); + asrt( is_array( $feed->post ), TRUE ); + asrt( $feed->post[0], 'first' ); + asrt( $feed->post[1], 'second' ); + asrt( $feed->post[2], 'third' ); + //now the catch: can we use export? + //PHP Fatal error: Call to a member function export() on a non-object + $feeds = R::exportAll( R::find( 'feed' ) ); + asrt( is_array( $feeds ), TRUE ); + $feed = reset( $feeds ); + asrt( $feed['post'][0], 'first' ); + asrt( $feed['post'][1], 'second' ); + asrt( $feed['post'][2], 'third' ); + //can we also dup()? + $feedOne = R::findOne( 'feed' ); + R::store( R::dup( $feedOne ) ); + asrt( R::count( 'feed' ), 2 ); + //can we delete? + R::trash( $feedOne ); + asrt( R::count( 'feed' ), 1 ); + $feedTwo = R::findOne( 'feed' ); + $feed = $feedTwo->export(); + asrt( $feed['post'][0], 'first' ); + asrt( $feed['post'][1], 'second' ); + asrt( $feed['post'][2], 'third' ); + } +} diff --git a/testing/cli/runtests.php b/testing/cli/runtests.php index 5900e8281..023417093 100644 --- a/testing/cli/runtests.php +++ b/testing/cli/runtests.php @@ -127,6 +127,7 @@ function activate_driver( $d ) 'Blackhole/Plugins', 'Blackhole/Debug', 'Base/Dispense', + 'Base/Issue408', 'Base/Threeway', 'Base/Chill', 'Base/Arrays', diff --git a/testing/helpers/classes.php b/testing/helpers/classes.php index 2398f6901..edf743164 100644 --- a/testing/helpers/classes.php +++ b/testing/helpers/classes.php @@ -412,6 +412,17 @@ public function delete() { } } +class Model_Feed extends \RedbeanPHP\SimpleModel { + public function update() { + $this->bean->post = json_encode($this->bean->post); + } + + public function open() { + $this->bean->post = json_decode($this->bean->post, true); + } +} + + /** * UUID QueryWriter for MySQL for testing purposes. */