Skip to content

Commit

Permalink
Fix issues with Hybrid Mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
gabordemooij committed Dec 26, 2019
1 parent 58770a1 commit 58d366a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
4 changes: 2 additions & 2 deletions RedBeanPHP/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,10 +619,10 @@ public static function store( $bean, $unfreezeIfNeeded = FALSE )
$result = self::$redbean->store( $bean );
} catch (SQLException $exception) {
$wasFrozen = self::$redbean->isFrozen();
if ( !self::$allowHybridMode || !$wasFrozen ) throw $exception;
if ( !self::$allowHybridMode || !$unfreezeIfNeeded ) throw $exception;
self::freeze( FALSE );
$result = self::$redbean->store( $bean );
self::freeze( !$wasFrozen );
self::freeze( $wasFrozen );
}
return $result;
}
Expand Down
34 changes: 28 additions & 6 deletions testing/RedUNIT/Base/Hybrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ public function testHybrid()
R::setAllowHybridMode( FALSE );
$book->title = 'Tales of a misfit';
try {
R::store( $book );
R::store( $book, TRUE );
fail();
} catch(\Exception $e) {
pass();
}
try {
R::store( $book, FALSE );
fail();
} catch(\Exception $e) {
pass();
Expand All @@ -48,6 +54,18 @@ public function testHybrid()
$book->title = 'Tales of a misfit';
try {
R::store( $book );
fail();
} catch(\Exception $e) {
pass();
}
try {
R::store( $book, FALSE );
fail();
} catch(\Exception $e) {
pass();
}
try {
R::store( $book, TRUE );
pass();
} catch(\Exception $e) {
fail();
Expand All @@ -71,24 +89,28 @@ public function testHybridDataType()
if ($this->currentlyActiveDriverID == 'sqlite') return;
$book = R::dispense('book');
$book->pages = 1;
$id = R::store( $book );
$id = R::store( $book, TRUE );
R::freeze( TRUE );
asrt( R::getRedBean()->isFrozen(), TRUE );
R::setAllowHybridMode( FALSE );
$book->pages = 'too many';
try {
R::store( $book );
R::store( $book, TRUE );
fail();
} catch(\Exception $e) {
pass();
}
asrt( R::getRedBean()->isFrozen(), TRUE );
R::setAllowHybridMode( TRUE );
asrt( R::getRedBean()->isFrozen(), TRUE );
R::debug(1);
try {
R::store( $book );
R::store( $book, TRUE );
pass();
} catch(\Exception $e) {
fail();
}
asrt( R::getRedBean()->isFrozen(), TRUE );
$book = $book->fresh();
echo $book;
asrt( $book->pages, 'too many' );
Expand All @@ -109,7 +131,7 @@ public function testHybridNonSQLException()
R::freeze( TRUE );
R::setAllowHybridMode( TRUE );
try {
R::store( $toy );
R::store( $toy, TRUE );
fail();
} catch(\Exception $e) {
pass();
Expand All @@ -120,7 +142,7 @@ public function testHybridNonSQLException()
R::freeze( TRUE );
R::setAllowHybridMode( TRUE );
try {
R::store( $toy );
R::store( $toy, TRUE );
pass();
} catch(\Exception $e) {
fail();
Expand Down

0 comments on commit 58d366a

Please sign in to comment.