Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-31542: Added PHP 7.4 support (eZ Platform 2.5) #3017

Merged
merged 17 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
1220729
Fixed "Invalid characters passed for attempted conversion, these have…
adamwojs Apr 4, 2020
f7a373c
Fixed "Notice: Trying to access array offset on value of type null" i…
adamwojs Apr 4, 2020
54be1ff
Fixed "Notice: Trying to access array offset on value of type null" …
adamwojs Apr 4, 2020
342f7f0
Fixed "Notice: Trying to access array offset on value of type null" i…
adamwojs Apr 9, 2020
f89bcef
Fixed "Notice: Trying to access array offset on value of type null" i…
adamwojs Apr 5, 2020
6296000
Fixed "Notice: Trying to access array offset on value of type null" i…
adamwojs Apr 5, 2020
3f78b24
Fixed "Notice: Trying to access array offset on value of type null" i…
adamwojs Apr 5, 2020
6f8943e
fixup! Fixed "Notice: Trying to access array offset on value of type …
adamwojs Apr 5, 2020
e7eeb1a
Fixed \eZ\Publish\API\Repository\Tests\UserPreferenceServiceTest::tes…
adamwojs Apr 5, 2020
a4b0f72
CS
adamwojs Apr 5, 2020
9893810
Fixed "Expectation failed for method name is "getCurrentUserReference…
adamwojs Apr 5, 2020
d70e4f4
Fixed "Notice: Trying to access array offset on value of type null" i…
adamwojs Apr 5, 2020
d40a17b
Fixed "Notice: Trying to access array offset on value of type null" i…
adamwojs Apr 5, 2020
e324fa7
Fixed "Notice: Trying to access array offset on value of type null" i…
adamwojs Apr 9, 2020
d359d4f
Enable testing on PHP 7.4 in .travis.yml
adamwojs Apr 9, 2020
1df7c6a
Update eZ/Publish/Core/Persistence/TransformationProcessor/PcreCompil…
adamwojs Apr 16, 2020
e545fda
Reduced number of Travis jobs
adamwojs Apr 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ matrix:
- name: 'Code Style Check'
php: 7.3
env: CHECK_CS=1
# 7.4
- php: 7.4
env: TEST_CONFIG="phpunit.xml"
- php: 7.4
env: PHP_IMAGE=ezsystems/php:7.4-v1 PHP_IMAGE_DEV=ezsystems/php:7.4-v1-dev REST_TEST_CONFIG="phpunit-functional-rest.xml" SYMFONY_ENV=behat SYMFONY_DEBUG=1 SF_CMD="ez:behat:create-language 'pol-PL' 'Polish (polski)'"
- php: 7.4
env: PHP_IMAGE=ezsystems/php:7.4-v1 PHP_IMAGE_DEV=ezsystems/php:7.4-v1-dev BEHAT_OPTS="--profile=rest --tags=~@broken --suite=fullJson" SYMFONY_ENV=behat SYMFONY_DEBUG=1
- php: 7.4
env: SOLR_VERSION="6.4.2" TEST_CONFIG="phpunit-integration-legacy-solr.xml" CUSTOM_CACHE_POOL="singleredis" CORES_SETUP="shared" SOLR_CONFIG="vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/schema.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/custom-fields-types.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/language-fieldtypes.xml" JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/"
- php: 7.4
env: TEST_CONFIG="phpunit-integration-legacy.xml" DB="postgresql" DATABASE="pgsql://postgres@localhost/testdb"
- php: 7.4
env: TEST_CONFIG="phpunit-integration-legacy.xml" DB="mysql" DATABASE="mysql://root@localhost/testdb"

Copy link
Contributor

@andrerom andrerom Apr 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets reduce number of tests here, it will take a long time to wait for them all to pass. We don't necerly need to test everything (3 flavours of integration test runs) on 7.4 once we have now gotten past to make sure all tests pass.

