Skip to content

Commit f496c8d

Browse files
committed
Refactored FieldTypeSerializerTest
1 parent d33b7c5 commit f496c8d

File tree

2 files changed

+37
-105
lines changed

2 files changed

+37
-105
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7290,51 +7290,11 @@ parameters:
72907290
count: 1
72917291
path: tests/lib/Output/FieldTypeSerializerTest.php
72927292

7293-
-
7294-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:getFieldTypeSerializer\\(\\) has no return type specified\\.$#"
7295-
count: 1
7296-
path: tests/lib/Output/FieldTypeSerializerTest.php
7297-
72987293
-
72997294
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:getFieldTypeServiceMock\\(\\) has no return type specified\\.$#"
73007295
count: 1
73017296
path: tests/lib/Output/FieldTypeSerializerTest.php
73027297

7303-
-
7304-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:getGeneratorMock\\(\\) has no return type specified\\.$#"
7305-
count: 1
7306-
path: tests/lib/Output/FieldTypeSerializerTest.php
7307-
7308-
-
7309-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:testSerializeFieldDefaultValue\\(\\) has no return type specified\\.$#"
7310-
count: 1
7311-
path: tests/lib/Output/FieldTypeSerializerTest.php
7312-
7313-
-
7314-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:testSerializeFieldSettings\\(\\) has no return type specified\\.$#"
7315-
count: 1
7316-
path: tests/lib/Output/FieldTypeSerializerTest.php
7317-
7318-
-
7319-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:testSerializeFieldSettingsWithPostProcessing\\(\\) has no return type specified\\.$#"
7320-
count: 1
7321-
path: tests/lib/Output/FieldTypeSerializerTest.php
7322-
7323-
-
7324-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:testSerializeFieldValueWithProcessor\\(\\) has no return type specified\\.$#"
7325-
count: 1
7326-
path: tests/lib/Output/FieldTypeSerializerTest.php
7327-
7328-
-
7329-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:testSerializeValidatorConfiguration\\(\\) has no return type specified\\.$#"
7330-
count: 1
7331-
path: tests/lib/Output/FieldTypeSerializerTest.php
7332-
7333-
-
7334-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:testSerializeValidatorConfigurationWithPostProcessing\\(\\) has no return type specified\\.$#"
7335-
count: 1
7336-
path: tests/lib/Output/FieldTypeSerializerTest.php
7337-
73387298
-
73397299
message: "#^Property Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:\\$contentTypeMock has no type specified\\.$#"
73407300
count: 1

tests/lib/Output/FieldTypeSerializerTest.php

Lines changed: 37 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function provideDataWithFieldValueToSerialize(): iterable
106106
];
107107
}
108108

109-
public function testSerializeFieldValueWithProcessor()
109+
public function testSerializeFieldValueWithProcessor(): void
110110
{
111111
$serializer = $this->getFieldTypeSerializer();
112112

@@ -154,19 +154,15 @@ static function () use ($fieldTypeMock) {
154154
);
155155
}
156156

157-
public function testSerializeFieldDefaultValue()
157+
public function testSerializeFieldDefaultValue(): void
158158
{
159159
$serializer = $this->getFieldTypeSerializer();
160160

161161
$fieldTypeMock = $this->getFieldTypeMock();
162-
$this->getFieldTypeServiceMock()->expects($this->once())
163-
->method('getFieldType')
164-
->with($this->equalTo('myFancyFieldType'))
165-
->willReturnCallback(
166-
static function () use ($fieldTypeMock) {
167-
return $fieldTypeMock;
168-
}
169-
);
162+
$this->mockFieldTypeServiceGetFieldType(
163+
'myFancyFieldType',
164+
$fieldTypeMock
165+
);
170166

171167
$fieldTypeMock->expects($this->once())
172168
->method('toHash')
@@ -183,19 +179,15 @@ static function () use ($fieldTypeMock) {
183179
);
184180
}
185181

186-
public function testSerializeFieldSettings()
182+
public function testSerializeFieldSettings(): void
187183
{
188184
$serializer = $this->getFieldTypeSerializer();
189185

190186
$fieldTypeMock = $this->getFieldTypeMock();
191-
$this->getFieldTypeServiceMock()->expects($this->once())
192-
->method('getFieldType')
193-
->with($this->equalTo('myFancyFieldType'))
194-
->willReturnCallback(
195-
static function () use ($fieldTypeMock) {
196-
return $fieldTypeMock;
197-
}
198-
);
187+
$this->mockFieldTypeServiceGetFieldType(
188+
'myFancyFieldType',
189+
$fieldTypeMock
190+
);
199191

200192
$fieldTypeMock->expects($this->once())
201193
->method('fieldSettingsToHash')
@@ -212,7 +204,7 @@ static function () use ($fieldTypeMock) {
212204
);
213205
}
214206

