Yaffs site version 1.1
[yaffs-website] / vendor / gabordemooij / redbean / testing / RedUNIT / Base / Performance.php
1 <?php
2
3 namespace RedUNIT\Base;
4
5 use RedUNIT\Base as Base;
6 use RedBeanPHP\Facade as R;
7 use RedBeanPHP\RedException as RedException;
8
9 /**
10  * Performance
11  *
12  * This performance test is used with runperf and xdebug profiler.
13  *
14  * @file    RedUNIT/Base/Performance.php
15  * @desc    Performance testing.
16  * @author  Gabor de Mooij and the RedBeanPHP Community
17  * @license New BSD/GPLv2
18  *
19  * (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
20  * This source file is subject to the New BSD/GPLv2 License that is bundled
21  * with this source code in the file license.txt.
22  */
23 class Performance extends Base
24 {
25         /**
26          * Setup
27          *
28          * @return void
29          */
30         public function setup()
31         {
32                 R::nuke();
33
34                 //Prepare structure
35                 $book = R::dispense( 'book' );
36                 $book->title = 'book';
37                 $pages = R::dispense( 'page', 10 );
38                 foreach( $pages as $page ) {
39                         $page->content = 'lorem ipsum';
40                         $page->title = 'data';
41                         $page->sequence = 'data';
42                         $page->order = 'data';
43                         $page->columns = 'data';
44                         $page->paragraphs = 'data';
45                         $page->paragraphs1 = 'data';
46                         $page->paragraphs2 = 'data';
47                         $page->paragraphs3 = 'data';
48                         $page->paragraphs4 = 'data';
49                 }
50                 $book->xownPageList = $pages;
51                 $tags = R::dispense( 'tag', 6 );
52                 foreach( $tags as $tag ) {
53                         $tag->label = 'tag';
54                 }
55                 $book->sharedTagList = $tags;
56                 R::store( $book );
57         }
58
59         /**
60          * CRUD performance.
61          *
62          * @return void
63          */
64         public function crud()
65         {
66                 R::freeze( TRUE );
67
68                 $book = R::dispense( 'book' );
69                 $book->title = 'Book';
70                 $page = R::dispense('page');
71                 $page->content = 'Content';
72                 $page->title = 'data';
73                 $page->sequence = 'data';
74                 $page->order = 'data';
75                 $page->columns = 'data';
76                 $page->paragraphs = 'data';
77                 $page->paragraphs1 = 'data';
78                 $page->paragraphs2 = 'data';
79                 $page->paragraphs3 = 'data';
80                 $page->paragraphs4 = 'data';
81                 $tag = R::dispense('tag');
82                 $tag->label = 'Tag ';
83                 $book->noLoad()->ownPage[] = $page;
84                 $book->noLoad()->sharedTag[] = $tag;
85                 R::store( $book );
86                 $book = $book->fresh();
87                 $book->ownPage;
88                 $book->sharedTag;
89                 R::trash( $book );
90
91         }
92
93         /**
94          * CRUD performance Array Access.
95          *
96          * @return void
97          */
98         public function crudaa()
99         {
100                 R::freeze( TRUE );
101
102                 $book = R::dispense( 'book' );
103                 $book['title'] = 'Book';
104                 $page = R::dispense('page');
105                 $page['content'] = 'Content';
106                 $page['title'] = 'data';
107                 $page['sequence'] = 'data';
108                 $page['order'] = 'data';
109                 $page['columns'] = 'data';
110                 $page['paragraphs'] = 'data';
111                 $page['paragraphs1'] = 'data';
112                 $page['paragraphs2'] = 'data';
113                 $page['paragraphs3'] = 'data';
114                 $page['paragraphs4'] = 'data';
115                 $tag = R::dispense('tag');
116                 $tag['label'] = 'Tag ';
117                 $book->ownPage[] = $page;
118                 $book->noLoad()->sharedTag[] = $tag;
119                 R::store( $book );
120                 $book = $book->fresh();
121                 $book->ownPage;
122                 $book->sharedTag;
123                 R::trash( $book );
124
125         }
126 }