Suggested change
# 7.4
- php: 7.4
env: TEST_CONFIG="phpunit.xml"
- php: 7.4
env: PHP_IMAGE=ezsystems/php:7.4-v1 PHP_IMAGE_DEV=ezsystems/php:7.4-v1-dev REST_TEST_CONFIG="phpunit-functional-rest.xml" SYMFONY_ENV=behat SYMFONY_DEBUG=1 SF_CMD="ez:behat:create-language 'pol-PL' 'Polish (polski)'"
- php: 7.4
env: PHP_IMAGE=ezsystems/php:7.4-v1 PHP_IMAGE_DEV=ezsystems/php:7.4-v1-dev BEHAT_OPTS="--profile=rest --tags=~@broken --suite=fullJson" SYMFONY_ENV=behat SYMFONY_DEBUG=1
- php: 7.4
env: SOLR_VERSION="6.4.2" TEST_CONFIG="phpunit-integration-legacy-solr.xml" CUSTOM_CACHE_POOL="singleredis" CORES_SETUP="shared" SOLR_CONFIG="vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/schema.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/custom-fields-types.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/language-fieldtypes.xml" JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/"
- php: 7.4
env: TEST_CONFIG="phpunit-integration-legacy.xml" DB="postgresql" DATABASE="pgsql://postgres@localhost/testdb"
- php: 7.4
env: TEST_CONFIG="phpunit-integration-legacy.xml" DB="mysql" DATABASE="mysql://root@localhost/testdb"
# 7.4
- php: 7.4
env: TEST_CONFIG="phpunit.xml"
- php: 7.4
env: PHP_IMAGE=ezsystems/php:7.4-v1 PHP_IMAGE_DEV=ezsystems/php:7.4-v1-dev REST_TEST_CONFIG="phpunit-functional-rest.xml" SYMFONY_ENV=behat SYMFONY_DEBUG=1 SF_CMD="ez:behat:create-language 'pol-PL' 'Polish (polski)'"
- php: 7.4
env: PHP_IMAGE=ezsystems/php:7.4-v1 PHP_IMAGE_DEV=ezsystems/php:7.4-v1-dev BEHAT_OPTS="--profile=rest --tags=~@broken --suite=fullJson" SYMFONY_ENV=behat SYMFONY_DEBUG=1
- php: 7.4
env: SOLR_VERSION="7.7.2" TEST_CONFIG="phpunit-integration-legacy-solr.xml" CORES_SETUP="shared" SOLR_CONFIG="vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/schema.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/custom-fields-types.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/language-fieldtypes.xml" JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/"
- php: 7.4
env: TEST_CONFIG="phpunit-integration-legacy.xml" DB="mysql" DATABASE="mysql://root@localhost/testdb" CUSTOM_CACHE_POOL="singleredis"

Note! I'm suggesting we test Solr 7 here on PHP 7.4. probably need adaptions in integration test script to pull in solr bundle 2.x when solr 7 is asked for.

 # 7.1
     - php: 7.1
       env: TEST_CONFIG="phpunit.xml"
     - php: 7.1
       env: PHP_IMAGE=ezsystems/php:7.1-v1 PHP_IMAGE_DEV=ezsystems/php:7.1-v1-dev REST_TEST_CONFIG="phpunit-functional-rest.xml" SYMFONY_ENV=behat SYMFONY_DEBUG=1 SF_CMD="ez:behat:create-language 'pol-PL' 'Polish (polski)'"
     - php: 7.1
       env: PHP_IMAGE=ezsystems/php:7.1-v1 PHP_IMAGE_DEV=ezsystems/php:7.1-v1-dev BEHAT_OPTS="--profile=rest --tags=~@broken --suite=fullJson" SYMFONY_ENV=behat SYMFONY_DEBUG=1
     - php: 7.1
