X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fgabordemooij%2Fredbean%2Ftesting%2FRedUNIT%2FBase%2FTypechecking.php;fp=vendor%2Fgabordemooij%2Fredbean%2Ftesting%2FRedUNIT%2FBase%2FTypechecking.php;h=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=ae3dc3192f0f1ced39d33d6736548a4835080d6f;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/vendor/gabordemooij/redbean/testing/RedUNIT/Base/Typechecking.php b/vendor/gabordemooij/redbean/testing/RedUNIT/Base/Typechecking.php deleted file mode 100644 index ae3dc3192..000000000 --- a/vendor/gabordemooij/redbean/testing/RedUNIT/Base/Typechecking.php +++ /dev/null @@ -1,151 +0,0 @@ - STRING - * NULL -> NULL - * - * @note Why not simply return bean->id in store()? Because not every driver returns the same type: - * databases without insert_id support require a separate query or a suffix returning STRINGS, not INTEGERS. - * - * @note Why not preserve types? I.e. I store integer, why do I get back a string? - * Answer: types are handled different across database platforms, would cause overhead to inspect every value for type, - * also PHP is a dynamically typed language so types should not matter that much. Another reason: due to the nature - * of RB columns in the database might change (INT -> STRING) this would cause return types to change as well which would - * cause 'cascading errors', i.e. a column gets widened and suddenly your code would break. - * - * @note Unfortunately the 32/64-bit issue cannot be tested fully. Return-strategy store() is probably the safest - * solution. - * - * @return void - */ - public function testTypes() - { - testpack( 'Beans can only contain STRING and NULL after reload' ); - R::nuke(); - $bean = R::dispense( 'bean' ); - $bean->number = 123; - $bean->float = 12.3; - $bean->bool = false; - $bean->bool2 = true; - $bean->text = 'abc'; - $bean->null = null; - $bean->datetime = new\DateTime( 'NOW', new\DateTimeZone( 'Europe/Amsterdam' ) ); - $id = R::store( $bean ); - asrt( is_int( $id ), TRUE ); - asrt( is_float( $bean->float ), TRUE ); - asrt( is_integer( $bean->number ), TRUE ); - asrt( is_string( $bean->bool ), TRUE ); - asrt( is_string( $bean->bool2 ), TRUE ); - asrt( is_string( $bean->datetime ), TRUE ); - asrt( is_string( $bean->text ), TRUE ); - asrt( is_null( $bean->null ), TRUE ); - $bean = R::load('bean', $id ); - asrt( is_string( $bean->id ), TRUE ); - asrt( is_string( $bean->float ), TRUE ); - asrt( is_string( $bean->number ), TRUE ); - asrt( is_string( $bean->bool ), TRUE ); - asrt( is_string( $bean->bool2 ), TRUE ); - asrt( is_string( $bean->datetime ), TRUE ); - asrt( is_string( $bean->text ), TRUE ); - asrt( is_null( $bean->null ), TRUE ); - asrt( $bean->bool, '0' ); - asrt( $bean->bool2, '1' ); - } - - /** - * Test bean type checking. - * - * @return void - */ - public function testBeanTypeChecking() - { - $redbean = R::getRedBean(); - $bean = $redbean->dispense( "page" ); - // Set some illegal values in the bean; this should trigger Security exceptions. - // Arrays are not allowed. - $bean->name = array( "1" ); - try { - $redbean->store( $bean ); - fail(); - } catch ( RedException $e ) { - pass(); - } - try { - $redbean->check( $bean ); - fail(); - } catch ( RedException $e ) { - pass(); - } - $bean->name = new OODBBean; - try { - $redbean->check( $bean ); - fail(); - } catch ( RedException $e ) { - pass(); - } - // Property names should be alphanumeric - $prop = "."; - $bean->$prop = 1; - try { - $redbean->store( $bean ); - fail(); - } catch ( RedException $e ) { - pass(); - } - try { - $redbean->check( $bean ); - fail(); - } catch ( RedException $e ) { - pass(); - } - // Really... - $prop = "-"; - $bean->$prop = 1; - try { - $redbean->store( $bean ); - fail(); - } catch ( RedException $e ) { - pass(); - } - try { - $redbean->check( $bean ); - fail(); - } catch ( RedException $e ) { - pass(); - } - } -}