GridBench::provideNbObjects()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\Grid\Benchmarks;
6
7
use Psi\Component\Grid\Tests\Functional\GridTestCase;
8
use Psi\Component\Grid\Tests\Model\Article;
9
10
/**
11
 * @BeforeMethods({"init"})
12
 * @Revs(100)
13
 * @Iterations(10)
14
 * @OutputTimeUnit("milliseconds")
15
 * @ParamProviders({"provideNbObjects"})
16
 */
17
class GridBench extends GridTestCase
18
{
19
    private $factory;
20
21
    public function init($params)
22
    {
23
        $nbObjects = $params['nb_objects'];
24
25
        $objects = [];
26
        for ($i = 0; $i < $nbObjects; $i++) {
27
            $objects[] = new Article('hello', $i);
28
        }
29
30
        $container = $this->createContainer([
31
            'mapping' => [
32
                Article::class => [
33
                    'grids' => [
34
                        'main' => [
35
                            'columns' => [
36
                                'title' => [
37
                                    'type' => 'property',
38
                                ],
39
                                'number' => [
40
                                    'type' => 'property',
41
                                ],
42
                            ],
43
                            'filters' => [
44
                                'title' => [
45
                                    'type' => 'string',
46
                                ],
47
                            ],
48
                        ],
49
                        'form' => [
50
                            'columns' => [
51
                                'select' => [
52
                                    'type' => 'select',
53
                                ],
54
                                'title' => [
55
                                    'type' => 'property',
56
                                ],
57
                                'number' => [
58
                                    'type' => 'property',
59
                                ],
60
                            ],
61
                            'filters' => [
62
                                'title' => [
63
                                    'type' => 'string',
64
                                ],
65
                            ],
66
                        ],
67
                    ],
68
                ],
69
            ],
70
            'collections' => [
71
                Article::class => $objects,
72
            ],
73
        ]);
74
75
        $this->factory = $container->get('grid.factory');
76
    }
77
78
    /**
79
     * @Subject()
80
     */
81
    public function grid_loading()
82
    {
83
        $this->factory->createGrid(Article::class, []);
84
    }
85
86
    /**
87
     * @Subject()
88
     */
89
    public function grid_loading_with_form()
90
    {
91
        $this->factory->createGrid(Article::class, [
92
            'variant' => 'form',
93
        ]);
94
    }
95
96
    public function provideNbObjects()
97
    {
98
        return [
99
            [
100
                'nb_objects' => 10,
101
            ],
102
            [
103
                'nb_objects' => 100,
104
            ],
105
            [
106
                'nb_objects' => 1000,
107
            ],
108
        ];
109
    }
110
}
111