3 namespace RedUNIT\Base;
5 use RedUNIT\Base as Base;
6 use RedBeanPHP\Facade as R;
7 use RedBeanPHP\OODBBean as OODBBean;
12 * Tests whether RedBeanPHP can use cursors (using the
13 * findCollection method) to iterate over large data sets.
15 * @file RedUNIT/Base/Cursors.php
16 * @desc Tests whether we can use cursors
17 * @author Gabor de Mooij and the RedBeanPHP Community
18 * @license New BSD/GPLv2
20 * (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
21 * This source file is subject to the New BSD/GPLv2 License that is bundled
22 * with this source code in the file license.txt.
24 class Cursors extends Base
27 * Test basic cursor functionality.
31 public function testBasicCursors()
34 for( $i=0; $i<20; $i++ ) {
35 $page = R::dispense( 'page' );
37 $page->content = sha1( $i );
40 $collection = R::findCollection( 'page' );
41 asrt( get_class( $collection ), 'RedBeanPHP\BeanCollection');
44 while( $bean = $collection->next() ) {
45 asrt( ( $bean instanceof OODBBean ), TRUE );
46 asrt( (string) $bean->number, strval( $i ) );
47 asrt( $bean->content, sha1( $i ) );
48 $list[] = $bean->content;
51 $collection = R::findCollection( 'page', ' ORDER BY content ASC ' );
54 while( $bean = $collection->next() ) {
55 asrt( $bean->content, $list[$i] );
58 $collection = R::findCollection( 'page', ' ORDER BY content ASC LIMIT 5 ' );
61 while( $bean = $collection->next() ) {
62 asrt( $bean->content, $list[$i] );
66 $key = array_rand( $list );
67 $content = $list[ $key ];
68 $collection = R::findCollection( 'page', ' content = ? ', array( $content ) );
69 $bean = $collection->next();
70 asrt( $bean->content, $content );
75 * Test empty collections (NULLCursor).
79 public function testEmptyCollection()
82 $page = R::dispense( 'page' );
83 $page->content = 'aaa';
85 $collection = R::findCollection( 'page' );
86 asrt( get_class( $collection ), 'RedBeanPHP\BeanCollection');
87 $collection = R::findCollection( 'page', ' content = ?', array( 'bbb' ) );
88 asrt( get_class( $collection ), 'RedBeanPHP\BeanCollection');
89 asrt( is_null( $collection->next() ), TRUE );
90 $collection = R::findCollection( 'something' );
91 asrt( get_class( $collection ), 'RedBeanPHP\BeanCollection');
92 asrt( is_null( $collection->next() ), TRUE );