Failed Conditions
Pull Request — master (#6575)
by Luís
14:40
created

SimpleHydrationBench::init()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 19
nc 2
nop 0
1
<?php
2
3
namespace Doctrine\Performance\Hydration;
4
5
use Doctrine\Common\Persistence\ObjectRepository;
6
use Doctrine\ORM\EntityManagerInterface;
7
use Doctrine\Performance\EntityManagerFactory;
8
use Doctrine\Tests\Models\CMS;
9
10
/**
11
 * @BeforeMethods({"init"})
12
 */
13
final class SimpleHydrationBench
14
{
15
    /**
16
     * @var EntityManagerInterface
17
     */
18
    private $entityManager;
19
20
    /**
21
     * @var ObjectRepository
22
     */
23
    private $repository;
24
25
    public function init()
26
    {
27
        $this->entityManager = EntityManagerFactory::getEntityManager([
28
            CMS\CmsUser::class,
29
            CMS\CmsPhonenumber::class,
30
            CMS\CmsAddress::class,
31
            CMS\CmsEmail::class,
32
            CMS\CmsGroup::class,
33
            CMS\CmsTag::class,
34
            CMS\CmsArticle::class,
35
            CMS\CmsComment::class,
36
        ]);
37
38
        for ($i = 2; $i < 10000; ++$i) {
39
            $user = new CMS\CmsUser();
40
41
            $user->status   = 'developer';
42
            $user->username = 'jwage' . $i;
43
            $user->name     = 'Jonathan';
44
45
            $this->entityManager->persist($user);
46
        }
47
48
        $this->entityManager->flush();
49
        $this->entityManager->clear();
50
51
        $this->repository = $this->entityManager->getRepository(CMS\CmsUser::class);
52
    }
53
54
    public function benchHydration()
55
    {
56
        $this->repository->findAll();
57
    }
58
}
59