Skip to content

Commit

Permalink
Fixed return types in ImageIntegrationTest
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Dec 5, 2023
1 parent 29a2224 commit c44b948
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 86 deletions.
40 changes: 0 additions & 40 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -30600,21 +30600,6 @@ parameters:
count: 1
path: tests/integration/Core/Repository/FieldType/ImageIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\ImageIntegrationTest\\:\\:assertCopiedFieldDataLoadedCorrectly\\(\\) has no return type specified\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/ImageIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\ImageIntegrationTest\\:\\:assertUpdatedFieldDataLoadedCorrect\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/ImageIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\ImageIntegrationTest\\:\\:assertUpdatedFieldDataLoadedCorrect\\(\\) should return array but return statement is missing\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/ImageIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\ImageIntegrationTest\\:\\:getAdditionallyIndexedFieldData\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -30630,11 +30615,6 @@ parameters:
count: 1
path: tests/integration/Core/Repository/FieldType/ImageIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\ImageIntegrationTest\\:\\:getValidatorSchema\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/ImageIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\ImageIntegrationTest\\:\\:provideFromHashData\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -30655,31 +30635,11 @@ parameters:
count: 1
path: tests/integration/Core/Repository/FieldType/ImageIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\ImageIntegrationTest\\:\\:providerForTestIsEmptyValue\\(\\) has no return type specified\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/ImageIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\ImageIntegrationTest\\:\\:providerForTestIsNotEmptyValue\\(\\) has no return type specified\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/ImageIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\ImageIntegrationTest\\:\\:publishNewImage\\(\\) has parameter \\$parentLocationIDs with no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/ImageIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\ImageIntegrationTest\\:\\:testInherentCopyForNewLanguage\\(\\) has no return type specified\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/ImageIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\ImageIntegrationTest\\:\\:testUpdatingImageMetadataOnlyWorks\\(\\) has no return type specified\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/ImageIntegrationTest.php

-
message: "#^Property Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\ImageIntegrationTest\\:\\:\\$loadedImagePath has no type specified\\.$#"
count: 1
Expand Down
127 changes: 81 additions & 46 deletions tests/integration/Core/Repository/FieldType/ImageIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Ibexa\Contracts\Core\Repository\Values\Content\Field;
use Ibexa\Contracts\Core\Test\Repository\SetupFactory\Legacy;
use Ibexa\Core\FieldType\Image\Value as ImageValue;
use stdClass;

