From 94e105ca2975779a30dcbe6120183138bcf62b64 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Thu, 18 Jul 2024 09:22:50 +0200 Subject: [PATCH] fix tests --- behat-bootstrap.php | 23 +- config/preload.php | 5 + .../Behat/Context/Domain/PimcoreContext.php | 8 +- .../Behat/Context/Hook/PimcoreDaoContext.php | 4 +- .../Context/Setup/ImportDefinitionContext.php | 113 +++--- .../Context/Setup/PimcoreAssetContext.php | 10 +- .../Context/Setup/PimcoreClassContext.php | 324 +++++++++++------- .../Transform/ImportDefinitionContext.php | 13 +- .../Context/Transform/PimcoreAssetContext.php | 8 +- .../Context/Transform/PimcoreClassContext.php | 26 +- .../Behat/Service/ClassStorage.php | 3 +- .../Behat/Service/SharedStorage.php | 11 +- 12 files changed, 304 insertions(+), 244 deletions(-) create mode 100644 config/preload.php diff --git a/behat-bootstrap.php b/behat-bootstrap.php index 4fa4f677..dc04b68c 100755 --- a/behat-bootstrap.php +++ b/behat-bootstrap.php @@ -1,4 +1,14 @@ sharedStorage = $sharedStorage; + } /** diff --git a/tests/DataDefinitionsBundle/Behat/Context/Hook/PimcoreDaoContext.php b/tests/DataDefinitionsBundle/Behat/Context/Hook/PimcoreDaoContext.php index fae83dc9..2ebd3f99 100644 --- a/tests/DataDefinitionsBundle/Behat/Context/Hook/PimcoreDaoContext.php +++ b/tests/DataDefinitionsBundle/Behat/Context/Hook/PimcoreDaoContext.php @@ -28,8 +28,8 @@ final class PimcoreDaoContext implements Context { public function __construct( - private Connection $connection, - private KernelInterface $kernel, + private readonly Connection $connection, + private readonly KernelInterface $kernel, ) { diff --git a/tests/DataDefinitionsBundle/Behat/Context/Setup/ImportDefinitionContext.php b/tests/DataDefinitionsBundle/Behat/Context/Setup/ImportDefinitionContext.php index 866cd01e..5d2b25e7 100644 --- a/tests/DataDefinitionsBundle/Behat/Context/Setup/ImportDefinitionContext.php +++ b/tests/DataDefinitionsBundle/Behat/Context/Setup/ImportDefinitionContext.php @@ -29,33 +29,16 @@ final class ImportDefinitionContext implements Context { - private $sharedStorage; - private $factory; - private $manager; - private $importer; - private $formFactory; - private $providerFormRegistry; - private $interpreterFormRegistry; - private $setterFormRegistry; - public function __construct( - SharedStorageInterface $sharedStorage, - FactoryInterface $factory, - ObjectManager $manager, - ImporterInterface $importer, - FormFactoryInterface $formFactory, - FormTypeRegistryInterface $providerFormRegistry, - FormTypeRegistryInterface $interpreterFormRegistry, - FormTypeRegistryInterface $setterFormRegistry + private readonly SharedStorageInterface $sharedStorage, + private readonly FactoryInterface $factory, + private readonly ObjectManager $manager, + private readonly ImporterInterface $importer, + private readonly FormFactoryInterface $formFactory, + private readonly FormTypeRegistryInterface $providerFormRegistry, + private readonly FormTypeRegistryInterface $interpreterFormRegistry, + private readonly FormTypeRegistryInterface $setterFormRegistry ) { - $this->sharedStorage = $sharedStorage; - $this->factory = $factory; - $this->manager = $manager; - $this->importer = $importer; - $this->formFactory = $formFactory; - $this->providerFormRegistry = $providerFormRegistry; - $this->interpreterFormRegistry = $interpreterFormRegistry; - $this->setterFormRegistry = $setterFormRegistry; } /** @@ -63,7 +46,7 @@ public function __construct( * @Given /^there is a import-definition "([^"]+)" for (definition)$/ * @Given /^there is a import-definition "([^"]+)" for (class "[^"]+")$/ */ - public function thereIsAImportDefinition($name, ClassDefinition $definition = null) + public function thereIsAImportDefinition(string $name, ClassDefinition $definition = null): void { /** * @var ImportDefinitionInterface $importDefinition @@ -87,9 +70,9 @@ public function thereIsAImportDefinition($name, ClassDefinition $definition = nu */ public function theImportDefinitionsProviderIs( ImportDefinitionInterface $importDefinition, - $provider, + string $provider, TableNode $tableNode = null - ) { + ): void { $importDefinition->setProvider($provider); if (null !== $tableNode) { @@ -103,7 +86,7 @@ public function theImportDefinitionsProviderIs( /** * @Given /^the (import-definitions) loader is "([^"]+)"$/ */ - public function theImportDefinitionsLoaderIs(ImportDefinitionInterface $importDefinition, $loader) + public function theImportDefinitionsLoaderIs(ImportDefinitionInterface $importDefinition, string $loader): void { $importDefinition->setLoader($loader); @@ -113,7 +96,7 @@ public function theImportDefinitionsLoaderIs(ImportDefinitionInterface $importDe /** * @Given /^the (import-definitions) object-path is "([^"]+)"$/ */ - public function theImportDefinitionsObjectPathIs(ImportDefinitionInterface $importDefinition, $objectPath) + public function theImportDefinitionsObjectPathIs(ImportDefinitionInterface $importDefinition, string $objectPath): void { $importDefinition->setObjectPath($objectPath); @@ -123,7 +106,7 @@ public function theImportDefinitionsObjectPathIs(ImportDefinitionInterface $impo /** * @Given /^the (import-definitions) cleaner is "([^"]+)"$/ */ - public function theImportDefinitionsCleanerIs(ImportDefinitionInterface $importDefinition, $cleaner) + public function theImportDefinitionsCleanerIs(ImportDefinitionInterface $importDefinition, string $cleaner): void { $importDefinition->setCleaner($cleaner); @@ -133,7 +116,7 @@ public function theImportDefinitionsCleanerIs(ImportDefinitionInterface $importD /** * @Given /^the (import-definitions) key is "([^"]+)"$/ */ - public function theImportDefinitionsKeyIs(ImportDefinitionInterface $importDefinition, $key) + public function theImportDefinitionsKeyIs(ImportDefinitionInterface $importDefinition, string $key): void { $importDefinition->setKey($key); @@ -143,7 +126,7 @@ public function theImportDefinitionsKeyIs(ImportDefinitionInterface $importDefin /** * @Given /^the (import-definitions) filter is "([^"]+)"$/ */ - public function theImportDefinitionsFilterIs(ImportDefinitionInterface $importDefinition, $filter) + public function theImportDefinitionsFilterIs(ImportDefinitionInterface $importDefinition, string $filter): void { $importDefinition->setFilter($filter); @@ -153,7 +136,7 @@ public function theImportDefinitionsFilterIs(ImportDefinitionInterface $importDe /** * @Given /^the (import-definitions) renames existing objects$/ */ - public function theImportDefinitionsRenamesExistingObjects(ImportDefinitionInterface $importDefinition) + public function theImportDefinitionsRenamesExistingObjects(ImportDefinitionInterface $importDefinition): void { $importDefinition->setRenameExistingObjects(true); @@ -163,7 +146,7 @@ public function theImportDefinitionsRenamesExistingObjects(ImportDefinitionInter /** * @Given /^the (import-definitions) does not rename existing objects$/ */ - public function theImportDefinitionsDoesNotRenameExistingObjects(ImportDefinitionInterface $importDefinition) + public function theImportDefinitionsDoesNotRenameExistingObjects(ImportDefinitionInterface $importDefinition): void { $importDefinition->setRenameExistingObjects(false); @@ -173,7 +156,7 @@ public function theImportDefinitionsDoesNotRenameExistingObjects(ImportDefinitio /** * @Given /^the (import-definitions) relocates existing objects$/ */ - public function theImportDefinitionsRelocatesExistingObjects(ImportDefinitionInterface $importDefinition) + public function theImportDefinitionsRelocatesExistingObjects(ImportDefinitionInterface $importDefinition): void { $importDefinition->setRelocateExistingObjects(true); @@ -183,7 +166,7 @@ public function theImportDefinitionsRelocatesExistingObjects(ImportDefinitionInt /** * @Given /^the (import-definitions) does not relocate existing objects$/ */ - public function theImportDefinitionsDoesNotRelocateExistingObjects(ImportDefinitionInterface $importDefinition) + public function theImportDefinitionsDoesNotRelocateExistingObjects(ImportDefinitionInterface $importDefinition): void { $importDefinition->setRelocateExistingObjects(false); @@ -193,7 +176,7 @@ public function theImportDefinitionsDoesNotRelocateExistingObjects(ImportDefinit /** * @Given /^the (import-definitions) omits the mandatory check$/ */ - public function theImportDefinitionsOmitsTheMandatoryCheck(ImportDefinitionInterface $importDefinition) + public function theImportDefinitionsOmitsTheMandatoryCheck(ImportDefinitionInterface $importDefinition): void { $importDefinition->setOmitMandatoryCheck(true); @@ -203,7 +186,7 @@ public function theImportDefinitionsOmitsTheMandatoryCheck(ImportDefinitionInter /** * @Given /^the (import-definitions) does not omit the mandatory check$/ */ - public function theImportDefinitionsDosNotOmitTheMandatoryCheck(ImportDefinitionInterface $importDefinition) + public function theImportDefinitionsDosNotOmitTheMandatoryCheck(ImportDefinitionInterface $importDefinition): void { $importDefinition->setOmitMandatoryCheck(false); @@ -213,7 +196,7 @@ public function theImportDefinitionsDosNotOmitTheMandatoryCheck(ImportDefinition /** * @Given /^the (import-definitions) skips new objects$/ */ - public function theImportDefinitionsSkipsNewObjects(ImportDefinitionInterface $importDefinition) + public function theImportDefinitionsSkipsNewObjects(ImportDefinitionInterface $importDefinition): void { $importDefinition->setSkipNewObjects(true); @@ -223,7 +206,7 @@ public function theImportDefinitionsSkipsNewObjects(ImportDefinitionInterface $i /** * @Given /^the (import-definitions) does not skip new objects$/ */ - public function theImportDefinitionsDoesNotSkipNewObjects(ImportDefinitionInterface $importDefinition) + public function theImportDefinitionsDoesNotSkipNewObjects(ImportDefinitionInterface $importDefinition): void { $importDefinition->setSkipNewObjects(false); @@ -233,7 +216,7 @@ public function theImportDefinitionsDoesNotSkipNewObjects(ImportDefinitionInterf /** * @Given /^the (import-definitions) skips existing objects$/ */ - public function theImportDefinitionsSkipsExistingObjects(ImportDefinitionInterface $importDefinition) + public function theImportDefinitionsSkipsExistingObjects(ImportDefinitionInterface $importDefinition): void { $importDefinition->setSkipExistingObjects(true); @@ -243,7 +226,7 @@ public function theImportDefinitionsSkipsExistingObjects(ImportDefinitionInterfa /** * @Given /^the (import-definitions) does not skip existing objects$/ */ - public function theImportDefinitionsDoesNotSkipExistingObjects(ImportDefinitionInterface $importDefinition) + public function theImportDefinitionsDoesNotSkipExistingObjects(ImportDefinitionInterface $importDefinition): void { $importDefinition->setSkipExistingObjects(false); @@ -253,7 +236,7 @@ public function theImportDefinitionsDoesNotSkipExistingObjects(ImportDefinitionI /** * @Given /^the (import-definitions) force loads objects$/ */ - public function theImportDefinitionsForceLoadsObjects(ImportDefinitionInterface $importDefinition) + public function theImportDefinitionsForceLoadsObjects(ImportDefinitionInterface $importDefinition): void { $importDefinition->setForceLoadObject(true); @@ -263,7 +246,7 @@ public function theImportDefinitionsForceLoadsObjects(ImportDefinitionInterface /** * @Given /^the (import-definitions) does not force load objects$/ */ - public function theImportDefinitionsDoesNotForceLoadObjects(ImportDefinitionInterface $importDefinition) + public function theImportDefinitionsDoesNotForceLoadObjects(ImportDefinitionInterface $importDefinition): void { $importDefinition->setForceLoadObject(false); @@ -273,7 +256,7 @@ public function theImportDefinitionsDoesNotForceLoadObjects(ImportDefinitionInte /** * @Given /the (import-definitions) mapping is:/ */ - public function theImportDefinitionsMappingIs(ImportDefinitionInterface $definition, TableNode $table) + public function theImportDefinitionsMappingIs(ImportDefinitionInterface $definition, TableNode $table): void { $hash = $table->getHash(); @@ -333,7 +316,12 @@ public function theImportDefinitionsMappingIs(ImportDefinitionInterface $definit * @Given /the (import-definitions) mapping for column "([^"]+)" uses interpreter "([^"]+)" with config:/ * @Given /the (import-definition "[^"]+") mapping for column "([^"]+)" uses interpreter "([^"]+)" with config:/ */ - public function theImportDefinitionsHasAMapping(ImportDefinitionInterface $definition, $toColumn, $interpreter, PyStringNode $config) + public function theImportDefinitionsHasAMapping( + ImportDefinitionInterface $definition, + string $toColumn, + string $interpreter, + PyStringNode $config + ): void { $column = null; @@ -369,7 +357,11 @@ public function theImportDefinitionsHasAMapping(ImportDefinitionInterface $defin * @Given /the (import-definitions) mapping for column "([^"]+)" uses interpreter "definition" for (import-definition "([^"]+)")$/ * @Given /the (import-definition "[^"]+") mapping for column "([^"]+)" uses interpreter "definition" for (import-definition "([^"]+)")$/ */ - public function theImportDefinitionsHasAMappingForInterpreterDefinition(ImportDefinitionInterface $definition, $toColumn, ImportDefinitionInterface $subDefinition) + public function theImportDefinitionsHasAMappingForInterpreterDefinition( + ImportDefinitionInterface $definition, + string $toColumn, + ImportDefinitionInterface $subDefinition + ): void { $column = null; @@ -405,7 +397,7 @@ public function theImportDefinitionsHasAMappingForInterpreterDefinition(ImportDe /** * @Given there is a file :file with content: */ - public function thereIsACSVFileWithContent($path, PyStringNode $content) + public function thereIsACSVFileWithContent(string $path, PyStringNode $content): void { file_put_contents(PIMCORE_PROJECT_ROOT.'/'.$path, $content); } @@ -414,7 +406,7 @@ public function thereIsACSVFileWithContent($path, PyStringNode $content) * @Given /I run the (import-definitions) with params:/ * @Given /I run the (import-definition "[^"]+") with params:/ */ - public function IRunTheImportDefinition(ImportDefinitionInterface $importDefinition, TableNode $tableNode) + public function IRunTheImportDefinition(ImportDefinitionInterface $importDefinition, TableNode $tableNode): void { $config = []; @@ -425,13 +417,7 @@ public function IRunTheImportDefinition(ImportDefinitionInterface $importDefinit $this->importer->doImport($importDefinition, $config); } - /** - * @param FormTypeRegistryInterface $formRegistry - * @param $type - * @param TableNode $tableNode - * @return array - */ - private function processTableConfiguration(FormTypeRegistryInterface $formRegistry, $type, TableNode $tableNode) + private function processTableConfiguration(FormTypeRegistryInterface $formRegistry, string $type, TableNode $tableNode): array { $config = []; @@ -442,13 +428,7 @@ private function processTableConfiguration(FormTypeRegistryInterface $formRegist return $this->processArrayConfiguration($formRegistry, $type, $config); } - /** - * @param FormTypeRegistryInterface $formRegistry - * @param $type - * @param array $data - * @return array - */ - private function processArrayConfiguration(FormTypeRegistryInterface $formRegistry, $type, array $data) + private function processArrayConfiguration(FormTypeRegistryInterface $formRegistry, string $type, array $data): array { $formType = $formRegistry->get($type, 'default'); @@ -462,10 +442,7 @@ private function processArrayConfiguration(FormTypeRegistryInterface $formRegist return $form->getData(); } - /** - * @param ImportDefinitionInterface $importDefinition - */ - private function persist(ImportDefinitionInterface $importDefinition) + private function persist(ImportDefinitionInterface $importDefinition): void { $this->sharedStorage->set('import-definition', $importDefinition); diff --git a/tests/DataDefinitionsBundle/Behat/Context/Setup/PimcoreAssetContext.php b/tests/DataDefinitionsBundle/Behat/Context/Setup/PimcoreAssetContext.php index 62251a50..c677765d 100644 --- a/tests/DataDefinitionsBundle/Behat/Context/Setup/PimcoreAssetContext.php +++ b/tests/DataDefinitionsBundle/Behat/Context/Setup/PimcoreAssetContext.php @@ -21,22 +21,18 @@ final class PimcoreAssetContext implements Context { - private $sharedStorage; - private $kernel; public function __construct( - SharedStorageInterface $sharedStorage, - KernelInterface $kernel + private readonly SharedStorageInterface $sharedStorage, + private readonly KernelInterface $kernel ) { - $this->sharedStorage = $sharedStorage; - $this->kernel = $kernel; } /** * @Given /^there is a asset with bundle file "([^"]+)"$/ * @Given /^there is a asset with bundle file "([^"]+)" at path "([^"]+)"$/ */ - public function thereIsAAssetWithBundleFile($bundleFile, $parentPath = null) + public function thereIsAAssetWithBundleFile(string $bundleFile, ?string $parentPath = null): void { $path = $this->kernel->locateResource($bundleFile); $parentId = 1; diff --git a/tests/DataDefinitionsBundle/Behat/Context/Setup/PimcoreClassContext.php b/tests/DataDefinitionsBundle/Behat/Context/Setup/PimcoreClassContext.php index 6c1791ed..2e5a2a2a 100644 --- a/tests/DataDefinitionsBundle/Behat/Context/Setup/PimcoreClassContext.php +++ b/tests/DataDefinitionsBundle/Behat/Context/Setup/PimcoreClassContext.php @@ -22,7 +22,6 @@ use CoreShop\Component\Pimcore\DataObject\ClassUpdate; use CoreShop\Component\Pimcore\DataObject\ClassUpdateInterface; use CoreShop\Component\Pimcore\DataObject\FieldCollectionDefinitionUpdate; -use CoreShop\Component\Pimcore\Exception\ClassDefinitionNotFoundException; use Pimcore\Model\DataObject; use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\DataObject\Concrete; @@ -32,28 +31,59 @@ final class PimcoreClassContext implements Context { - private $sharedStorage; - private $classStorage; - public function __construct( - SharedStorageInterface $sharedStorage, - ClassStorageInterface $classStorage + private readonly SharedStorageInterface $sharedStorage, + private readonly ClassStorageInterface $classStorage, ) { - $this->sharedStorage = $sharedStorage; - $this->classStorage = $classStorage; + } + + /** + * @Given /^I enable inheritance for class "([^"]+)"$/ + */ + public function iEnableInheritanceForPimcoreClass($className): void + { + $definitionUpdater = new ClassUpdate($className); + $definitionUpdater->setProperty('allowInherit', true); + $definitionUpdater->save(); + } + + /** + * @Given /^I enable variants for class "([^"]+)"$/ + */ + public function iEnableVariantsForPimcoreClass($className): void + { + $definitionUpdater = new ClassUpdate($className); + $definitionUpdater->setProperty('allowVariants', true); + $definitionUpdater->save(); + } + + /** + * @Given /^I enable pimcore inheritance$/ + */ + public function enableInheritance(): void + { + DataObject\AbstractObject::setGetInheritedValues(true); + } + + /** + * @Given /^I disable pimcore inheritance$/ + */ + public function disableInheritance(): void + { + DataObject\AbstractObject::setGetInheritedValues(false); } /** * @Given /^there is a pimcore class "([^"]+)"$/ */ - public function createClassNamed($className) + public function createClassNamed($className): void { $name = $this->classStorage->set($className); $classDefinition = new ClassDefinition(); $classDefinition->setName($name); $classDefinition->setLayoutDefinitions( - json_decode('', true) + json_decode(''), ); $classDefinition->save(); @@ -126,19 +156,19 @@ public function createClassNamed($className) ClassDefinition\Service::importClassDefinitionFromJson($classDefinition, $json, true); $this->sharedStorage->set('pimcore_definition_name', $className); - $this->sharedStorage->set('pimcore_definition_class', get_class($classDefinition)); + $this->sharedStorage->set('pimcore_definition_class', $classDefinition::class); } /** * @Given /^there is a pimcore brick "([^"]+)"$/ */ - public function createBrickNamed($brickName) + public function createBrickNamed($brickName): void { $name = $this->classStorage->set($brickName); $brickDefinition = new Objectbrick\Definition(); $brickDefinition->setKey($name); - $brickDefinition->setLayoutDefinitions([]); + $brickDefinition->setLayoutDefinitions(null); $brickDefinition->save(); $json = '{ @@ -186,13 +216,13 @@ public function createBrickNamed($brickName) ClassDefinition\Service::importObjectBrickFromJson($brickDefinition, $json, true); $this->sharedStorage->set('pimcore_definition_name', $brickName); - $this->sharedStorage->set('pimcore_definition_class', get_class($brickDefinition)); + $this->sharedStorage->set('pimcore_definition_class', $brickDefinition::class); } /** * @Given /^there is a pimcore field-collection "([^"]+)"$/ */ - public function createCollectionNamed($collection) + public function createCollectionNamed($collection): void { $name = $this->classStorage->set($collection); @@ -244,13 +274,13 @@ public function createCollectionNamed($collection) ClassDefinition\Service::importFieldCollectionFromJson($collectionDefinition, $json, true); $this->sharedStorage->set('pimcore_definition_name', $collection); - $this->sharedStorage->set('pimcore_definition_class', get_class($collectionDefinition)); + $this->sharedStorage->set('pimcore_definition_class', $collectionDefinition::class); } /** * @Given /^the (definitions) parent class is set to "([^"]+)"$/ */ - public function definitionsParentClassIsSetTo($definition, $parentClass) + public function definitionsParentClassIsSetTo($definition, $parentClass): void { $definitionUpdater = $this->getUpdater($definition); $definitionUpdater->setProperty('parentClass', $parentClass); @@ -260,7 +290,7 @@ public function definitionsParentClassIsSetTo($definition, $parentClass) /** * @Given /^the (definition) is allowed for (behat-class "[^"]+") in field "([^"]+)"$/ */ - public function theDefinitionIsAllowedForClass($definition, ClassDefinition $class, $field) + public function theDefinitionIsAllowedForClass($definition, ClassDefinition $class, $field): void { if (!$definition instanceof Objectbrick\Definition) { throw new \InvalidArgumentException('This call is only allowed for brick definitions'); @@ -279,14 +309,12 @@ public function theDefinitionIsAllowedForClass($definition, ClassDefinition $cla /** * @Given /^the (definition) has a input field "([^"]+)"$/ */ - public function definitionHasInputField($definition, $name) + public function definitionHasInputField($definition, $name): void { $jsonDefinition = sprintf(' { "fieldtype": "input", "width": null, - "queryColumnType": "varchar", - "columnType": "varchar", "columnLength": 190, "phpdocType": "string", "regex": "", @@ -341,19 +369,31 @@ public function definitionHasExternalImageField($definition, $name) $this->addFieldDefinitionToDefinition($definition, $jsonDefinition); } - /** - * @Given /^the (definition) has a link field "([^"]+)"$/ + /** + * @Given /^the (definition) has a numeric field "([^"]+)"$/ */ - public function definitionHasLinkField($definition, $name) + public function definitionHasNumberField($definition, $name): void { $jsonDefinition = sprintf(' { - "fieldtype": "link", + "fieldtype": "numeric", + "width": "", + "defaultValue": null, + "queryColumnType": "double", + "columnType": "double", + "phpdocType": "float", + "integer": false, + "unsigned": false, + "minValue": null, + "maxValue": null, + "unique": null, + "decimalSize": null, + "decimalPrecision": null, "name": "%s", "title": "%s", "tooltip": "", "mandatory": false, - "noteditable": false, + "noteditable": true, "index": false, "locked": false, "style": "", @@ -362,7 +402,8 @@ public function definitionHasLinkField($definition, $name) "relationType": false, "invisible": false, "visibleGridView": false, - "visibleSearch": false + "visibleSearch": false, + "defaultValueGenerator": "" } ', $name, $name); @@ -370,19 +411,47 @@ public function definitionHasLinkField($definition, $name) } /** - * @Given /^the (definition) has a wysiwyg field "([^"]+)"$/ + * @Given /^the (definition) has a image field "([^"]+)"$/ */ - public function definitionHasWysiwygField($definition, $name) + public function definitionHasImageField($definition, $name) { $jsonDefinition = sprintf(' { - "fieldtype": "wsysiwyg", - "width": null, - "queryColumnType": "varchar", - "columnType": "varchar", - "columnLength": 190, - "phpdocType": "string", - "regex": "", + "fieldtype":"image", + "width":350, + "height":350, + "uploadPath":"", + "queryColumnType":"int(11)", + "columnType":"int(11)", + "phpdocType":"\\Pimcore\\Model\\Asset\\Image", + "name": "%s", + "title": "%s", + "tooltip":"", + "mandatory":false, + "noteditable":false, + "index":false, + "locked":false, + "style":"", + "permissions":null, + "datatype":"data", + "relationType":false, + "invisible":false, + "visibleGridView":false, + "visibleSearch":false + } + ', $name, $name); + + $this->addFieldDefinitionToDefinition($definition, $jsonDefinition); + } + + /** + * @Given /^the (definition) has a link field "([^"]+)"$/ + */ + public function definitionHasLinkField($definition, $name) + { + $jsonDefinition = sprintf(' + { + "fieldtype": "link", "name": "%s", "title": "%s", "tooltip": "", @@ -395,8 +464,8 @@ public function definitionHasWysiwygField($definition, $name) "datatype": "data", "relationType": false, "invisible": false, - "visibleGridView": true, - "visibleSearch": true + "visibleGridView": false, + "visibleSearch": false } ', $name, $name); @@ -404,33 +473,40 @@ public function definitionHasWysiwygField($definition, $name) } /** - * @Given /^the (definition) has a image field "([^"]+)"$/ + * @Given /^the (definition) has a numeric integer field "([^"]+)"$/ */ - public function definitionHasImageField($definition, $name) + public function definitionHasIntegerField($definition, $name): void { $jsonDefinition = sprintf(' { - "fieldtype":"image", - "width":350, - "height":350, - "uploadPath":"", - "queryColumnType":"int(11)", - "columnType":"int(11)", - "phpdocType":"\\Pimcore\\Model\\Asset\\Image", + "fieldtype": "numeric", + "width": "", + "defaultValue": null, + "queryColumnType": "int", + "columnType": "int", + "phpdocType": "int", + "integer": true, + "unsigned": false, + "minValue": null, + "maxValue": null, + "unique": null, + "decimalSize": null, + "decimalPrecision": null, "name": "%s", "title": "%s", - "tooltip":"", - "mandatory":false, - "noteditable":false, - "index":false, - "locked":false, - "style":"", - "permissions":null, - "datatype":"data", - "relationType":false, - "invisible":false, - "visibleGridView":false, - "visibleSearch":false + "tooltip": "", + "mandatory": true, + "noteditable": true, + "index": false, + "locked": false, + "style": "", + "permissions": null, + "datatype": "data", + "relationType": false, + "invisible": false, + "visibleGridView": false, + "visibleSearch": false, + "defaultValueGenerator": "" } ', $name, $name); @@ -440,7 +516,7 @@ public function definitionHasImageField($definition, $name) /** * @Given /^the (definition) has a relation field "([^"]+)"$/ */ - public function definitionHasRelationField($definition, $name) + public function definitionHasRelationField($definition, $name): void { $jsonDefinition = sprintf(' { @@ -448,11 +524,6 @@ public function definitionHasRelationField($definition, $name) "width": "", "assetUploadPath": "", "relationType": true, - "queryColumnType": { - "id": "int(11)", - "type": "enum(\'document\',\'asset\',\'object\')" - }, - "phpdocType": "\\Pimcore\\Model\\Document\\Page | \\Pimcore\\Model\\Document\\Snippet | \\Pimcore\\Model\\Document | \\Pimcore\\Model\\Asset | \\Pimcore\\Model\\DataObject\\AbstractObject", "objectsAllowed": true, "assetsAllowed": false, "assetTypes": [], @@ -484,15 +555,13 @@ public function definitionHasRelationField($definition, $name) /** * @Given /^the (definition) has a checkbox field "([^"]+)"$/ */ - public function definitionHasCheckboxField($definition, $name) + public function definitionHasCheckboxField($definition, $name): void { $jsonDefinition = sprintf(' { "fieldtype": "checkbox", + "datatype": "data", "defaultValue": 0, - "queryColumnType": "tinyint(1)", - "columnType": "tinyint(1)", - "phpdocType": "boolean", "name": "%s", "title": "%s", "tooltip": "", @@ -516,7 +585,7 @@ public function definitionHasCheckboxField($definition, $name) /** * @Given /^the (definition) has a localized input field "([^"]+)"$/ */ - public function definitionHasLocalizedInputField($definition, $name) + public function definitionHasLocalizedInputField($definition, $name): void { $jsonDefinition = sprintf(' { @@ -526,10 +595,7 @@ public function definitionHasLocalizedInputField($definition, $name) { "fieldtype": "input", "width": null, - "queryColumnType": "varchar", - "columnType": "varchar", "columnLength": 190, - "phpdocType": "string", "regex": "", "unique": false, "name": "%s", @@ -566,8 +632,6 @@ public function definitionHasLocalizedInputField($definition, $name) "style": "", "permissions": null, "datatype": "data", - "columnType": null, - "queryColumnType": null, "relationType": false, "invisible": false, "visibleGridView": true, @@ -581,7 +645,7 @@ public function definitionHasLocalizedInputField($definition, $name) /** * @Given /^the (definition) has a localized textarea field "([^"]+)"$/ */ - public function definitionHasLocalizedTextareaField($definition, $name) + public function definitionHasLocalizedTextareaField($definition, $name): void { $jsonDefinition = sprintf(' { @@ -592,9 +656,6 @@ public function definitionHasLocalizedTextareaField($definition, $name) "fieldtype": "textarea", "width": "", "height": "", - "queryColumnType": "longtext", - "columnType": "longtext", - "phpdocType": "string", "name": "%s", "title": "%s", "tooltip": "", @@ -629,8 +690,6 @@ public function definitionHasLocalizedTextareaField($definition, $name) "style": "", "permissions": null, "datatype": "data", - "columnType": null, - "queryColumnType": null, "relationType": false, "invisible": false, "visibleGridView": true, @@ -644,10 +703,10 @@ public function definitionHasLocalizedTextareaField($definition, $name) /** * @Given /^the (definition) has a brick field "([^"]+)"$/ */ - public function definitionHasABrickField($definition, $name) + public function definitionHasABrickField($definition, $name): void { if (!$definition instanceof ClassDefinition) { - throw new \InvalidArgumentException(sprintf('Bricks are only allowed in ClassDefinitions, given %s', null !== $definition ? get_class($definition) : 'null')); + throw new \InvalidArgumentException(sprintf('Bricks are only allowed in ClassDefinitions, given %s', null !== $definition ? $definition::class : 'null')); } $jsonDefinition = sprintf(' @@ -655,7 +714,7 @@ public function definitionHasABrickField($definition, $name) "fieldtype": "objectbricks", "phpdocType": "\\Pimcore\\Model\\DataObject\\Objectbrick", "allowedTypes": [], - "maxItems": "", + "maxItems": null, "name": "%s", "title": "%s", "tooltip": "", @@ -666,8 +725,6 @@ public function definitionHasABrickField($definition, $name) "style": "", "permissions": null, "datatype": "data", - "columnType": null, - "queryColumnType": null, "relationType": false, "invisible": false, "visibleGridView": false, @@ -681,10 +738,10 @@ public function definitionHasABrickField($definition, $name) /** * @Given /^the (definition) has a field-collection field "([^"]+)" for (field-collection "[^"]+")$/ */ - public function definitionHasAFieldCollectionField($definition, $name, Fieldcollection\Definition $fieldCollectionDefinition) + public function definitionHasAFieldCollectionField($definition, $name, Fieldcollection\Definition $fieldCollectionDefinition): void { if (!$definition instanceof ClassDefinition) { - throw new \InvalidArgumentException(sprintf('Fieldcollections are only allowed in ClassDefinitions, given %s', null !== $definition ? get_class($definition) : 'null')); + throw new \InvalidArgumentException(sprintf('Fieldcollections are only allowed in ClassDefinitions, given %s', null !== $definition ? $definition::class : 'null')); } $jsonDefinition = sprintf(' @@ -695,7 +752,7 @@ public function definitionHasAFieldCollectionField($definition, $name, Fieldcoll "%s" ], "lazyLoading": true, - "maxItems": "", + "maxItems": null, "disallowAddRemove": false, "disallowReorder": false, "collapsed": false, @@ -710,8 +767,6 @@ public function definitionHasAFieldCollectionField($definition, $name, Fieldcoll "style": "", "permissions": null, "datatype": "data", - "columnType": null, - "queryColumnType": null, "relationType": false, "invisible": false, "visibleGridView": false, @@ -725,8 +780,11 @@ public function definitionHasAFieldCollectionField($definition, $name, Fieldcoll /** * @Given /^there is an instance of (class|behat-class "[^"]+") with key "([^"]+)"$/ */ - public function thereIsAnInstanceofClassWithKey(ClassDefinition $definition, $key) + public function thereIsAnInstanceofClassWithKey(ClassDefinition $definition, $key): void { + /** + * @var class-string $className + */ $className = sprintf('Pimcore\\Model\\DataObject\\%s', $definition->getName()); /** * @var Concrete $instance @@ -739,10 +797,20 @@ public function thereIsAnInstanceofClassWithKey(ClassDefinition $definition, $ke $this->sharedStorage->set('object-instance', $instance); } + /** + * @Given /^I reload the (object-instance) into object-instance-2$/ + */ + public function iReloadTheObjectInstanceIntoObjectInstance2(Concrete $dataObject): void + { + $newInstance = $dataObject::getById($dataObject->getId(), ['force' => true]); + + $this->sharedStorage->set('object-instance-2', $newInstance); + } + /** * @Given /^the (object-instance) is published$/ */ - public function theObjectInstanceIsPublished(Concrete $instance) + public function theObjectInstanceIsPublished(Concrete $instance): void { $instance->setPublished(true); $instance->save(); @@ -751,7 +819,7 @@ public function theObjectInstanceIsPublished(Concrete $instance) /** * @Given /^the (object-instance) is not published$/ */ - public function theObjectInstanceIsNotPublished(Concrete $instance) + public function theObjectInstanceIsNotPublished(Concrete $instance): void { $instance->setPublished(false); $instance->save(); @@ -759,28 +827,42 @@ public function theObjectInstanceIsNotPublished(Concrete $instance) /** * @Given /the (object-instance) has following values:/ + * @Given /I change the (object-instance) values:/ + * @Given /I change the (object-instance-2) values:/ + */ + public function theObjectInstanceHasFollowingValues(Concrete $object, TableNode $table): void + { + $this->setObjectValuesFromTable($object, $table); + $object->save(); + } + + /** + * @Given /the (object-instance) has following values as version:/ */ - public function theObjectInstanceHasFollowingValues(Concrete $object, TableNode $table) + public function theObjectInstanceHasFollowingValuesAsVersion(Concrete $object, TableNode $table): void + { + $this->setObjectValuesFromTable($object, $table); + $object->saveVersion(); + } + + private function setObjectValuesFromTable(Concrete $object, TableNode $table): void { $hash = $table->getHash(); foreach ($hash as $row) { switch ($row['type']) { case 'checkbox': - $object->setValue($row['key'], filter_var($row['value'], FILTER_VALIDATE_BOOLEAN)); + $object->setValue($row['key'], filter_var($row['value'], \FILTER_VALIDATE_BOOLEAN)); break; - case 'input': $object->setValue($row['key'], $row['value']); break; - - case 'href': + case 'relation': $object->setValue($row['key'], DataObject::getById($row['value'])); break; - case 'localized': $setter = 'set' . ucfirst($row['key']); @@ -789,10 +871,12 @@ public function theObjectInstanceHasFollowingValues(Concrete $object, TableNode } break; - case 'brick': $config = json_decode(stripslashes($row['value']), true); $type = $this->classStorage->get($config['type']); + /** + * @var class-string $className + */ $className = sprintf('Pimcore\\Model\\DataObject\\Objectbrick\\Data\\%s', $type); $brickInstance = new $className($object); @@ -804,15 +888,20 @@ public function theObjectInstanceHasFollowingValues(Concrete $object, TableNode $object->{'get' . ucfirst($row['key'])}()->{'set' . ucfirst($type)}($brickInstance); break; - case 'collection': $config = json_decode(stripslashes($row['value']), true); $type = $this->classStorage->get($config['type']); + /** + * @var class-string $className + */ $className = sprintf('Pimcore\\Model\\DataObject\\Fieldcollection\\Data\\%s', $type); $items = new Fieldcollection(); foreach ($config['values'] as $itemValues) { + /** + * @var Fieldcollection\Data\AbstractData $collectionInstance + */ $collectionInstance = new $className(); foreach ($itemValues as $key => $value) { @@ -825,38 +914,25 @@ public function theObjectInstanceHasFollowingValues(Concrete $object, TableNode $object->{'set' . ucfirst($row['key'])}($items); break; - default: throw new \InvalidArgumentException(sprintf('Type %s not yet supported', $row['type'])); - - break; } } - - $object->save(); } - /** - * @param string $definition - * @param string $fieldDefinition - * - * @throws ClassDefinitionNotFoundException - */ - private function addFieldDefinitionToDefinition($definition, $fieldDefinition) - { + private function addFieldDefinitionToDefinition( + ClassDefinition|Objectbrick\Definition|Fieldcollection\Definition $definition, + string $fieldDefinition, + ): void { $definitionUpdater = $this->getUpdater($definition); - $definitionUpdater->insertField(json_decode(stripslashes($fieldDefinition), true)); + $definitionUpdater->insertField(json_decode(stripslashes($fieldDefinition), true, 512, \JSON_THROW_ON_ERROR)); $definitionUpdater->save(); } /** - * @param string $definition - * - * @return BrickDefinitionUpdate|ClassUpdate|FieldCollectionDefinitionUpdate - * - * @throws ClassDefinitionNotFoundException + * @psalm-suppress RedundantCondition */ - private function getUpdater($definition) + private function getUpdater(ClassDefinition|Objectbrick\Definition|Fieldcollection\Definition $definition): ClassUpdateInterface { $definitionUpdater = null; @@ -866,12 +942,10 @@ private function getUpdater($definition) $definitionUpdater = new BrickDefinitionUpdate($definition->getKey()); } elseif ($definition instanceof Fieldcollection\Definition) { $definitionUpdater = new FieldCollectionDefinitionUpdate($definition->getKey()); - } else { - throw new \InvalidArgumentException(sprintf('Definition Updater for %s not found', null !== $definition ? get_class($definition) : 'null')); } if (!$definitionUpdater instanceof ClassUpdateInterface) { - throw new \InvalidArgumentException(sprintf('Definition Updater for %s not found', null !== $definition ? get_class($definition) : 'null')); + throw new \InvalidArgumentException(sprintf('Definition Updater for %s not found', $definition::class)); } return $definitionUpdater; diff --git a/tests/DataDefinitionsBundle/Behat/Context/Transform/ImportDefinitionContext.php b/tests/DataDefinitionsBundle/Behat/Context/Transform/ImportDefinitionContext.php index 905b990e..3749e33c 100644 --- a/tests/DataDefinitionsBundle/Behat/Context/Transform/ImportDefinitionContext.php +++ b/tests/DataDefinitionsBundle/Behat/Context/Transform/ImportDefinitionContext.php @@ -21,21 +21,16 @@ final class ImportDefinitionContext implements Context { - private $sharedStorage; - private $definitionRepository; - public function __construct( - SharedStorageInterface $sharedStorage, - PimcoreDaoRepositoryInterface $definitionRepository + private readonly SharedStorageInterface $sharedStorage, + private readonly PimcoreDaoRepositoryInterface $definitionRepository ) { - $this->sharedStorage = $sharedStorage; - $this->definitionRepository = $definitionRepository; } /** * @Transform /^import-definition "([^"]+)"$/ */ - public function definitionWithName($name) + public function definitionWithName(string $name): DataDefinitionInterface { $all = $this->definitionRepository->findAll(); @@ -55,7 +50,7 @@ public function definitionWithName($name) * @Transform /^import-definition$/ * @Transform /^import-definitions$/ */ - public function definition() + public function definition(): ?DataDefinitionInterface { return $this->sharedStorage->get('import-definition'); } diff --git a/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreAssetContext.php b/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreAssetContext.php index c12864a0..487662ca 100644 --- a/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreAssetContext.php +++ b/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreAssetContext.php @@ -20,18 +20,16 @@ final class PimcoreAssetContext implements Context { - private $sharedStorage; - public function __construct( - SharedStorageInterface $sharedStorage + private readonly SharedStorageInterface $sharedStorage ) { - $this->sharedStorage = $sharedStorage; + } /** * @Transform /^asset "([^"]+)"$/ */ - public function objectInstanceWithKey($path) + public function objectInstanceWithKey(string $path): Asset { return Asset::getByPath($path); } diff --git a/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreClassContext.php b/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreClassContext.php index ebf5e9a1..48aa50b8 100644 --- a/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreClassContext.php +++ b/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreClassContext.php @@ -26,21 +26,16 @@ final class PimcoreClassContext implements Context { - private $sharedStorage; - private $classStorage; - public function __construct( - SharedStorageInterface $sharedStorage, - ClassStorageInterface $classStorage + private readonly SharedStorageInterface $sharedStorage, + private readonly ClassStorageInterface $classStorage ) { - $this->sharedStorage = $sharedStorage; - $this->classStorage = $classStorage; } /** * @Transform /^class "([^"]+)"$/ */ - public function class($name) + public function class(string $name): ClassDefinition { RuntimeCache::clear(); @@ -56,7 +51,7 @@ public function class($name) /** * @Transform /^field-collection "([^"]+)"$/ */ - public function fieldCollection($name) + public function fieldCollection(string $name): Definition { $name = $this->classStorage->get($name); @@ -70,7 +65,7 @@ public function fieldCollection($name) /** * @Transform /^object-instance$/ */ - public function objectInstance() + public function objectInstance(): Concrete { return $this->sharedStorage->get('object-instance'); } @@ -78,7 +73,7 @@ public function objectInstance() /** * @Transform /^object-instance "([^"]+)"$/ */ - public function objectInstanceWithKey($key) + public function objectInstanceWithKey(string $key): Concrete { return Concrete::getByPath('/'.$key); } @@ -86,10 +81,13 @@ public function objectInstanceWithKey($key) /** * @Transform /^object of the definition$/ */ - public function objectOfTheDefinition() + public function objectOfTheDefinition(): Concrete { $definition = $this->definition(); + /** + * @var class-string $fqcn + */ $fqcn = 'Pimcore\Model\DataObject\\'.ucfirst($definition->getName()); /** @@ -106,7 +104,7 @@ public function objectOfTheDefinition() /** * @Transform /^object of class "([^"]+)"$/ */ - public function objectOfTheClass($name) + public function objectOfTheClass(string $name): Concrete { $definition = $this->class($name); @@ -127,7 +125,7 @@ public function objectOfTheClass($name) * @Transform /^definition/ * @Transform /^definitions/ */ - public function definition() + public function definition(): ClassDefinition { RuntimeCache::clear(); diff --git a/tests/DataDefinitionsBundle/Behat/Service/ClassStorage.php b/tests/DataDefinitionsBundle/Behat/Service/ClassStorage.php index 5e3a0f17..56ecf36f 100644 --- a/tests/DataDefinitionsBundle/Behat/Service/ClassStorage.php +++ b/tests/DataDefinitionsBundle/Behat/Service/ClassStorage.php @@ -14,7 +14,7 @@ class ClassStorage implements ClassStorageInterface { - private $storage = []; + private array $storage = []; public function get(string $className): string { @@ -42,3 +42,4 @@ private function getBehatClassName(string $className): string return sprintf('Behat%s%s', $className, uniqid()); } } + diff --git a/tests/DataDefinitionsBundle/Behat/Service/SharedStorage.php b/tests/DataDefinitionsBundle/Behat/Service/SharedStorage.php index b3f7c94c..f9bdc69e 100644 --- a/tests/DataDefinitionsBundle/Behat/Service/SharedStorage.php +++ b/tests/DataDefinitionsBundle/Behat/Service/SharedStorage.php @@ -14,10 +14,11 @@ class SharedStorage implements SharedStorageInterface { - private $clipboard = []; - private $latestKey; + private array $clipboard = []; - public function get(string $key) + private ?string $latestKey = null; + + public function get(string $key): mixed { if (!isset($this->clipboard[$key])) { throw new \InvalidArgumentException(sprintf('There is no current resource for "%s"!', $key)); @@ -31,13 +32,13 @@ public function has(string $key): bool return isset($this->clipboard[$key]); } - public function set(string $key, $resource): void + public function set(string $key, mixed $resource): void { $this->clipboard[$key] = $resource; $this->latestKey = $key; } - public function getLatestResource() + public function getLatestResource(): mixed { if (!isset($this->clipboard[$this->latestKey])) { throw new \InvalidArgumentException(sprintf('There is no "%s" latest resource!', $this->latestKey));