id, 0 ); R::freeze( TRUE ); $exception = NULL; try { $book = R::load( 'book', 1 ); } catch( RedException $exception ) {} asrt( ( $exception instanceof RedException ), TRUE ); R::freeze( FALSE ); R::store( $book ); /* bean does not exist - table exists */ $book = R::load( 'book', 2 ); pass(); asrt( $book->id, 0 ); R::freeze( TRUE ); $book = R::load( 'book', 2 ); pass(); asrt( $book->id, 0 ); /* other error */ if ( !( R::getWriter() instanceof SQLiteT ) ) { R::freeze( FALSE ); $exception = NULL; try { $book = R::load( 'book', 1, 'invalid sql' ); } catch( RedException $exception ) {} //not supported for CUBRID if ($this->currentlyActiveDriverID !== 'CUBRID') { asrt( ( $exception instanceof RedException ), TRUE ); } } else { /* error handling in SQLite is suboptimal */ R::freeze( FALSE ); $book = R::load( 'book', 1, 'invalid sql' ); pass(); asrt( $book->id, 0 ); } R::freeze( TRUE ); $exception = NULL; try { $book = R::load( 'book', 1, 'invalid sql' ); } catch( RedException $exception ) {} asrt( ( $exception instanceof RedException ), TRUE ); R::freeze( FALSE ); R::nuke(); } /** * Test delete exceptions * * - in fluid mode no complaining about missing structures * * @return void */ public function testDeleteExceptions() { R::nuke(); $book = R::dispense( 'book' ); R::store( $book ); R::nuke(); R::trash( $book ); R::freeze( TRUE ); $exception = NULL; try { R::trash( $book ); } catch( RedException $exception ) {} asrt( ( $exception instanceof RedException ), TRUE ); R::freeze( FALSE ); $adapter = R::getDatabaseAdapter(); R::nuke(); $book = R::dispense( 'book' ); R::store( $book ); $broken = new BrokenWriter( $adapter ); $redbean = R::getRedBean(); $oodb = new OODB( $broken, $redbean->isFrozen() ); R::setRedBean( $oodb ); $exception = NULL; try { R::trash( $book ); } catch( RedException $exception ) {} asrt( ( $exception instanceof RedException ), TRUE ); R::freeze( TRUE ); $exception = NULL; try { R::trash( $book ); } catch( RedException $exception ) {} asrt( ( $exception instanceof RedException ), TRUE ); R::setRedBean( $redbean ); } /** * Test chaining of exceptions. * * @return void */ public function testChainingExceptions() { R::freeze( TRUE ); $exception = NULL; try { $book = R::load( 'book', 1, 'invalid sql' ); } catch( RedException $exception ) {} pass(); asrt( ( $exception instanceof RedException ), TRUE ); asrt( ( $exception->getPrevious() instanceof \Exception ), TRUE ); } } class BrokenWriter extends SQLiteT { public function deleteRecord( $type, $conditions = array(), $addSql = NULL, $bindings = array() ) { throw new SQLException('oops'); } }