215-
public function testSerializeFieldSettingsWithPostProcessing()
207+
public function testSerializeFieldSettingsWithPostProcessing(): void
216208
{
217209
$serializer = $this->getFieldTypeSerializer();
218210
$fieldTypeMock = $this->getFieldTypeMock();
@@ -237,14 +229,10 @@ static function () use ($processorMock) {
237229
->with($this->equalTo(['foo' => 'bar']))
238230
->willReturn(['post-processed']);
239231

240-
$this->getFieldTypeServiceMock()->expects($this->once())
241-
->method('getFieldType')
242-
->with($this->equalTo('myFancyFieldType'))
243-
->willReturnCallback(
244-
static function () use ($fieldTypeMock) {
245-
return $fieldTypeMock;
246-
}
247-
);
232+
$this->mockFieldTypeServiceGetFieldType(
233+
'myFancyFieldType',
234+
$fieldTypeMock
235+
);
248236

249237
$fieldTypeMock->expects($this->once())
250238
->method('fieldSettingsToHash')
@@ -261,19 +249,15 @@ static function () use ($fieldTypeMock) {
261249
);
262250
}
263251

264-
public function testSerializeValidatorConfiguration()
252+
public function testSerializeValidatorConfiguration(): void
265253
{
266254
$serializer = $this->getFieldTypeSerializer();
267255

268256
$fieldTypeMock = $this->getFieldTypeMock();
269-
$this->getFieldTypeServiceMock()->expects($this->once())
270-
->method('getFieldType')
271-
->with($this->equalTo('myFancyFieldType'))
272-
->willReturnCallback(
273-
static function () use ($fieldTypeMock) {
274-
return $fieldTypeMock;
275-
}
276-
);
257+
$this->mockFieldTypeServiceGetFieldType(
258+
'myFancyFieldType',
259+
$fieldTypeMock
260+
);
277261

278262
$fieldTypeMock->expects($this->once())
279263
->method('validatorConfigurationToHash')
@@ -290,7 +274,7 @@ static function () use ($fieldTypeMock) {
290274
);
291275
}
292276

293-
public function testSerializeValidatorConfigurationWithPostProcessing()
277+
public function testSerializeValidatorConfigurationWithPostProcessing(): void
294278
{
295279
$serializer = $this->getFieldTypeSerializer();
296280
$fieldTypeMock = $this->getFieldTypeMock();
@@ -316,23 +300,10 @@ static function () use ($processorMock) {
316300
->willReturn(['post-processed']);
317301

318302
$fieldTypeMock = $this->getFieldTypeMock();
319-
$this->getFieldTypeServiceMock()->expects($this->once())
320-
->method('getFieldType')
321-
->with($this->equalTo('myFancyFieldType'))
322-
->willReturnCallback(
323-
static function () use ($fieldTypeMock) {
324-
return $fieldTypeMock;
325-
}
326-
);
327-
328-
$this->getFieldTypeServiceMock()->expects($this->once())
329-
->method('getFieldType')
330-
->with($this->equalTo('myFancyFieldType'))
331-
->willReturnCallback(
332-
static function () use ($fieldTypeMock) {
333-
return $fieldTypeMock;
334-
}
335-
);
303+
$this->mockFieldTypeServiceGetFieldType(
304+
'myFancyFieldType',
305+
$fieldTypeMock
306+
);
336307

337308
$fieldTypeMock->expects($this->once())
338309
->method('validatorConfigurationToHash')
@@ -349,7 +320,7 @@ static function () use ($fieldTypeMock) {
349320
);
350321
}
351322

352-
protected function getFieldTypeSerializer()
323+
protected function getFieldTypeSerializer(): FieldTypeSerializer
353324
{
354325
return new FieldTypeSerializer(
355326
$this->getFieldTypeServiceMock(),
@@ -402,15 +373,6 @@ protected function getFieldTypeMock()
402373
return $this->fieldTypeMock;
403374
}
404375

405-
protected function getGeneratorMock()
406-
{
407-
if (!isset($this->generatorMock)) {
408-
$this->generatorMock = $this->createMock(Generator::class);
409-
}
410-
411-
return $this->generatorMock;
412-
}
413-
414376
/**
415377
* @param mixed $value
416378
*/
@@ -465,6 +427,16 @@ private function createFieldTypeMock(
465427

466428
return $fieldTypeMock;
467429
}
430+
431+
private function mockFieldTypeServiceGetFieldType(
432+
string $identifier,
433+
APIFieldType $fieldType
434+
): void {
435+
$this->getFieldTypeServiceMock()
436+
->method('getFieldType')
437+
->with($identifier)
438+
->willReturn($fieldType);
439+
}
468440
}
469441

470442
class_alias(FieldTypeSerializerTest::class, 'EzSystems\EzPlatformRest\Tests\Output\FieldTypeSerializerTest');

0 commit comments

Comments
 (0)