/**
* Integration test for use field type.
Expand Down Expand Up @@ -42,7 +43,7 @@ protected function getStoragePrefix()
*
* @return array
*/
protected function getFixtureData()
protected function getFixtureData(): array
{
return [
'create' => [
Expand All @@ -65,7 +66,7 @@ protected function getFixtureData()
*
* @return string
*/
public function getTypeName()
public function getTypeName(): string
{
return 'ezimage';
}
Expand All @@ -91,9 +92,11 @@ public function getSettingsSchema(): array
/**
* Get a valid $fieldSettings value.
*
* @return mixed
* @return array{
* mimeTypes: array<string>,
* }
*/
public function getValidFieldSettings()
public function getValidFieldSettings(): array
{
return [
'mimeTypes' => [
Expand All @@ -106,9 +109,11 @@ public function getValidFieldSettings()
/**
* Get $fieldSettings value not accepted by the field type.
*
* @return mixed
* @return array{
* somethingUnknown: int,
* }
*/
public function getInvalidFieldSettings()
public function getInvalidFieldSettings(): array
{
return [
'somethingUnknown' => 0,
Expand All @@ -118,9 +123,22 @@ public function getInvalidFieldSettings()
/**
* Get expected validator schema.
*
* @return array
* @return array{
* FileSizeValidator: array{
* maxFileSize: array{
* type: string,
* default: null,
* }
* },
* AlternativeTextValidator: array{
* required: array{
* type: string,
* default: bool,
* }
* },
* }
*/
public function getValidatorSchema()
public function getValidatorSchema(): array
{
return [
'FileSizeValidator' => [
Expand All @@ -141,9 +159,16 @@ public function getValidatorSchema()
/**
* Get a valid $validatorConfiguration.
*
* @return mixed
* @return array{
* FileSizeValidator: array{
* maxFileSize: numeric,
* },
* AlternativeTextValidator: array{
* required: bool,
* },
* }
*/
public function getValidValidatorConfiguration()
public function getValidValidatorConfiguration(): array
{
return [
'FileSizeValidator' => [
Expand All @@ -158,23 +183,25 @@ public function getValidValidatorConfiguration()
/**
* Get $validatorConfiguration not accepted by the field type.
*
* @return mixed
* @return array{
* StringLengthValidator: array{
* minStringLength: \stdClass,
* },
* }
*/
public function getInvalidValidatorConfiguration()
public function getInvalidValidatorConfiguration(): array
{
return [
'StringLengthValidator' => [
'minStringLength' => new \stdClass(),
'minStringLength' => new stdClass(),
],
];
}

/**
* Get initial field data for valid object creation.
*
* @return mixed
*/
public function getValidCreationFieldData()
public function getValidCreationFieldData(): ImageValue
{
$fixtureData = $this->getFixtureData();

Expand All @@ -186,7 +213,7 @@ public function getValidCreationFieldData()
*
* @return string
*/
public function getFieldName()
public function getFieldName(): string
{
return 'My icy flower at night';
}
Expand Down Expand Up @@ -226,7 +253,7 @@ public function assertFieldDataLoadedCorrect(Field $field): void
self::$loadedImagePath = $field->value->id;
}

public function provideInvalidCreationFieldData()
public function provideInvalidCreationFieldData(): array
{
return [
// will fail because the provided file doesn't exist, and fileSize/fileName won't be set
Expand All @@ -243,24 +270,15 @@ public function provideInvalidCreationFieldData()

/**
* Get update field externals data.
*
* @return \Ibexa\Core\FieldType\Image\Value
*/
public function getValidUpdateFieldData()
public function getValidUpdateFieldData(): ImageValue
{
$fixtureData = $this->getFixtureData();

return new ImageValue($fixtureData['update']);
}

/**
* Get externals updated field data values.
*
* This is a PHPUnit data provider
*
* @return array
*/
public function assertUpdatedFieldDataLoadedCorrect(Field $field)
public function assertUpdatedFieldDataLoadedCorrect(Field $field): void
{
self::assertInstanceOf(
ImageValue::class,
Expand Down Expand Up @@ -289,7 +307,7 @@ public function assertUpdatedFieldDataLoadedCorrect(Field $field)
);
}

public function provideInvalidUpdateFieldData()
public function provideInvalidUpdateFieldData(): array
{
return $this->provideInvalidCreationFieldData();
}
Expand All @@ -299,10 +317,8 @@ public function provideInvalidUpdateFieldData()
*
* Asserts that the data provided by {@link getValidCreationFieldData()}
* was copied and loaded correctly.
*
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Field $field
*/
public function assertCopiedFieldDataLoadedCorrectly(Field $field)
public function assertCopiedFieldDataLoadedCorrectly(Field $field): void
{
$this->assertFieldDataLoadedCorrect($field);

Expand Down Expand Up @@ -332,7 +348,7 @@ public function assertCopiedFieldDataLoadedCorrectly(Field $field)
*
* @return array
*/
public function provideToHashData()
public function provideToHashData(): array
{
return [
[
Expand Down Expand Up @@ -397,7 +413,7 @@ public function provideToHashData()
*
* @return array
*/
public function provideFromHashData()
public function provideFromHashData(): array
{
$fixture = $this->getFixtureData();

Expand All @@ -409,7 +425,7 @@ public function provideFromHashData()
];
}

public function testInherentCopyForNewLanguage()
public function testInherentCopyForNewLanguage(): void
{
$repository = $this->getRepository();
$contentService = $repository->getContentService();
Expand Down Expand Up @@ -459,14 +475,24 @@ public function testInherentCopyForNewLanguage()
}
}

public function providerForTestIsEmptyValue()
/**
* @return array<array{
* \Ibexa\Core\FieldType\Image\Value
* }>
*/
public function providerForTestIsEmptyValue(): array
{
return [
[new ImageValue()],
];
}

public function providerForTestIsNotEmptyValue()
/**
* @return array<array{
* \Ibexa\Core\FieldType\Image\Value
* }>
*/
public function providerForTestIsNotEmptyValue(): array
{
return [
[
Expand All @@ -478,7 +504,7 @@ public function providerForTestIsNotEmptyValue()
/**
* Covers EZP-23080.
*/
public function testUpdatingImageMetadataOnlyWorks()
public function testUpdatingImageMetadataOnlyWorks(): void
{
$repository = $this->getRepository();
$contentService = $repository->getContentService();
Expand Down Expand Up @@ -599,7 +625,7 @@ protected function checkSearchEngineSupport(): void
}
}

protected function getValidSearchValueOne()
protected function getValidSearchValueOne(): ImageValue
{
return new ImageValue(
[
Expand All @@ -611,7 +637,7 @@ protected function getValidSearchValueOne()
);
}

protected function getValidSearchValueTwo()
protected function getValidSearchValueTwo(): ImageValue
{
return new ImageValue(
[
Expand All @@ -623,22 +649,31 @@ protected function getValidSearchValueTwo()
);
}

protected function getSearchTargetValueOne()
protected function getSearchTargetValueOne(): string
{
$value = $this->getValidSearchValueOne();

// ensure case-insensitivity
/**
* ensure case-insensitivity.
*
* @phpstan-ignore-next-line
*/
return strtoupper($value->fileName);
}

protected function getSearchTargetValueTwo()
protected function getSearchTargetValueTwo(): string
{
$value = $this->getValidSearchValueTwo();
// ensure case-insensitivity

/**
* ensure case-insensitivity.
*
* @phpstan-ignore-next-line
*/
return strtoupper($value->fileName);
}

protected function getAdditionallyIndexedFieldData()
protected function getAdditionallyIndexedFieldData(): array
{
return [
[
Expand Down

0 comments on commit c44b948

Please sign in to comment.