-       env: SOLR_VERSION="6.4.2" TEST_CONFIG="phpunit-integration-legacy-solr.xml" CUSTOM_CACHE_POOL="singleredis" CORES_SETUP="shared" SOLR_CONFIG="vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/schema.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/custom-fields-types.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/language-fieldtypes.xml" JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/"
+       env: SOLR_VERSION="6.6.5" TEST_CONFIG="phpunit-integration-legacy-solr.xml" CUSTOM_CACHE_POOL="singleredis" CORES_SETUP="shared" SOLR_CONFIG="vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/schema.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/custom-fields-types.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/language-fieldtypes.xml" JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/"
     - php: 7.1
       env: TEST_CONFIG="phpunit-integration-legacy.xml" DB="postgresql" DATABASE="pgsql://postgres@localhost/testdb"
-     - php: 7.1
-       env: TEST_CONFIG="phpunit-integration-legacy.xml" DB="mysql" DATABASE="mysql://root@localhost/testdb"

Could also consider to split the functional testing across 7.1 and 7.4 as opposed to run both on both php versions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, number of jobs will be reduced before merge. Right now I needed them to make sure that everything works 😉


# test only master, stable branches and pull requests
branches:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ protected function setUp()

protected function getAssetFactory()
{
$parameterBag = $this->createMock(ParameterBagInterface::class);
$parameterBag->method('resolveValue')->willReturnArgument(0);

$assetFactory = new AssetFactory(
$this->createMock(KernelInterface::class),
$this->createMock(ContainerInterface::class),
$this->createMock(ParameterBagInterface::class),
$parameterBag,
'/root/dir/'
);
$assetFactory->setConfigResolver($this->configResolver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ public function sortProvider()

foreach ($additionalFields as $additionalField) {
foreach ($templates as $template) {
$template[] = $additionalField[0];
$template[] = $additionalField[0] ?? null;
$fixture[] = $template;
}
}
Expand Down
6 changes: 3 additions & 3 deletions eZ/Publish/Core/FieldType/BinaryFile/SearchField.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
return [
new Search\Field(
'file_name',
$field->value->externalData['fileName'],
$field->value->externalData['fileName'] ?? null,
new Search\FieldType\StringField()
),
new Search\Field(
'file_size',
$field->value->externalData['fileSize'],
$field->value->externalData['fileSize'] ?? null,
new Search\FieldType\IntegerField()
),
new Search\Field(
'mime_type',
$field->value->externalData['mimeType'],
$field->value->externalData['mimeType'] ?? null,
new Search\FieldType\StringField()
),
];
Expand Down
2 changes: 1 addition & 1 deletion eZ/Publish/Core/FieldType/DateAndTime/SearchField.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
return [
new Search\Field(
'value',
$field->value->data['timestamp'],
$field->value->data['timestamp'] ?? null,
new Search\FieldType\DateField()
),
];
Expand Down
8 changes: 4 additions & 4 deletions eZ/Publish/Core/FieldType/Image/SearchField.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
return [
new Search\Field(
'filename',
$field->value->data['fileName'],
$field->value->data['fileName'] ?? null,
new Search\FieldType\StringField()
),
new Search\Field(
'alternative_text',
$field->value->data['alternativeText'],
$field->value->data['alternativeText'] ?? null,
new Search\FieldType\StringField()
),
new Search\Field(
'file_size',
$field->value->data['fileSize'],
$field->value->data['fileSize'] ?? null,
new Search\FieldType\IntegerField()
),
new Search\Field(
'mime_type',
$field->value->data['mime'],
$field->value->data['mime'] ?? null,
new Search\FieldType\StringField()
),
];
Expand Down
8 changes: 4 additions & 4 deletions eZ/Publish/Core/FieldType/MapLocation/SearchField.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
return [
new Search\Field(
'value_address',
$field->value->externalData['address'],
$field->value->externalData['address'] ?? null,
new Search\FieldType\StringField()
),
new Search\Field(
'value_location',
[
'latitude' => $field->value->externalData['latitude'],
'longitude' => $field->value->externalData['longitude'],
'latitude' => $field->value->externalData['latitude'] ?? null,
'longitude' => $field->value->externalData['longitude'] ?? null,
],
new Search\FieldType\GeoLocationField()
),
new Search\Field(
'fulltext',
$field->value->externalData['address'],
$field->value->externalData['address'] ?? null,
new Search\FieldType\FullTextField()
),
];
Expand Down
6 changes: 3 additions & 3 deletions eZ/Publish/Core/FieldType/Media/SearchField.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
return [
new Search\Field(
'file_name',
$field->value->externalData['fileName'],
$field->value->externalData['fileName'] ?? null,
new Search\FieldType\StringField()
),
new Search\Field(
'file_size',
$field->value->externalData['fileSize'],
$field->value->externalData['fileSize'] ?? null,
new Search\FieldType\IntegerField()
),
new Search\Field(
'mime_type',
$field->value->externalData['mimeType'],
$field->value->externalData['mimeType'] ?? null,
new Search\FieldType\StringField()
),
];
Expand Down
9 changes: 8 additions & 1 deletion eZ/Publish/Core/FieldType/Relation/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,14 @@ protected function getSortInfo(BaseValue $value)
*/
public function fromHash($hash)
{
return new Value($hash['destinationContentId']);
if ($hash !== null) {
$destinationContentId = $hash['destinationContentId'];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this should also use ?? null to get the destinationContentId?

if ($destinationContentId !== null) {
return new Value((int)$destinationContentId);
}
}

return $this->getEmptyValue();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion eZ/Publish/Core/FieldType/Tests/Url/UrlStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function testStoreFieldDataWithEmptyUrl()
$result = $storage->storeFieldData($versionInfo, $field, $this->getContext());

$this->assertFalse($result);
$this->assertNull($field->value->data['urlId']);
$this->assertNull($field->value->data);
}

public function testGetFieldData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue)
*/
public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef)
{
$storageDef->dataInt1 = (int)$fieldDef->fieldTypeConstraints->fieldSettings['defaultAuthor'];
$fieldSettings = $fieldDef->fieldTypeConstraints->fieldSettings;

if ($fieldSettings !== null) {
$storageDef->dataInt1 = (int)$fieldSettings['defaultAuthor'];
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,16 @@ public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue)
*/
public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef)
{
$storageDef->dataInt2 = $fieldDef->fieldTypeConstraints->fieldSettings['useSeconds'] ? 1 : 0;
$storageDef->dataInt1 = $fieldDef->fieldTypeConstraints->fieldSettings['defaultType'];
$fieldSettings = $fieldDef->fieldTypeConstraints->fieldSettings;
if ($fieldSettings === null) {
return;
}

$storageDef->dataInt2 = $fieldSettings['useSeconds'] ? 1 : 0;
$storageDef->dataInt1 = $fieldSettings['defaultType'];
alongosz marked this conversation as resolved.
Show resolved Hide resolved

if ($fieldDef->fieldTypeConstraints->fieldSettings['defaultType'] === DateAndTimeType::DEFAULT_CURRENT_DATE_ADJUSTED) {
$storageDef->dataText5 = $this->generateDateIntervalXML(
$fieldDef->fieldTypeConstraints->fieldSettings['dateInterval']
);
if ($fieldSettings['defaultType'] === DateAndTimeType::DEFAULT_CURRENT_DATE_ADJUSTED) {
$storageDef->dataText5 = $this->generateDateIntervalXML($fieldSettings['dateInterval']);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue)
*/
public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef)
{
$storageDef->dataInt1 = $fieldDef->fieldTypeConstraints->fieldSettings['defaultType'];
$storageDef->dataInt1 = $fieldDef->fieldTypeConstraints->fieldSettings['defaultType'] ?? null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue)
*/
public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef)
{
$storageDef->dataInt1 = $fieldDef->fieldTypeConstraints->fieldSettings['defaultType'];
$storageDef->dataInt2 = $fieldDef->fieldTypeConstraints->fieldSettings['useSeconds'] ? 1 : 0;
$fieldSettings = $fieldDef->fieldTypeConstraints->fieldSettings;

if ($fieldSettings !== null) {
$storageDef->dataInt1 = $fieldSettings['defaultType'];
$storageDef->dataInt2 = $fieldSettings['useSeconds'] ? 1 : 0;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,15 @@ public function testPublishFirstVersion()
->with(23, 1)
->will(
$this->returnValue(
new VersionInfo(['contentInfo' => new ContentInfo(['currentVersionNo' => 1])])
new VersionInfo([
'contentInfo' => new ContentInfo([
'currentVersionNo' => 1,
'mainLanguageCode' => 'eng-GB',
]),
'names' => [
'eng-GB' => '',
],
])
)
);

Expand Down Expand Up @@ -325,7 +333,15 @@ public function testPublish()
->with(23, 2)
->will(
$this->returnValue(
new VersionInfo(['contentInfo' => new ContentInfo(['currentVersionNo' => 1])])
new VersionInfo([
'contentInfo' => new ContentInfo([
'currentVersionNo' => 1,
'mainLanguageCode' => 'eng-GB',
]),
'names' => [
'eng-GB' => '',
],
])
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ protected function getModuloCharRange($start, $end, $modulo)
*/
protected function getTransposeClosure($operator, $value)
{
$value = hexdec($value) * ($operator === '-' ? -1 : 1);
$value = $this->hexdec($value) * ($operator === '-' ? -1 : 1);
$converter = $this->converter;

return function ($matches) use ($value, $converter) {
Expand Down Expand Up @@ -273,4 +273,18 @@ protected function compileCharacter($char)
throw new RuntimeException("Invalid character definition: $char");
}
}

/**
* Converts a hexadecimal string to a decimal number.
*
* In compare to standard hexdec function it will ignore any non-hexadecimal characters
adamwojs marked this conversation as resolved.
Show resolved Hide resolved
*/
private function hexdec(?string $value): int
{
if ($value === null) {
return 0;
}

return hexdec(preg_replace('/[^[:xdigit:]]/', '', (string)$value));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ protected function setUp()
$this->userSPIPreferenceHandler = $this->getPersistenceMockHandler('UserPreference\\Handler');
$permissionResolverMock = $this->createMock(PermissionResolver::class);
$permissionResolverMock
->expects($this->atLeastOnce())
->method('getCurrentUserReference')
->willReturn(new UserReference(self::CURRENT_USER_ID));
$repository = $this->getRepositoryMock();
$repository
->expects($this->atLeastOnce())
->method('getPermissionResolver')
->willReturn($permissionResolverMock);
}
Expand Down
13 changes: 9 additions & 4 deletions eZ/Publish/Core/Repository/UserPreferenceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,27 @@ public function setUserPreference(array $userPreferenceSetStructs): void
{
$spiSetStructs = [];
foreach ($userPreferenceSetStructs as $key => $userPreferenceSetStruct) {
$spiSetStruct = new UserPreferenceSetStruct();
$spiSetStruct->userId = $this->getCurrentUserId();

if (empty($userPreferenceSetStruct->name)) {
throw new InvalidArgumentException('name', $userPreferenceSetStruct->name . ' at index ' . $key);
}

$spiSetStruct->name = $userPreferenceSetStruct->name;
$value = $userPreferenceSetStruct->value;

if (is_object($value) && !method_exists($value, '__toString')) {
throw new InvalidArgumentException('value', 'Cannot convert value to string at index ' . $key);
}

try {
$value = (string)$userPreferenceSetStruct->value;
} catch (\Exception $exception) {
throw new InvalidArgumentException('value', 'Can not convert value to string at index ' . $key);
}

$spiSetStruct = new UserPreferenceSetStruct();
$spiSetStruct->userId = $this->getCurrentUserId();
$spiSetStruct->name = $userPreferenceSetStruct->name;
$spiSetStruct->value = $value;

$spiSetStructs[] = $spiSetStruct;
}

Expand Down