1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Psi\Component\ContentType\Benchmark; |
4
|
|
|
|
5
|
|
|
use Psi\Component\ContentType\Tests\Functional\Example\Model\Article; |
6
|
|
|
use Psi\Component\ContentType\Tests\Functional\Example\Model\Image; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @BeforeMethods({"setUp"}) |
10
|
|
|
* @Revs(1) |
11
|
|
|
* @Iterations(10) |
12
|
|
|
* @OutputTimeUnit("milliseconds", precision=2) |
13
|
|
|
*/ |
14
|
|
|
trait DoctrineBenchTrait |
15
|
|
|
{ |
16
|
|
|
protected $objectManager; |
17
|
|
|
|
18
|
|
|
public function getBenchContainer() |
19
|
|
|
{ |
20
|
|
|
$container = $this->getContainer([ |
|
|
|
|
21
|
|
|
'mapping' => [ |
22
|
|
|
Article::class => [ |
23
|
|
|
'properties' => [ |
24
|
|
|
'title' => [ |
25
|
|
|
'type' => 'text', |
26
|
|
|
'role' => 'title', |
27
|
|
|
], |
28
|
|
|
'image' => [ |
29
|
|
|
'type' => 'image', |
30
|
|
|
'role' => 'image', |
31
|
|
|
], |
32
|
|
|
'slideshow' => [ |
33
|
|
|
'type' => 'collection', |
34
|
|
|
'options' => [ |
35
|
|
|
'field_type' => 'image', |
36
|
|
|
], |
37
|
|
|
], |
38
|
|
|
'date' => [ |
39
|
|
|
'type' => 'datetime', |
40
|
|
|
], |
41
|
|
|
'referencedImage' => [ |
42
|
|
|
'type' => 'object_reference', |
43
|
|
|
], |
44
|
|
|
'paragraphs' => [ |
45
|
|
|
'type' => 'collection', |
46
|
|
|
'options' => [ |
47
|
|
|
'field_type' => 'text', |
48
|
|
|
'field_options' => [], |
49
|
|
|
], |
50
|
|
|
], |
51
|
|
|
'numbers' => [ |
52
|
|
|
'type' => 'collection', |
53
|
|
|
'options' => [ |
54
|
|
|
'field_type' => 'integer', |
55
|
|
|
], |
56
|
|
|
], |
57
|
|
|
], |
58
|
|
|
], |
59
|
|
|
], |
60
|
|
|
]); |
61
|
|
|
|
62
|
|
|
return $container; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @Subject() |
67
|
|
|
*/ |
68
|
|
|
public function image_phpcr_odm_only() |
69
|
|
|
{ |
70
|
|
|
static $id; |
71
|
|
|
$image = new Image( |
72
|
|
|
'/path/to/image', 100, 200, 'image/jpeg' |
73
|
|
|
); |
74
|
|
|
$image->id = '/test/image' . $id++; |
75
|
|
|
|
76
|
|
|
$this->objectManager->persist($image); |
77
|
|
|
$this->objectManager->flush(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @Subject() |
82
|
|
|
*/ |
83
|
|
|
public function ct_article() |
84
|
|
|
{ |
85
|
|
|
static $id; |
86
|
|
|
$article = new Article(); |
87
|
|
|
$article->id = '/test/article' . $id++; |
88
|
|
|
$article->title = 'Hello'; |
89
|
|
|
$article->date = new \DateTime('2016-01-01 00:00:00'); |
90
|
|
|
|
91
|
|
|
$this->objectManager->persist($article); |
92
|
|
|
$this->objectManager->flush(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @Subject() |
97
|
|
|
*/ |
98
|
|
|
public function ct_article_with_image() |
99
|
|
|
{ |
100
|
|
|
static $id; |
101
|
|
|
$article = new Article(); |
102
|
|
|
$article->id = '/test/article' . $id++; |
103
|
|
|
$article->title = 'Hello'; |
104
|
|
|
$article->date = new \DateTime('2016-01-01 00:00:00'); |
105
|
|
|
|
106
|
|
|
$article->image = new Image( |
107
|
|
|
'/path/to/image', 100, 200, 'image/jpeg' |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
$this->objectManager->persist($article); |
111
|
|
|
$this->objectManager->flush(); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.