Skip to content

Commit 69acebf

Browse files
committed
fix: Reduce code duplication
1 parent 0f7966d commit 69acebf

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

tests/lib/Persistence/Legacy/Content/Mapper/ResolveVirtualFieldSubscriberTest.php

+25-23
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ public function testResolveVirtualField(): void
6161
$contentGateway->expects($this->never())
6262
->method('insertNewField');
6363

64-
$eventDispatcher = new TraceableEventDispatcher(
65-
new EventDispatcher(),
66-
new Stopwatch()
67-
);
68-
64+
$eventDispatcher = $this->getEventDispatcher();
6965
$eventDispatcher->addSubscriber(
7066
new ResolveVirtualFieldSubscriber(
7167
$converterRegistry,
@@ -123,6 +119,7 @@ public function testResolveVirtualExternalStorageField(): void
123119

124120
$storageRegistry = $this->createMock(StorageRegistry::class);
125121
$storageRegistry->method('getStorage')
122+
// Multiple interface mocks are deprecated in PHPUnit 9+
126123
->willReturn(new class() implements FieldStorage, DefaultDataFieldStorage {
127124
public function getDefaultFieldData(VersionInfo $versionInfo, Field $field): void
128125
{
@@ -133,42 +130,47 @@ public function getDefaultFieldData(VersionInfo $versionInfo, Field $field): voi
133130

134131
public function storeFieldData(VersionInfo $versionInfo, Field $field, array $context): void
135132
{
133+
// Mock
136134
}
137135

138136
public function getFieldData(VersionInfo $versionInfo, Field $field, array $context): void
139137
{
138+
// Mock
140139
}
141140

142141
public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds, array $context): void
143142
{
143+
// Mock
144144
}
145145

146146
public function hasFieldData(): void
147147
{
148+
// Mock
148149
}
149150

150151
public function getIndexData(VersionInfo $versionInfo, Field $field, array $context): void
151152
{
153+
// Mock
152154
}
153155
});
154156

155-
$eventDispatcher = new TraceableEventDispatcher(
156-
new EventDispatcher(),
157-
new Stopwatch()
158-
);
157+
$contentGateway = $this->createMock(ContentGateway::class);
158+
$contentGateway->expects($this->never())
159+
->method('insertNewField');
159160

161+
$eventDispatcher = $this->getEventDispatcher();
160162
$eventDispatcher->addSubscriber(
161163
new ResolveVirtualFieldSubscriber(
162164
$converterRegistry,
163165
$storageRegistry,
164-
$this->createMock(ContentGateway::class)
166+
$contentGateway
165167
)
166168
);
167169

168170
$content = $this->getContent();
169171
$fieldDefinition = new FieldDefinition([
170-
'id' => 123,
171-
'identifier' => 'example_field',
172+
'id' => 678,
173+
'identifier' => 'example_external_field',
172174
'fieldType' => 'external_type_virtual',
173175
'defaultValue' => new Content\FieldValue(),
174176
]);
@@ -183,7 +185,7 @@ public function getIndexData(VersionInfo $versionInfo, Field $field, array $cont
183185

184186
$expected = new Content\Field([
185187
'id' => null,
186-
'fieldDefinitionId' => 123,
188+
'fieldDefinitionId' => 678,
187189
'type' => 'external_type_virtual',
188190
'value' => new Content\FieldValue([
189191
'externalData' => [
@@ -233,11 +235,7 @@ public function testPersistEmptyExternalStorageField(): void
233235
->method('insertNewField')
234236
->willReturn(567);
235237

236-
$eventDispatcher = new TraceableEventDispatcher(
237-
new EventDispatcher(),
238-
new Stopwatch()
239-
);
240-
238+
$eventDispatcher = $this->getEventDispatcher();
241239
$eventDispatcher->addSubscriber(
242240
new ResolveVirtualFieldSubscriber(
243241
$converterRegistry,
@@ -316,11 +314,7 @@ public function testPersistExternalStorageField(): void
316314
->method('insertNewField')
317315
->willReturn(456);
318316

319-
$eventDispatcher = new TraceableEventDispatcher(
320-
new EventDispatcher(),
321-
new Stopwatch()
322-
);
323-
317+
$eventDispatcher = $this->getEventDispatcher();
324318
$eventDispatcher->addSubscriber(
325319
new ResolveVirtualFieldSubscriber(
326320
$converterRegistry,
@@ -378,4 +372,12 @@ public function testPersistExternalStorageField(): void
378372
array_column($eventDispatcher->getCalledListeners(), 'pretty')
379373
);
380374
}
375+
376+
private function getEventDispatcher(): TraceableEventDispatcher
377+
{
378+
return new TraceableEventDispatcher(
379+
new EventDispatcher(),
380+
new Stopwatch()
381+
);
382+
}
381383
}

0 commit comments

Comments
 (0)