1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Psi\Component\ContentType\Benchmark; |
4
|
|
|
|
5
|
|
|
use Psi\Bridge\ContentType\Doctrine\Orm\Tests\Functional\OrmTestCase; |
6
|
|
|
use Psi\Component\ContentType\Tests\Functional\Example\Model\Article; |
7
|
|
|
use Psi\Component\ContentType\Tests\Functional\Example\Model\Image; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @BeforeMethods({"setUp"}) |
11
|
|
|
* @Revs(1) |
12
|
|
|
* @Iterations(10) |
13
|
|
|
* @OutputTimeUnit("milliseconds", precision=2) |
14
|
|
|
*/ |
15
|
|
View Code Duplication |
class DoctrineOrmBench extends OrmTestCase |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
private $entityManager; |
18
|
|
|
|
19
|
|
|
public function setUp() |
20
|
|
|
{ |
21
|
|
|
$container = $this->getContainer([ |
22
|
|
|
'mapping' => [ |
23
|
|
|
Article::class => [ |
24
|
|
|
'properties' => [ |
25
|
|
|
'title' => [ |
26
|
|
|
'type' => 'text', |
27
|
|
|
'role' => 'title', |
28
|
|
|
], |
29
|
|
|
'image' => [ |
30
|
|
|
'type' => 'image', |
31
|
|
|
'role' => 'image', |
32
|
|
|
], |
33
|
|
|
'slideshow' => [ |
34
|
|
|
'type' => 'collection', |
35
|
|
|
'options' => [ |
36
|
|
|
'field_type' => 'image', |
37
|
|
|
], |
38
|
|
|
], |
39
|
|
|
'date' => [ |
40
|
|
|
'type' => 'datetime', |
41
|
|
|
], |
42
|
|
|
'referencedImage' => [ |
43
|
|
|
'type' => 'object_reference', |
44
|
|
|
], |
45
|
|
|
'paragraphs' => [ |
46
|
|
|
'type' => 'collection', |
47
|
|
|
'options' => [ |
48
|
|
|
'field_type' => 'text', |
49
|
|
|
'field_options' => [], |
50
|
|
|
], |
51
|
|
|
], |
52
|
|
|
'numbers' => [ |
53
|
|
|
'type' => 'collection', |
54
|
|
|
'options' => [ |
55
|
|
|
'field_type' => 'integer', |
56
|
|
|
], |
57
|
|
|
], |
58
|
|
|
], |
59
|
|
|
], |
60
|
|
|
], |
61
|
|
|
]); |
62
|
|
|
$this->entityManager = $container->get('doctrine.entity_manager'); |
63
|
|
|
$this->initOrm($this->entityManager); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @Subject() |
68
|
|
|
*/ |
69
|
|
|
public function image_phpcr_odm_only() |
70
|
|
|
{ |
71
|
|
|
static $id; |
72
|
|
|
$image = new Image( |
73
|
|
|
'/path/to/image', 100, 200, 'image/jpeg' |
74
|
|
|
); |
75
|
|
|
$image->id = '/test/image' . $id++; |
76
|
|
|
|
77
|
|
|
$this->entityManager->persist($image); |
78
|
|
|
$this->entityManager->flush(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @Subject() |
83
|
|
|
*/ |
84
|
|
|
public function ct_article() |
85
|
|
|
{ |
86
|
|
|
static $id; |
87
|
|
|
$article = new Article(); |
88
|
|
|
$article->id = '/test/article' . $id++; |
89
|
|
|
$article->title = 'Hello'; |
90
|
|
|
$article->date = new \DateTime('2016-01-01 00:00:00'); |
91
|
|
|
|
92
|
|
|
$this->entityManager->persist($article); |
93
|
|
|
$this->entityManager->flush(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @Subject() |
98
|
|
|
*/ |
99
|
|
|
public function ct_article_with_image() |
100
|
|
|
{ |
101
|
|
|
static $id; |
102
|
|
|
$article = new Article(); |
103
|
|
|
$article->id = '/test/article' . $id++; |
104
|
|
|
$article->title = 'Hello'; |
105
|
|
|
$article->date = new \DateTime('2016-01-01 00:00:00'); |
106
|
|
|
|
107
|
|
|
$article->image = new Image( |
108
|
|
|
'/path/to/image', 100, 200, 'image/jpeg' |
109
|
|
|
); |
110
|
|
|
|
111
|
|
|
$this->entityManager->persist($article); |
112
|
|
|
$this->entityManager->flush(); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.