Skip to content

Commit

Permalink
Refactored FieldTypeSerializerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Dec 7, 2023
1 parent d33b7c5 commit f496c8d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 105 deletions.
40 changes: 0 additions & 40 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7290,51 +7290,11 @@ parameters:
count: 1
path: tests/lib/Output/FieldTypeSerializerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:getFieldTypeSerializer\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/FieldTypeSerializerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:getFieldTypeServiceMock\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/FieldTypeSerializerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:getGeneratorMock\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/FieldTypeSerializerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:testSerializeFieldDefaultValue\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/FieldTypeSerializerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:testSerializeFieldSettings\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/FieldTypeSerializerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:testSerializeFieldSettingsWithPostProcessing\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/FieldTypeSerializerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:testSerializeFieldValueWithProcessor\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/FieldTypeSerializerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:testSerializeValidatorConfiguration\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/FieldTypeSerializerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:testSerializeValidatorConfigurationWithPostProcessing\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/FieldTypeSerializerTest.php

-
message: "#^Property Ibexa\\\\Tests\\\\Rest\\\\Output\\\\FieldTypeSerializerTest\\:\\:\\$contentTypeMock has no type specified\\.$#"
count: 1
Expand Down
102 changes: 37 additions & 65 deletions tests/lib/Output/FieldTypeSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function provideDataWithFieldValueToSerialize(): iterable
];
}

public function testSerializeFieldValueWithProcessor()
public function testSerializeFieldValueWithProcessor(): void
{
$serializer = $this->getFieldTypeSerializer();

Expand Down Expand Up @@ -154,19 +154,15 @@ static function () use ($fieldTypeMock) {
);
}

public function testSerializeFieldDefaultValue()
public function testSerializeFieldDefaultValue(): void
{
$serializer = $this->getFieldTypeSerializer();

$fieldTypeMock = $this->getFieldTypeMock();
$this->getFieldTypeServiceMock()->expects($this->once())
->method('getFieldType')
->with($this->equalTo('myFancyFieldType'))
->willReturnCallback(
static function () use ($fieldTypeMock) {
return $fieldTypeMock;
}
);
$this->mockFieldTypeServiceGetFieldType(
'myFancyFieldType',
$fieldTypeMock
);

$fieldTypeMock->expects($this->once())
->method('toHash')
Expand All @@ -183,19 +179,15 @@ static function () use ($fieldTypeMock) {
);
}

public function testSerializeFieldSettings()
public function testSerializeFieldSettings(): void
{
$serializer = $this->getFieldTypeSerializer();

$fieldTypeMock = $this->getFieldTypeMock();
$this->getFieldTypeServiceMock()->expects($this->once())
->method('getFieldType')
->with($this->equalTo('myFancyFieldType'))
->willReturnCallback(
static function () use ($fieldTypeMock) {
return $fieldTypeMock;
}
);
$this->mockFieldTypeServiceGetFieldType(
'myFancyFieldType',
$fieldTypeMock
);

$fieldTypeMock->expects($this->once())
->method('fieldSettingsToHash')
Expand All @@ -212,7 +204,7 @@ static function () use ($fieldTypeMock) {
);
}

public function testSerializeFieldSettingsWithPostProcessing()
public function testSerializeFieldSettingsWithPostProcessing(): void
{
$serializer = $this->getFieldTypeSerializer();
$fieldTypeMock = $this->getFieldTypeMock();
Expand All @@ -237,14 +229,10 @@ static function () use ($processorMock) {
->with($this->equalTo(['foo' => 'bar']))
->willReturn(['post-processed']);

$this->getFieldTypeServiceMock()->expects($this->once())
->method('getFieldType')
->with($this->equalTo('myFancyFieldType'))
->willReturnCallback(
static function () use ($fieldTypeMock) {
return $fieldTypeMock;
}
);
$this->mockFieldTypeServiceGetFieldType(
'myFancyFieldType',
$fieldTypeMock
);

$fieldTypeMock->expects($this->once())
->method('fieldSettingsToHash')
Expand All @@ -261,19 +249,15 @@ static function () use ($fieldTypeMock) {
);
}

public function testSerializeValidatorConfiguration()
public function testSerializeValidatorConfiguration(): void
{
$serializer = $this->getFieldTypeSerializer();

$fieldTypeMock = $this->getFieldTypeMock();
$this->getFieldTypeServiceMock()->expects($this->once())
->method('getFieldType')
->with($this->equalTo('myFancyFieldType'))
->willReturnCallback(
static function () use ($fieldTypeMock) {
return $fieldTypeMock;
}
);
$this->mockFieldTypeServiceGetFieldType(
'myFancyFieldType',
$fieldTypeMock
);

$fieldTypeMock->expects($this->once())
->method('validatorConfigurationToHash')
Expand All @@ -290,7 +274,7 @@ static function () use ($fieldTypeMock) {
);
}

public function testSerializeValidatorConfigurationWithPostProcessing()
public function testSerializeValidatorConfigurationWithPostProcessing(): void
{
$serializer = $this->getFieldTypeSerializer();
$fieldTypeMock = $this->getFieldTypeMock();
Expand All @@ -316,23 +300,10 @@ static function () use ($processorMock) {
->willReturn(['post-processed']);

$fieldTypeMock = $this->getFieldTypeMock();
$this->getFieldTypeServiceMock()->expects($this->once())
->method('getFieldType')
->with($this->equalTo('myFancyFieldType'))
->willReturnCallback(
static function () use ($fieldTypeMock) {
return $fieldTypeMock;
}
);

$this->getFieldTypeServiceMock()->expects($this->once())
->method('getFieldType')
->with($this->equalTo('myFancyFieldType'))
->willReturnCallback(
static function () use ($fieldTypeMock) {
return $fieldTypeMock;
}
);
$this->mockFieldTypeServiceGetFieldType(
'myFancyFieldType',
$fieldTypeMock
);

$fieldTypeMock->expects($this->once())
->method('validatorConfigurationToHash')
Expand All @@ -349,7 +320,7 @@ static function () use ($fieldTypeMock) {
);
}

protected function getFieldTypeSerializer()
protected function getFieldTypeSerializer(): FieldTypeSerializer
{
return new FieldTypeSerializer(
$this->getFieldTypeServiceMock(),
Expand Down Expand Up @@ -402,15 +373,6 @@ protected function getFieldTypeMock()
return $this->fieldTypeMock;
}

protected function getGeneratorMock()
{
if (!isset($this->generatorMock)) {
$this->generatorMock = $this->createMock(Generator::class);
}

return $this->generatorMock;
}

/**
* @param mixed $value
*/
Expand Down Expand Up @@ -465,6 +427,16 @@ private function createFieldTypeMock(

return $fieldTypeMock;
}

private function mockFieldTypeServiceGetFieldType(
string $identifier,
APIFieldType $fieldType
): void {
$this->getFieldTypeServiceMock()
->method('getFieldType')
->with($identifier)
->willReturn($fieldType);
}
}

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

0 comments on commit f496c8d

Please sign in to comment.