Issues (590)

bench/Entity/EntityHydrationBench.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace Bdf\Prime\Entity;
4
5
require_once __DIR__.'/../../tests/_files/PrimeTestCase.php';
6
require_once __DIR__.'/../../tests/_files/HydratorGeneration.php';
7
require_once __DIR__.'/../../tests/_files/array_hydrator_entities.php';
8
9
use Bdf\Prime\ArrayHydratorTestEntity;
0 ignored issues
show
The type Bdf\Prime\ArrayHydratorTestEntity was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Bdf\Prime\Bench\HydratorGeneration;
11
use Bdf\Prime\EmbeddedEntity;
0 ignored issues
show
The type Bdf\Prime\EmbeddedEntity was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Bdf\Prime\Entity\Hydrator\ArrayHydrator;
13
use Bdf\Prime\Entity\Hydrator\HydratorGeneratedInterface;
14
use Bdf\Prime\PrimeTestCase;
15
use Bdf\Serializer\Serializer;
16
use Bdf\Serializer\SerializerBuilder;
17
18
/**
19
 * @Revs(1000)
20
 */
21
class EntityHydrationBench extends \BenchCaseAdapter
22
{
23
    use PrimeTestCase;
24
    use HydratorGeneration;
25
26
    /**
27
     * @var array
28
     */
29
    protected $data;
30
31
    /**
32
     * @var int
33
     */
34
    protected $times;
35
36
    /**
37
     * @var ArrayHydratorTestEntity
38
     */
39
    protected $entity;
40
41
    /**
42
     * @var ArrayHydrator
43
     */
44
    protected $hydrator;
45
46
    /**
47
     * @var HydratorGeneratedInterface
48
     */
49
    protected $generated;
50
51
    /**
52
     * @var Serializer
53
     */
54
    protected $serializer;
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function setUp()
60
    {
61
        $this->configurePrime();
62
63
        $this->data = [
64
            'name' => 'Bob',
65
            'phone' => '0123654987',
66
            'password' => 'bob',
67
            'ref' => [
68
                'id' => 15
69
            ],
70
            'ref2' => new EmbeddedEntity(123)
71
        ];
72
73
        $this->times = 1000;
74
75
        $this->entity = new ArrayHydratorTestEntity();
76
77
        $this->hydrator = new ArrayHydrator();
78
        $this->serializer = SerializerBuilder::create()->build();
79
        $this->generated = $this->createGeneratedHydrator(ArrayHydratorTestEntity::class);
80
81
        $this->entity->import($this->data);
82
    }
83
84
    /**
85
     * @Groups({"import"})
86
     */
87
    public function bench_ArrayInjector_fromArray()
88
    {
89
        $this->entity->import($this->data);
90
    }
91
92
    /**
93
     * @Groups({"import"})
94
     *
95
     */
96
    public function bench_ArrayHydrator_hydrate()
97
    {
98
        $this->hydrator->hydrate($this->entity, $this->data);
99
    }
100
101
    /**
102
     * @Groups({"import"})
103
     *
104
     */
105
    public function bench_Serializer_hydrate()
106
    {
107
        $this->serializer->fromArray($this->data, $this->entity);
108
    }
109
110
    /**
111
     * @Groups({"import"})
112
     *
113
     */
114
    public function bench_GeneratedHydrator()
115
    {
116
        $this->generated->hydrate($this->entity, $this->data);
117
    }
118
119
    /**
120
     * @Groups({"export"})
121
     *
122
     */
123
    public function bench_ArrayInjector_toArray()
124
    {
125
        return $this->entity->export();
126
    }
127
128
    /**
129
     * @Groups({"export"})
130
     *
131
     */
132
    public function bench_ArrayHydrator_extract()
133
    {
134
        return $this->hydrator->extract($this->entity);
135
    }
136
137
    /**
138
     * @Groups({"export"})
139
     *
140
     */
141
    public function bench_Serializer_toArray()
142
    {
143
        return $this->serializer->toArray($this->entity);
144
    }
145
146
    /**
147
     * @Groups({"export"})
148
     *
149
     */
150
    public function bench_Generated_extract()
151
    {
152
        return $this->generated->extract($this->entity);
153
    }
154
155
    /**
156
     * @Groups({"export-filter"})
157
     *
158
     */
159
    public function bench_ArrayInjector_toArray_with_filter()
160
    {
161
        return $this->entity->export(['name', 'phone', 'ref']);
162
    }
163
164
    /**
165
     * @Groups({"export-filter"})
166
     *
167
     */
168
    public function bench_ArrayHydrator_extract_with_filter()
169
    {
170
        return $this->hydrator->extract($this->entity, ['name', 'phone', 'ref']);
171
    }
172
173
    /**
174
     * @Groups({"export-filter"})
175
     *
176
     */
177
    public function bench_Serializer_toArray_with_filter()
178
    {
179
        return $this->serializer->toArray($this->entity, ['include' => ['name', 'phone', 'ref']]);
180
    }
181
182
    /**
183
     * @Groups({"export-filter"})
184
     *
185
     */
186
    public function bench_Generated_extract_with_filter()
187
    {
188
        return $this->generated->extract($this->entity, ['name', 'phone', 'ref']);
189
    }
190
}
191