Skip to content
Permalink
Browse files

Fix issues with Hybrid Mode.

  • Loading branch information
gabordemooij committed Dec 26, 2019
1 parent 58770a1 commit 58d366ac135cf14c7b952cda075a7723dfb425a7
Showing with 30 additions and 8 deletions.
  1. +2 −2 RedBeanPHP/Facade.php
  2. +28 −6 testing/RedUNIT/Base/Hybrid.php
@@ -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;
}
@@ -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();
@@ -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();
@@ -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' );
@@ -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();
@@ -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();

0 comments on commit 58d366a

Please sign in to comment.
You can’t perform that action at this time.