Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed Jul 18, 2024
1 parent dd0142b commit 94e105c
Show file tree
Hide file tree
Showing 12 changed files with 304 additions and 244 deletions.
23 changes: 19 additions & 4 deletions behat-bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

if (!defined('PIMCORE_PROJECT_ROOT')) {
define(
Expand All @@ -9,11 +19,16 @@
);
}

define('PIMCORE_TEST', true);

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

require_once __DIR__ .'/src/BehatKernel.php';

\Pimcore\Bootstrap::setProjectRoot();
\Pimcore\Bootstrap::bootstrap();
if (file_exists(PIMCORE_PROJECT_ROOT.'/pimcore/config/bootstrap.php')) {
require_once PIMCORE_PROJECT_ROOT.'/pimcore/config/bootstrap.php';
}
else {
\Pimcore\Bootstrap::setProjectRoot();
\Pimcore\Bootstrap::bootstrap();
}
5 changes: 5 additions & 0 deletions config/preload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php';
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

final class PimcoreContext implements Context
{
private $sharedStorage;

public function __construct(SharedStorageInterface $sharedStorage)
public function __construct(
private readonly SharedStorageInterface $sharedStorage
)
{
$this->sharedStorage = $sharedStorage;

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,24 @@

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;
}

/**
* @Given /^there is a import-definition "([^"]+)"$/
* @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
Expand All @@ -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) {
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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();

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand All @@ -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 = [];

Expand All @@ -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 = [];

Expand All @@ -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');

Expand All @@ -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);

Expand Down
Loading

0 comments on commit 94e105c

Please sign in to comment.