diff --git a/Build/Scripts/runTests.sh b/Build/Scripts/runTests.sh index 3fa78539..00b5a925 100755 --- a/Build/Scripts/runTests.sh +++ b/Build/Scripts/runTests.sh @@ -202,13 +202,12 @@ Options: - 15 maintained until 2027-11-11 - 16 maintained until 2028-11-09 - -p <7.4|8.0|8.1|8.2|8.3> + -p <8.1|8.2|8.3|8.4> Specifies the PHP minor version to be used - - 7.4: (default) use PHP 7.4 - - 8.0: use PHP 8.0 - - 8.1: use PHP 8.1 + - 8.1: (default) use PHP 8.1 - 8.2: use PHP 8.2 - 8.3: use PHP 8.3 + - 8.4: use PHP 8.4 -x Only with -s functional|unit @@ -256,7 +255,7 @@ TEST_SUITE="cgl" DATABASE_DRIVER="" DBMS="mysql" DBMS_VERSION="" -PHP_VERSION="7.4" +PHP_VERSION="8.1" PHP_XDEBUG_ON=0 PHP_XDEBUG_PORT=9003 CGLCHECK_DRY_RUN=0 @@ -293,7 +292,7 @@ while getopts "a:b:d:i:s:p:xy:nhu" OPT; do ;; p) PHP_VERSION=${OPTARG} - if ! [[ ${PHP_VERSION} =~ ^(7.4|8.0|8.1|8.2|8.3)$ ]]; then + if ! [[ ${PHP_VERSION} =~ ^(8.1|8.2|8.3|8.4)$ ]]; then INVALID_OPTIONS+=("p ${OPTARG}") fi ;; @@ -475,7 +474,7 @@ case ${TEST_SUITE} in ;; functional) CONTAINER_PARAMS="" - COMMAND=(.Build/bin/phpunit -c .Build/bin/phpunit -c .Build/vendor/nimut/testing-framework/res/Configuration/FunctionalTests.xml Tests/Functional/ --exclude-group not-${DBMS} ${EXTRA_TEST_OPTIONS} "$@") + COMMAND=(.Build/bin/phpunit -c .Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTests.xml Tests/Functional/ --exclude-group not-${DBMS} ${EXTRA_TEST_OPTIONS} "$@") case ${DBMS} in mariadb) echo "Using driver: ${DATABASE_DRIVER}" @@ -546,7 +545,7 @@ case ${TEST_SUITE} in SUITE_EXIT_CODE=$? ;; unit) - COMMAND=(.Build/bin/phpunit -c .Build/vendor/nimut/testing-framework/res/Configuration/UnitTests.xml Tests/Unit ${EXTRA_TEST_OPTIONS} "$@") + COMMAND=(.Build/bin/phpunit -c .Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTests.xml Tests/Unit ${EXTRA_TEST_OPTIONS} "$@") ${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name unit-${SUFFIX} ${XDEBUG_MODE} -e XDEBUG_CONFIG="${XDEBUG_CONFIG}" ${IMAGE_PHP} "${COMMAND[@]}" SUITE_EXIT_CODE=$? ;; diff --git a/Build/phpstan/phpstan.neon b/Build/phpstan/phpstan.neon index f9f8dfab..a946349b 100644 --- a/Build/phpstan/phpstan.neon +++ b/Build/phpstan/phpstan.neon @@ -14,7 +14,3 @@ parameters: excludePaths: - '../../ext_emconf.php' - # Todo: Drop exclude after dropping v11 support - - '../../Classes/Reaction' - - '../../Classes/Message' - diff --git a/Build/rector/rector.php b/Build/rector/rector.php index 67581868..46f617b4 100644 --- a/Build/rector/rector.php +++ b/Build/rector/rector.php @@ -30,11 +30,11 @@ __DIR__ . '/../../Configuration', __DIR__ . '/../../*.php', ]) - ->withPhpSets(php74: true) + ->withPhpSets(php81: true) ->withSets([ Typo3SetList::CODE_QUALITY, Typo3SetList::GENERAL, - Typo3LevelSetList::UP_TO_TYPO3_11, + Typo3LevelSetList::UP_TO_TYPO3_12, ]) ->withImportNames(importShortClasses: false, removeUnusedImports: true) // To have a better analysis from PHPStan, we teach it here some more things @@ -46,7 +46,7 @@ ConvertImplicitVariablesToExplicitGlobalsRector::class, ]) ->withConfiguredRule(ExtEmConfRector::class, [ - ExtEmConfRector::TYPO3_VERSION_CONSTRAINT => '11.5.0-12.4.99', + ExtEmConfRector::TYPO3_VERSION_CONSTRAINT => '12.4.0-13.4.99', ExtEmConfRector::ADDITIONAL_VALUES_TO_BE_REMOVED => [], ]) // If you use importNames(), you should consider excluding some TYPO3 files. diff --git a/ChangeLog b/ChangeLog index aec36ccf..9343a7b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2025-01-20 Francois Suter (Idéative) + + * Migrate all tests to typo3/testing-framework, resolves #359 + 2025-01-10 Francois Suter (Idéative) * Update datatables, drop RequireJS, use Luxon instead of Moment, resolves #358 diff --git a/Classes/Testing/FunctionalTestCaseWithDatabaseTools.php b/Classes/Testing/FunctionalTestCaseWithDatabaseTools.php new file mode 100644 index 00000000..2713063e --- /dev/null +++ b/Classes/Testing/FunctionalTestCaseWithDatabaseTools.php @@ -0,0 +1,65 @@ +importCSVDataSet(__DIR__ . '/../../Tests/Functional/Fixtures/BackendUser.csv'); + $userRow = $this->getBackendUserRecordFromDatabase(1); + $backendUser = GeneralUtility::makeInstance(BackendUserAuthentication::class); + $request = new ServerRequest('https://www.example.com/', null, 'php://input', [], ['HTTPS' => 'ON']); + $session = $backendUser->createUserSession($userRow); + $request = $request->withCookieParams(['be_typo_user' => $session->getJwt()]); + $request = $request->withAttribute('normalizedParams', NormalizedParams::createFromRequest($request)); + $request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE); + $GLOBALS['TYPO3_REQUEST'] = $request; + $GLOBALS['BE_USER'] = $this->authenticateBackendUser($backendUser, $request); + } + + /** + * @throws \Doctrine\DBAL\Exception + */ + protected function selectCount(string $field, string $table, ?string $condition = '', bool $includeHiddenRecords = false): int + { + $queryBuilder = $this->getConnectionPool()->getQueryBuilderForTable($table); + if ($includeHiddenRecords) { + $queryBuilder->getRestrictions()->removeByType(\TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction::class); + } + $queryBuilder->count($field) + ->from($table); + if (!empty($condition)) { + $queryBuilder->where($condition); + } + $result = $queryBuilder->executeQuery(); + return (int)$result->fetchOne(); + } +} diff --git a/Makefile b/Makefile index 85326b71..dfc5ff4c 100644 --- a/Makefile +++ b/Makefile @@ -30,27 +30,27 @@ fix: fix-cgl## Run all fixes test-cgl: ## Fix PHP coding styles Build/Scripts/runTests.sh -s cgl -.PHONY: test-unit-7-4 -test-unit-7-4: ## Run unit tests with PHP 7.4 (lowest) - Build/Scripts/runTests.sh -s unit -p 7.4 +.PHONY: test-unit-8-1 +test-unit-8-1: ## Run unit tests with PHP 8.1 (lowest) + Build/Scripts/runTests.sh -s unit -p 8.1 -.PHONY: test-unit-8-3 -test-unit-8-3: ## Run unit tests with PHP 8.3 (highest supported by TYPO3 11) - Build/Scripts/runTests.sh -s unit -p 8.3 +.PHONY: test-unit-8-4 +test-unit-8-4: ## Run unit tests with PHP 8.4 (highest supported by TYPO3 13) + Build/Scripts/runTests.sh -s unit -p 8.4 .PHONY: test-unit -test-unit: test-unit-7-4 test-unit-8-3## Run unit tests with PHP 7.4 and 8.3 +test-unit: test-unit-8-1 test-unit-8-4## Run unit tests with PHP 8.1 and 8.4 -.PHONY: test-functional-7-4 -test-functional-7-4: ## Run functional tests with PHP 7.4 and mariadb (lowest) - Build/Scripts/runTests.sh -s functional -p 7.4 -d mysql +.PHONY: test-functional-8-1 +test-functional-8-1: ## Run functional tests with PHP 8.1 and mariadb (lowest) + Build/Scripts/runTests.sh -s functional -p 8.1 -d mysql -.PHONY: test-functional-8-3 -test-functional-8-3: ## Run functional tests with PHP 8.3 and mariadb (highest supported by TYPO3 11) - Build/Scripts/runTests.sh -s functional -p 8.3 -d mysql +.PHONY: test-functional-8-4 +test-functional-8-4: ## Run functional tests with PHP 8.4 and mariadb (highest supported by TYPO3 13) + Build/Scripts/runTests.sh -s functional -p 8.4 -d mysql .PHONY: test-functional -test-functional: test-functional-7-4 test-functional-8-3## Run functional tests with PHP 7.4 and 8.3 +test-functional: test-functional-8-1 test-functional-8-4## Run functional tests with PHP 8.1 and 8.4 .PHONY: phpstan phpstan: ## Run phpstan tests diff --git a/Tests/Functional/Domain/Repository/ConfigurationRepositoryTest.php b/Tests/Functional/Domain/Repository/ConfigurationRepositoryTest.php index 81e60e4e..8c82909f 100644 --- a/Tests/Functional/Domain/Repository/ConfigurationRepositoryTest.php +++ b/Tests/Functional/Domain/Repository/ConfigurationRepositoryTest.php @@ -19,43 +19,39 @@ use Cobweb\ExternalImport\Domain\Model\Configuration; use Cobweb\ExternalImport\Domain\Repository\ConfigurationRepository; +use Cobweb\ExternalImport\Testing\FunctionalTestCaseWithDatabaseTools; use Cobweb\ExternalimportTest\UserFunction\Transformation; -use Nimut\TestingFramework\TestCase\FunctionalTestCase; -use TYPO3\CMS\Core\Localization\LanguageService; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; +use TYPO3\CMS\Core\Core\Bootstrap; use TYPO3\CMS\Core\Utility\GeneralUtility; /** * Test suite for the ConfigurationRepository class. */ -class ConfigurationRepositoryTest extends FunctionalTestCase +class ConfigurationRepositoryTest extends FunctionalTestCaseWithDatabaseTools { - protected $coreExtensionsToLoad = [ + protected array $coreExtensionsToLoad = [ 'scheduler', ]; - protected $testExtensionsToLoad = [ - 'typo3conf/ext/svconnector', - 'typo3conf/ext/external_import', - 'typo3conf/ext/externalimport_test', + protected array $testExtensionsToLoad = [ + 'cobweb/svconnector', + 'cobweb/svconnector_csv', + 'cobweb/svconnector_feed', + 'cobweb/svconnector_json', + 'cobweb/external_import', + 'cobweb/externalimport_test', ]; - /** - * @var ConfigurationRepository - */ - protected $subject; - - public function __sleep() - { - return []; - } + protected ConfigurationRepository $subject; public function setUp(): void { parent::setUp(); try { - $this->setUpBackendUserFromFixture(1); - // Configuration repository needs a global LanguageService object - $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageService::class); + $this->initializeBackendUser(); + Bootstrap::initializeLanguageObject(); $this->subject = GeneralUtility::makeInstance(ConfigurationRepository::class); } catch (\Exception $e) { @@ -69,9 +65,7 @@ public function setUp(): void } } - /** - * @test - */ + #[Test] public function findByGroupFindsDesignatedGroup(): void { $groups = $this->subject->findByGroup('Products'); @@ -81,23 +75,7 @@ public function findByGroupFindsDesignatedGroup(): void ); } - public function syncFlagProvider(): array - { - return [ - 'sync is true' => [ - true, - 16, - ], - 'sync is false' => [ - false, - 1, - ], - ]; - } - - /** - * @test - */ + #[Test] public function findAllGroupsReturnsListOfGroups(): void { self::assertSame( @@ -108,12 +86,21 @@ public function findAllGroupsReturnsListOfGroups(): void ); } - /** - * @param bool $sync - * @param int $expectedCount - * @test - * @dataProvider syncFlagProvider - */ + public static function syncFlagProvider(): array + { + return [ + 'sync is true' => [ + 'sync' => true, + 'expectedCount' => 16, + ], + 'sync is false' => [ + 'sync' => false, + 'expectedCount' => 1, + ], + ]; + } + + #[Test] #[DataProvider('syncFlagProvider')] public function findBySyncFindsCorrectCountOfConfigurations(bool $sync, int $expectedCount): void { // TODO: this is not very satisfying, because the default user provided by the backend user fixture is admin @@ -123,15 +110,15 @@ public function findBySyncFindsCorrectCountOfConfigurations(bool $sync, int $exp ); } - public function findConfigurationProvider(): array + public static function findConfigurationProvider(): array { return [ 'simple configuration' => [ 'table' => 'tx_externalimporttest_bundle', 'index' => 0, - 'referenceUid' => 'bundle_code', - 'testedProperty' => 'bundle_code', - 'columnConfiguration' => [ + 'expectedReferenceUidValue' => 'bundle_code', + 'testColumnName' => 'bundle_code', + 'expectedColumnConfiguration' => [ 'field' => 'code', 'transformations' => [ 10 => [ @@ -139,7 +126,7 @@ public function findConfigurationProvider(): array ], ], ], - 'additionalFields' => [ + 'expectedAdditionalFieldsConfiguration' => [ 'position' => [ 'field' => 'position', 'transformations' => [ @@ -157,23 +144,23 @@ public function findConfigurationProvider(): array 'configuration with useColumnIndex and no specific configuration' => [ 'table' => 'tx_externalimporttest_product', 'index' => 'stable', - 'referenceUid' => 'sku', - 'testedProperty' => 'sku', + 'expectedReferenceUidValue' => 'sku', + 'testColumnName' => 'sku', // NOTE: this is expected to match information from the "base" configuration, // since the "stable" configuration has the useColumnIndex property pointing to "base" configuration - 'columnConfiguration' => [ + 'expectedColumnConfiguration' => [ 'xpath' => './self::*[@type="current"]/item', 'attribute' => 'sku', ], - 'additionalFields' => [], + 'expectedAdditionalFieldsConfiguration' => [], ], 'configuration with useColumnIndex but specific configuration' => [ 'table' => 'tx_externalimporttest_product', 'index' => 'stable', - 'referenceUid' => 'sku', - 'testedProperty' => 'name', + 'expectedReferenceUidValue' => 'sku', + 'testColumnName' => 'name', // NOTE: in this case the "name" column has its own configuration, despite the use of useColumnIndex - 'columnConfiguration' => [ + 'expectedColumnConfiguration' => [ 'xpath' => './self::*[@type="current"]/item', 'transformations' => [ 10 => [ @@ -187,25 +174,17 @@ public function findConfigurationProvider(): array ], ], ], - 'additionalFields' => [], + 'expectedAdditionalFieldsConfiguration' => [], ], ]; } - /** - * @test - * @dataProvider findConfigurationProvider - * @param string $table - * @param mixed $index - * @param string $expectedReferenceUdiValue - * @param array $expectedColumnConfiguration - * @param array $expectedAdditionalFieldsConfiguration - */ + #[Test] #[DataProvider('findConfigurationProvider')] public function findConfigurationObjectReturnsExpectedConfiguration( string $table, - $index, - string $expectedReferenceUdiValue, - $testColumnName, + mixed $index, + string $expectedReferenceUidValue, + string $testColumnName, array $expectedColumnConfiguration, array $expectedAdditionalFieldsConfiguration ): void { @@ -214,7 +193,7 @@ public function findConfigurationObjectReturnsExpectedConfiguration( $index ); self::assertSame( - $expectedReferenceUdiValue, + $expectedReferenceUidValue, $configuration->getGeneralConfigurationProperty('referenceUid') ); self::assertSame( @@ -227,9 +206,7 @@ public function findConfigurationObjectReturnsExpectedConfiguration( ); } - /** - * @test - */ + #[Test] public function findGlobalWriteAccessReturnsAll(): void { // TODO: this is not very satisfying, because the default user provided by the backend user fixture is admin @@ -239,9 +216,7 @@ public function findGlobalWriteAccessReturnsAll(): void ); } - /** - * @test - */ + #[Test] public function findOrderedConfigurationsReturnsFullOrderedList(): void { $expectedList = [ @@ -298,9 +273,7 @@ public function findOrderedConfigurationsReturnsFullOrderedList(): void ); } - /** - * @test - */ + #[Test] public function findByTableAndIndexReturnsExternalConfiguration(): void { $externalConfiguration = $this->subject->findByTableAndIndex( @@ -385,9 +358,7 @@ public function findByTableAndIndexReturnsExternalConfiguration(): void ); } - /** - * @test - */ + #[Test] public function findByTableAndIndexWithWrongInformationThrowsException(): void { $this->expectException(\Cobweb\ExternalImport\Exception\NoConfigurationException::class); diff --git a/Tests/Functional/Domain/Repository/LogRepositoryTest.php b/Tests/Functional/Domain/Repository/LogRepositoryTest.php index 0db242d3..dac55792 100644 --- a/Tests/Functional/Domain/Repository/LogRepositoryTest.php +++ b/Tests/Functional/Domain/Repository/LogRepositoryTest.php @@ -19,36 +19,35 @@ use Cobweb\ExternalImport\Domain\Model\Dto\QueryParameters; use Cobweb\ExternalImport\Domain\Repository\LogRepository; -use Nimut\TestingFramework\TestCase\FunctionalTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; /** * Test case for the LogRepository class. */ class LogRepositoryTest extends FunctionalTestCase { - protected $testExtensionsToLoad = [ - 'typo3conf/ext/svconnector', - 'typo3conf/ext/external_import', + protected array $coreExtensionsToLoad = [ + 'scheduler', ]; - /** - * @var LogRepository - */ - protected $subject; + protected array $testExtensionsToLoad = [ + 'cobweb/svconnector', + 'cobweb/external_import', + ]; - /** - * @var QueryParameters - */ - protected $queryParameters; + protected LogRepository $subject; + protected QueryParameters $queryParameters; public function setUp(): void { parent::setUp(); try { - $this->subject = GeneralUtility::makeInstance(LogRepository::class); - $this->queryParameters = GeneralUtility::makeInstance(QueryParameters::class); - $this->importDataSet(__DIR__ . '/../../Fixtures/Logs.xml'); + $this->subject = new LogRepository(); + $this->queryParameters = new QueryParameters(); + $this->importCSVDataSet(__DIR__ . '/../../Fixtures/Logs.csv'); } catch (\Exception $e) { self::markTestSkipped( sprintf( @@ -60,7 +59,7 @@ public function setUp(): void } } - public function queryDataProvider(): array + public static function queryDataProvider(): array { $searchColumns = [ 0 => [ @@ -88,18 +87,18 @@ public function queryDataProvider(): array ]; return [ 'No search, no limit' => [ - [ + 'parameters' => [ 'search' => [ 'value' => '', ], 'columns' => $searchColumns, 'order' => $order, ], - 4, - 4, + 'fullCount' => 4, + 'filteredCount' => 4, ], 'No search, limit 2' => [ - [ + 'parameters' => [ 'search' => [ 'value' => '', ], @@ -107,31 +106,27 @@ public function queryDataProvider(): array 'length' => 2, 'order' => $order, ], - 4, - 2, + 'fullCount' => 4, + 'filteredCount' => 2, ], 'Search for "cli"' => [ - [ + 'parameters' => [ 'search' => [ 'value' => 'cli', ], 'columns' => $searchColumns, 'order' => $order, ], - 3, - 3, + 'fullCount' => 3, + 'filteredCount' => 3, ], ]; } /** - * @test - * @dataProvider queryDataProvider - * @param array $parameters - * @param int $fullCount The total number of records - * @param int $filteredCount The filtered number of records - * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException + * @throws \Doctrine\DBAL\Driver\Exception */ + #[Test] #[DataProvider('queryDataProvider')] public function countBySearchReturnsExpectedNumberOfRecords( array $parameters, int $fullCount, @@ -147,28 +142,22 @@ public function countBySearchReturnsExpectedNumberOfRecords( } /** - * @test - * @dataProvider queryDataProvider - * @param array $parameters - * @param int $fullCount The total number of records - * @param int $filteredCount The filtered number of records - * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException + * @throws \Doctrine\DBAL\Exception */ + #[Test] #[DataProvider('queryDataProvider')] public function findBySearchReturnsExpectedRecords(array $parameters, int $fullCount, int $filteredCount): void { $this->queryParameters->setAllParameters($parameters); $records = $this->subject->findBySearch($this->queryParameters); - self::assertEquals( + self::assertCount( $filteredCount, - $records->count() + $records ); // To go one step further, test ordering (which should be by descending creation date) // by accessing the first record and checking the creation timestamp - /** @var \Cobweb\ExternalImport\Domain\Model\Log $firstRecord */ - $firstRecord = $records->getFirst(); self::assertEquals( 1529789282, - $firstRecord->getCrdate()->getTimestamp() + $records[0]['crdate'] ); } } diff --git a/Tests/Functional/Domain/Repository/SchedulerRepositoryTest.php b/Tests/Functional/Domain/Repository/SchedulerRepositoryTest.php index cd16ce7a..88686b38 100644 --- a/Tests/Functional/Domain/Repository/SchedulerRepositoryTest.php +++ b/Tests/Functional/Domain/Repository/SchedulerRepositoryTest.php @@ -1,5 +1,7 @@ subject = GeneralUtility::makeInstance(SchedulerRepository::class); + $this->subject = new SchedulerRepository( + new SchedulerTaskRepository( + new TaskSerializer() + ), + new TaskSerializer() + ); } - /** - * @test - * @throws \Nimut\TestingFramework\Exception\Exception - */ + #[Test] public function fetchAllGroupsReturnsAllExistingGroups(): void { - $this->importDataSet(__DIR__ . '/../../Fixtures/Scheduler.xml'); + $this->importCSVDataSet(__DIR__ . '/../../Fixtures/Scheduler.csv'); $groups = $this->subject->fetchAllGroups(); self::assertSame( [ - 0 => '', - 5 => 'Group 0', - 1 => 'Group 1', - 3 => 'Group 3', + 0 => '', + 5 => 'Group 0', + 1 => 'Group 1', + 3 => 'Group 3', ], $groups ); diff --git a/Tests/Functional/Domain/Repository/UidRepositoryTest.php b/Tests/Functional/Domain/Repository/UidRepositoryTest.php index cea30913..77237b24 100644 --- a/Tests/Functional/Domain/Repository/UidRepositoryTest.php +++ b/Tests/Functional/Domain/Repository/UidRepositoryTest.php @@ -19,109 +19,97 @@ use Cobweb\ExternalImport\Domain\Model\Configuration; use Cobweb\ExternalImport\Domain\Repository\UidRepository; -use Nimut\TestingFramework\TestCase\FunctionalTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; /** * Test class for the UidRepository */ class UidRepositoryTest extends FunctionalTestCase { - /** - * @var UidRepository - */ - protected $subject; - - public function __sleep() - { - return []; - } + protected UidRepository $subject; public function setUp(): void { parent::setUp(); - $this->subject = GeneralUtility::makeInstance(UidRepository::class); + $this->subject = new UidRepository(); } - public function configurationDataProvider(): array + public static function configurationDataProvider(): array { return [ 'No special configuration, no pid restriction' => [ - [ + 'configuration' => [ 'referenceUid' => 'tstamp', ], - [ + 'listOfUids' => [ 1520788063 => 2, 1520788087 => 3, ], - [ + 'listOfPids' => [ 1520788063 => 1, 1520788087 => 2, ], ], 'Pid restriction true' => [ - [ + 'configuration' => [ 'referenceUid' => 'tstamp', 'enforcePid' => true, ], - [ + 'listOfUids' => [ 1520788063 => 2, ], - [ + 'listOfPids' => [ 1520788063 => 1, ], ], 'Pid restriction true-ish' => [ - [ + 'configuration' => [ 'referenceUid' => 'tstamp', 'enforcePid' => 1, ], - [ + 'listOfUids' => [ 1520788063 => 2, ], - [ + 'listOfPids' => [ 1520788063 => 1, ], ], 'Pid restriction other than true' => [ - [ + 'configuration' => [ 'referenceUid' => 'tstamp', 'enforcePid' => false, ], - [ + 'listOfUids' => [ 1520788063 => 2, 1520788087 => 3, ], - [ + 'listOfPids' => [ 1520788063 => 1, 1520788087 => 2, ], ], 'Where clause' => [ - [ + 'configuration' => [ 'referenceUid' => 'tstamp', 'whereClause' => 'header like \'%deleted%\'', ], - [ + 'listOfUids' => [ 1520788087 => 3, ], - [ + 'listOfPids' => [ 1520788087 => 2, ], ], ]; } - /** - * @param array $configuration - * @param array $listOfUids - * @param array $listOfPids - * @test - * @dataProvider configurationDataProvider - */ + #[Test] #[DataProvider('configurationDataProvider')] public function getExistingUidsTriggersFetchingOfUidsAndPids(array $configuration, array $listOfUids, array $listOfPids): void { - $this->importDataSet(__DIR__ . '/../../Fixtures/UidRepository.xml'); + $this->importCSVDataSet(__DIR__ . '/../../Fixtures/UidRepository.csv'); $configurationObject = GeneralUtility::makeInstance(Configuration::class); $configurationObject->setTable('tt_content'); $configurationObject->setGeneralConfiguration($configuration); diff --git a/Tests/Functional/Fixtures/BackendUser.csv b/Tests/Functional/Fixtures/BackendUser.csv new file mode 100644 index 00000000..e90aef3e --- /dev/null +++ b/Tests/Functional/Fixtures/BackendUser.csv @@ -0,0 +1,3 @@ +be_users,,,, +,uid,pid,username,admin +,1,0,_cli_,1 diff --git a/Tests/Functional/Fixtures/Bundles.csv b/Tests/Functional/Fixtures/Bundles.csv new file mode 100644 index 00000000..378ad6e5 --- /dev/null +++ b/Tests/Functional/Fixtures/Bundles.csv @@ -0,0 +1,2 @@ +tx_externalimporttest_bundle,,,,,, +,1,1,PAIN02,Mad Max,Bundle of extra pain,Some random notes that will disappear anyway. diff --git a/Tests/Functional/Fixtures/Bundles.xml b/Tests/Functional/Fixtures/Bundles.xml deleted file mode 100644 index e46190d0..00000000 --- a/Tests/Functional/Fixtures/Bundles.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - 1 - 1 - PAIN02 - Mad Max - Bundle of extra pain - Some random notes that will disappear anyway. - - \ No newline at end of file diff --git a/Tests/Functional/Fixtures/Categories.csv b/Tests/Functional/Fixtures/Categories.csv new file mode 100644 index 00000000..5fd3abb4 --- /dev/null +++ b/Tests/Functional/Fixtures/Categories.csv @@ -0,0 +1,4 @@ +sys_category,,,, +,uid,pid,title,external_key +,1,0,Useful products,USEFUL +,2,0,Useless products,USELESS diff --git a/Tests/Functional/Fixtures/Categories.xml b/Tests/Functional/Fixtures/Categories.xml deleted file mode 100644 index 4569af58..00000000 --- a/Tests/Functional/Fixtures/Categories.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - 1 - 0 - Useful products - USEFUL - - - 2 - 0 - Useless products - USELESS - - \ No newline at end of file diff --git a/Tests/Functional/Fixtures/CategoriesMM.csv b/Tests/Functional/Fixtures/CategoriesMM.csv new file mode 100644 index 00000000..d217ca0b --- /dev/null +++ b/Tests/Functional/Fixtures/CategoriesMM.csv @@ -0,0 +1,6 @@ +sys_category,,,, +,uid,pid,title,external_key +,1,0,Nice products,NICE +sys_category_record_mm,,,, +,uid_local,uid_foreign,tablenames,fieldname +,1,1,tx_externalimporttest_product,categories diff --git a/Tests/Functional/Fixtures/CategoriesMM.xml b/Tests/Functional/Fixtures/CategoriesMM.xml deleted file mode 100644 index 1511e0d5..00000000 --- a/Tests/Functional/Fixtures/CategoriesMM.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - 1 - 0 - Nice products - NICE - - - 1 - 1 - tx_externalimporttest_product - categories - - \ No newline at end of file diff --git a/Tests/Functional/Fixtures/ClearCacheStepPreviewTest.csv b/Tests/Functional/Fixtures/ClearCacheStepPreviewTest.csv new file mode 100644 index 00000000..e7ad0a8a --- /dev/null +++ b/Tests/Functional/Fixtures/ClearCacheStepPreviewTest.csv @@ -0,0 +1,3 @@ +cache_pages_tags,,, +,id,identifier,tag +,2,22d0fdf207b692ac14340ee40b5677b7,pageId_1 diff --git a/Tests/Functional/Fixtures/ClearCacheStepPreviewTest.xml b/Tests/Functional/Fixtures/ClearCacheStepPreviewTest.xml deleted file mode 100644 index 9db84a04..00000000 --- a/Tests/Functional/Fixtures/ClearCacheStepPreviewTest.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - 2 - 22d0fdf207b692ac14340ee40b5677b7 - pageId_1 - - \ No newline at end of file diff --git a/Tests/Functional/Fixtures/ExtraStoragePage.csv b/Tests/Functional/Fixtures/ExtraStoragePage.csv new file mode 100644 index 00000000..e4b15ccf --- /dev/null +++ b/Tests/Functional/Fixtures/ExtraStoragePage.csv @@ -0,0 +1,3 @@ +pages,,,,, +,uid,pid,title,doktype,product_sku +,2,0,Additional import storage,254,002 diff --git a/Tests/Functional/Fixtures/ExtraStoragePage.xml b/Tests/Functional/Fixtures/ExtraStoragePage.xml deleted file mode 100644 index 629dd9d2..00000000 --- a/Tests/Functional/Fixtures/ExtraStoragePage.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - 2 - 0 - Additional import storage - 254 - - 002 - - \ No newline at end of file diff --git a/Tests/Functional/Fixtures/Logs.csv b/Tests/Functional/Fixtures/Logs.csv new file mode 100644 index 00000000..a338c4c7 --- /dev/null +++ b/Tests/Functional/Fixtures/Logs.csv @@ -0,0 +1,6 @@ +tx_externalimport_domain_model_log,,,,,,,, +,uid,pid,crdate,cruser_id,status,configuration,context,message +,1,0,1529489282,1,0,tx_foo / import foos,cli,1 new record(s) inserted +,2,0,1529589282,1,0,tx_foo / import foos,manual,2 new record(s) inserted +,3,0,1529689282,1,0,tx_foo / import foos,cli,3 new record(s) inserted +,4,0,1529789282,1,0,tx_foo / import foos,cli,4 new record(s) inserted diff --git a/Tests/Functional/Fixtures/Logs.xml b/Tests/Functional/Fixtures/Logs.xml deleted file mode 100644 index 5a3c22f6..00000000 --- a/Tests/Functional/Fixtures/Logs.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - 1 - 0 - 1529489282 - 1 - 0 - tx_foo / import foos - cli - 1 new record(s) inserted - - - 2 - 0 - 1529589282 - 1 - 0 - tx_foo / import foos - manual - 2 new record(s) inserted - - - 3 - 0 - 1529689282 - 1 - 0 - tx_foo / import foos - cli - 3 new record(s) inserted - - - 4 - 0 - 1529789282 - 1 - 0 - tx_foo / import foos - cli - 4 new record(s) inserted - - \ No newline at end of file diff --git a/Tests/Functional/Fixtures/Mappings.csv b/Tests/Functional/Fixtures/Mappings.csv new file mode 100644 index 00000000..1b4d0d6c --- /dev/null +++ b/Tests/Functional/Fixtures/Mappings.csv @@ -0,0 +1,10 @@ +pages,,, +,uid,pid,title +,1,0,Mapping storage 1 +,2,0,Mapping storage 2 +sys_category,,,,,,, +,uid,pid,deleted,hidden,title,external_key,description +,1,1,0,0,Category 1,CAT1, +,2,2,0,1,Category 2,CAT2, +,3,2,1,0,Category 3,CAT3, +,4,2,0,0,Category 4,0,Tests that 0 is an acceptable value for external_key diff --git a/Tests/Functional/Fixtures/Mappings.xml b/Tests/Functional/Fixtures/Mappings.xml deleted file mode 100644 index f6b102cd..00000000 --- a/Tests/Functional/Fixtures/Mappings.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - 1 - 0 - Mapping storage 1 - - - 2 - 0 - Mapping storage 2 - - - 1 - 1 - 0 - 0 - Category 1 - CAT1 - - - 2 - 2 - 0 - 1 - Category 2 - CAT2 - - - 3 - 2 - 1 - 0 - Category 3 - CAT3 - - - - 4 - 2 - 0 - 0 - Category 4 - 0 - - \ No newline at end of file diff --git a/Tests/Functional/Fixtures/Orders.csv b/Tests/Functional/Fixtures/Orders.csv new file mode 100644 index 00000000..e74fb052 --- /dev/null +++ b/Tests/Functional/Fixtures/Orders.csv @@ -0,0 +1,8 @@ +tx_externalimporttest_order,,,,, +,uid,pid,order_id,order_date,client_id +,1,1,000001,1596810720,Conan the Barbarian +,12,1,000005,1596810720,Attila the Hun +tx_externalimporttest_order_items,,,,, +,uid,uid_local,uid_foreign,quantity,pid +,1,1,1,2,1 +,2,1,5,4,1 diff --git a/Tests/Functional/Fixtures/Orders.xml b/Tests/Functional/Fixtures/Orders.xml deleted file mode 100644 index ada32108..00000000 --- a/Tests/Functional/Fixtures/Orders.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - 1 - 1 - 000001 - 1596810720 - Conan the Barbarian - - - - 12 - 1 - 000005 - 1596810720 - Attila the Hun - - - - 1 - 1 - 1 - 2 - 1 - - - - 2 - 1 - 5 - 4 - 1 - - \ No newline at end of file diff --git a/Tests/Functional/Fixtures/ProductsInStores.csv b/Tests/Functional/Fixtures/ProductsInStores.csv new file mode 100644 index 00000000..e308efec --- /dev/null +++ b/Tests/Functional/Fixtures/ProductsInStores.csv @@ -0,0 +1,4 @@ +tx_externalimporttest_store,,,, +,3,1,Sin City,SIN +tx_externalimporttest_store_product,,,,, +,1,1,3,1,42 diff --git a/Tests/Functional/Fixtures/ProductsInStores.xml b/Tests/Functional/Fixtures/ProductsInStores.xml deleted file mode 100644 index f5f1dc0c..00000000 --- a/Tests/Functional/Fixtures/ProductsInStores.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - 3 - 1 - Sin City - SIN - - - - 1 - 1 - 3 - 1 - 42 - - \ No newline at end of file diff --git a/Tests/Functional/Fixtures/Scheduler.csv b/Tests/Functional/Fixtures/Scheduler.csv new file mode 100644 index 00000000..692713fa --- /dev/null +++ b/Tests/Functional/Fixtures/Scheduler.csv @@ -0,0 +1,7 @@ +tx_scheduler_task_group,,,,, +,uid,pid,deleted,hidden,groupName +,1,0,0,0,Group 1 +,2,0,1,0,Group 2 +,3,0,0,0,Group 3 +,4,0,0,1,Group 4 +,5,0,0,0,Group 0 diff --git a/Tests/Functional/Fixtures/Scheduler.xml b/Tests/Functional/Fixtures/Scheduler.xml deleted file mode 100644 index 89df3b06..00000000 --- a/Tests/Functional/Fixtures/Scheduler.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - 1 - 0 - 0 - 0 - Group 1 - - - 2 - 0 - 1 - 0 - Group 2 - - - 3 - 0 - 0 - 0 - Group 3 - - - 4 - 0 - 0 - 1 - Group 4 - - - 5 - 0 - 0 - 0 - Group 0 - - \ No newline at end of file diff --git a/Tests/Functional/Fixtures/StoragePage.csv b/Tests/Functional/Fixtures/StoragePage.csv new file mode 100644 index 00000000..4752a314 --- /dev/null +++ b/Tests/Functional/Fixtures/StoragePage.csv @@ -0,0 +1,23 @@ +pages,,,, +,uid,pid,title,doktype +,1,0,External import storage,254 +sys_file_storage,,,,,,,,,, +,uid,pid,name,driver,is_default,is_browsable,is_public,is_writable,is_online,configuration +,1,0,"fileadmin/ (auto-created)","Local",1,1,1,1,1," + + + + + + fileadmin/ + + + relative + + + + + + + +" diff --git a/Tests/Functional/Fixtures/StoragePage.xml b/Tests/Functional/Fixtures/StoragePage.xml deleted file mode 100644 index c65a53e5..00000000 --- a/Tests/Functional/Fixtures/StoragePage.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - 1 - 0 - External import storage - 254 - - - 1 - 0 - fileadmin/ (auto-created) - Local - - - - - - - fileadmin/ - - - relative - - - - - - - - - ]]> - - 1 - 1 - 1 - 1 - 1 - - \ No newline at end of file diff --git a/Tests/Functional/Fixtures/StoreDataStepPreviewTest.csv b/Tests/Functional/Fixtures/StoreDataStepPreviewTest.csv new file mode 100644 index 00000000..c763a4d4 --- /dev/null +++ b/Tests/Functional/Fixtures/StoreDataStepPreviewTest.csv @@ -0,0 +1,3 @@ +tx_externalimporttest_tag,,,, +,uid,pid,code,name +,2,1,unknown,Dead record diff --git a/Tests/Functional/Fixtures/StoreDataStepPreviewTest.xml b/Tests/Functional/Fixtures/StoreDataStepPreviewTest.xml deleted file mode 100644 index e2bcf4b0..00000000 --- a/Tests/Functional/Fixtures/StoreDataStepPreviewTest.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - 2 - 1 - unknown - Dead record - - \ No newline at end of file diff --git a/Tests/Functional/Fixtures/UidRepository.csv b/Tests/Functional/Fixtures/UidRepository.csv new file mode 100644 index 00000000..72c36182 --- /dev/null +++ b/Tests/Functional/Fixtures/UidRepository.csv @@ -0,0 +1,9 @@ +pages,,, +,uid,pid,title +,1,0,Page 1 +,2,0,Page 2 +tt_content,,,,, +,uid,pid,deleted,hidden,header,tstamp +,1,1,1,0,Deleted content,1520788041 +,2,1,0,1,Hidden content,1520788063 +,3,2,0,0,Not deleted nor hidden content,1520788087 diff --git a/Tests/Functional/Fixtures/UidRepository.xml b/Tests/Functional/Fixtures/UidRepository.xml deleted file mode 100644 index 5f7b2779..00000000 --- a/Tests/Functional/Fixtures/UidRepository.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - 1 - 0 - Page 1 - - - 2 - 0 - Page 2 - - - - 1 - 1 - 1 - 0 -
Deleted content
- 1520788041 -
- - 2 - 1 - 0 - 1 -
Hidden content
- 1520788063 -
- - 3 - 2 - 0 - 0 -
Not deleted, not hidden content
- 1520788087 -
-
\ No newline at end of file diff --git a/Tests/Functional/ImporterPreviewTest.php b/Tests/Functional/ImporterPreviewTest.php index edc09b98..ceb2e7f1 100644 --- a/Tests/Functional/ImporterPreviewTest.php +++ b/Tests/Functional/ImporterPreviewTest.php @@ -1,5 +1,7 @@ setUpBackendUserFromFixture(1); - // Connector services need a global LanguageService object - $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageService::class); + $this->initializeBackendUser(); + Bootstrap::initializeLanguageObject(); $this->subject = GeneralUtility::makeInstance(Importer::class); - $this->importDataSet(__DIR__ . '/Fixtures/StoragePage.xml'); + $this->subject->setTestMode(true); + $this->importCSVDataSet(__DIR__ . '/Fixtures/StoragePage.csv'); $this->subject->setForcedStoragePid(1); } catch (\Exception $e) { self::markTestSkipped( @@ -79,9 +80,7 @@ protected function setUp(): void } } - /** - * @test - */ + #[Test] public function runPreviewWithWrongPreviewStepIssuesWarning(): void { $this->subject->setPreviewStep('foo'); @@ -91,13 +90,11 @@ public function runPreviewWithWrongPreviewStepIssuesWarning(): void ); self::assertCount( 1, - $messages[AbstractMessage::WARNING] + $messages[ContextualFeedbackSeverity::WARNING->value] ); } - /** - * @test - */ + #[Test] public function runPreviewOnCheckPermissionsStepReturnsNull(): void { $this->subject->setPreviewStep(CheckPermissionsStep::class); @@ -110,9 +107,7 @@ public function runPreviewOnCheckPermissionsStepReturnsNull(): void ); } - /** - * @test - */ + #[Test] public function runPreviewOnValidateConfigurationStepReturnsNull(): void { $this->subject->setPreviewStep(ValidateConfigurationStep::class); @@ -125,9 +120,7 @@ public function runPreviewOnValidateConfigurationStepReturnsNull(): void ); } - /** - * @test - */ + #[Test] public function runPreviewOnValidateConnectorStepReturnsNull(): void { $this->subject->setPreviewStep(ValidateConnectorStep::class); @@ -140,7 +133,7 @@ public function runPreviewOnValidateConnectorStepReturnsNull(): void ); } - public function readPreviewProvider(): array + public static function readPreviewProvider(): array { return [ 'xml-type data' => [ @@ -181,14 +174,8 @@ public function readPreviewProvider(): array ]; } - /** - * @test - * @dataProvider readPreviewProvider - * @param $table - * @param $index - * @param $result - */ - public function runPreviewOnReadDataStepReturnsRawData($table, $index, $result): void + #[Test] #[DataProvider('readPreviewProvider')] + public function runPreviewOnReadDataStepReturnsRawData(string $table, mixed $index, array|string $result): void { $this->subject->setPreviewStep(ReadDataStep::class); $messages = $this->subject->synchronize( @@ -196,7 +183,7 @@ public function runPreviewOnReadDataStepReturnsRawData($table, $index, $result): $index ); // The result variable may be pointing to a file, in which case we want to read it - if (is_string($result) && strpos($result, 'EXT:') === 0) { + if (is_string($result) && str_starts_with($result, 'EXT:')) { $result = file_get_contents( GeneralUtility::getFileAbsFileName($result) ); @@ -207,7 +194,7 @@ public function runPreviewOnReadDataStepReturnsRawData($table, $index, $result): ); } - public function handlePreviewProvider(): array + public static function handlePreviewProvider(): array { return [ 'xml-type data' => [ @@ -352,14 +339,8 @@ public function handlePreviewProvider(): array ]; } - /** - * @test - * @dataProvider handlePreviewProvider - * @param $table - * @param $index - * @param $result - */ - public function runPreviewOnHandleDataStepReturnsHandledData($table, $index, $result): void + #[Test] #[DataProvider('handlePreviewProvider')] + public function runPreviewOnHandleDataStepReturnsHandledData(string $table, mixed $index, array $result): void { $this->subject->setPreviewStep(HandleDataStep::class); $messages = $this->subject->synchronize( @@ -372,9 +353,7 @@ public function runPreviewOnHandleDataStepReturnsHandledData($table, $index, $re ); } - /** - * @test - */ + #[Test] public function runPreviewOnValidateDataStepReturnsNull(): void { $this->subject->setPreviewStep(ValidateDataStep::class); @@ -387,7 +366,7 @@ public function runPreviewOnValidateDataStepReturnsNull(): void ); } - public function transformPreviewProvider(): array + public static function transformPreviewProvider(): array { return [ 'tags' => [ @@ -463,14 +442,8 @@ public function transformPreviewProvider(): array ]; } - /** - * @test - * @dataProvider transformPreviewProvider - * @param $table - * @param $index - * @param $result - */ - public function runPreviewOnTransformDataStepReturnsTransformedData($table, $index, $result): void + #[Test] #[DataProvider('transformPreviewProvider')] + public function runPreviewOnTransformDataStepReturnsTransformedData(string $table, mixed $index, array $result): void { $this->subject->setPreviewStep(TransformDataStep::class); $messages = $this->subject->synchronize( @@ -483,14 +456,14 @@ public function runPreviewOnTransformDataStepReturnsTransformedData($table, $ind ); } - public function storePreviewProvider(): array + public static function storePreviewProvider(): array { return [ 'tags' => [ 'fixtures' => [ - __DIR__ . '/Fixtures/StoreDataStepPreviewTest.xml', + __DIR__ . '/Fixtures/StoreDataStepPreviewTest.csv', ], - 'prerequisistes' => [], + 'prerequisites' => [], 'table' => 'tx_externalimporttest_tag', 'index' => 0, 'testDatabase' => true, @@ -539,9 +512,9 @@ public function storePreviewProvider(): array ], 'tags (only delete)' => [ 'fixtures' => [ - __DIR__ . '/Fixtures/StoreDataStepPreviewTest.xml', + __DIR__ . '/Fixtures/StoreDataStepPreviewTest.csv', ], - 'prerequisistes' => [], + 'prerequisites' => [], 'table' => 'tx_externalimporttest_tag', 'index' => 'only-delete', 'testDatabase' => true, @@ -564,7 +537,7 @@ public function storePreviewProvider(): array ], 'base products (insert)' => [ 'fixtures' => [], - 'prerequisistes' => [ + 'prerequisites' => [ [ 'table' => 'tx_externalimporttest_tag', 'index' => 0, @@ -633,7 +606,7 @@ public function storePreviewProvider(): array ], 'base products (update)' => [ 'fixtures' => [], - 'prerequisistes' => [ + 'prerequisites' => [ [ 'table' => 'tx_externalimporttest_product', 'index' => 'base', @@ -703,9 +676,9 @@ public function storePreviewProvider(): array ], 'update products with move' => [ 'fixtures' => [ - __DIR__ . '/Fixtures/ExtraStoragePage.xml', + __DIR__ . '/Fixtures/ExtraStoragePage.csv', ], - 'prerequisistes' => [ + 'prerequisites' => [ [ 'table' => 'tx_externalimporttest_product', 'index' => 'base', @@ -792,7 +765,7 @@ public function storePreviewProvider(): array ], 'orders' => [ 'fixtures' => [ - __DIR__ . '/Fixtures/Orders.xml', + __DIR__ . '/Fixtures/Orders.csv', ], 'prerequisites' => [ [ @@ -901,24 +874,14 @@ public function storePreviewProvider(): array ]; } - /** - * @test - * @dataProvider storePreviewProvider - * @param array $fixtures List of fixture files to load - * @param array $prerequisites List of imports to perform before the one being actually tested - * @param $table - * @param $index - * @param bool $testDatabase TRUE to test DB insertions - * @param int $recordsCount How many records should be in the database - * @param $result - */ - public function runPreviewOnStoreDataStepReturnsStorageDataAndWritesNothingToDatabase(array $fixtures, array $prerequisites, $table, $index, bool $testDatabase, int $recordsCount, $result): void + #[Test] #[DataProvider('storePreviewProvider')] + public function runPreviewOnStoreDataStepReturnsStorageDataAndWritesNothingToDatabase(array $fixtures, array $prerequisites, string $table, mixed $index, bool $testDatabase, int $recordsCount, array $result): void { // Load designated fixture files if (count($fixtures) > 0) { foreach ($fixtures as $fixture) { try { - $this->importDataSet($fixture); + $this->importCSVDataSet($fixture); } catch (\Exception $e) { self::markTestSkipped( sprintf( @@ -943,6 +906,7 @@ public function runPreviewOnStoreDataStepReturnsStorageDataAndWritesNothingToDat // Run the actual test $this->subject->setPreviewStep(StoreDataStep::class); $this->subject->setTestMode(true); + $this->subject->getTemporaryKeyRepository()->resetForcedTemporaryKeySerial(); $messages = $this->subject->synchronize( $table, $index @@ -955,7 +919,7 @@ public function runPreviewOnStoreDataStepReturnsStorageDataAndWritesNothingToDat // Test that nothing was written to the database, i.e. the record count is unchanged // (if appropriate, not for update scenarios) if ($testDatabase) { - $countItems = $this->getDatabaseConnection()->selectCount( + $countItems = $this->selectCount( 'uid', $table ); @@ -963,7 +927,7 @@ public function runPreviewOnStoreDataStepReturnsStorageDataAndWritesNothingToDat } } - public function clearCachePreviewProvider(): array + public static function clearCachePreviewProvider(): array { return [ 'tags' => [ @@ -985,17 +949,11 @@ public function clearCachePreviewProvider(): array ]; } - /** - * @test - * @dataProvider clearCachePreviewProvider - * @param $table - * @param $index - * @param $result - */ - public function runPreviewOnClearCacheStepReturnsCacheListAndClearsNothing($table, $index, $result): void + #[Test] #[DataProvider('clearCachePreviewProvider')] + public function runPreviewOnClearCacheStepReturnsCacheListAndClearsNothing(string $table, mixed $index, array $result): void { try { - $this->importDataSet(__DIR__ . '/Fixtures/ClearCacheStepPreviewTest.xml'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/ClearCacheStepPreviewTest.csv'); } catch (\Exception $e) { self::markTestSkipped( sprintf( @@ -1016,17 +974,15 @@ public function runPreviewOnClearCacheStepReturnsCacheListAndClearsNothing($tabl $result, $this->subject->getPreviewData() ); - // The cache item created with the fixture should not be have been cleared - $countCacheItems = $this->getDatabaseConnection()->selectCount( + // The cache item created with the fixture should not have been cleared + $countCacheItems = $this->selectCount( 'id', 'cache_pages_tags' ); self::assertEquals(1, $countCacheItems); } - /** - * @test - */ + #[Test] public function runPreviewOnConnectorCallbackStepReturnsNull(): void { $this->subject->setPreviewStep(ConnectorCallbackStep::class); @@ -1038,4 +994,6 @@ public function runPreviewOnConnectorCallbackStepReturnsNull(): void $this->subject->getPreviewData() ); } + + // TODO: add ReportStep test (maybe) } diff --git a/Tests/Functional/ImporterTest.php b/Tests/Functional/ImporterTest.php index 72880a99..3e45667b 100644 --- a/Tests/Functional/ImporterTest.php +++ b/Tests/Functional/ImporterTest.php @@ -19,46 +19,43 @@ use Cobweb\ExternalImport\Importer; use Cobweb\ExternalImport\Step\StoreDataStep; -use Nimut\TestingFramework\TestCase\FunctionalTestCase; -use TYPO3\CMS\Core\Localization\LanguageService; -use TYPO3\CMS\Core\Messaging\AbstractMessage; +use Cobweb\ExternalImport\Testing\FunctionalTestCaseWithDatabaseTools; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; +use TYPO3\CMS\Core\Core\Bootstrap; use TYPO3\CMS\Core\Resource\ResourceFactory; +use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity; use TYPO3\CMS\Core\Utility\GeneralUtility; /** * Testcase for the External Import importer */ -class ImporterTest extends FunctionalTestCase +class ImporterTest extends FunctionalTestCaseWithDatabaseTools { - protected $testExtensionsToLoad = [ - 'typo3conf/ext/svconnector', - 'typo3conf/ext/svconnector_csv', - 'typo3conf/ext/svconnector_feed', - 'typo3conf/ext/svconnector_json', - 'typo3conf/ext/external_import', - 'typo3conf/ext/externalimport_test', + protected array $coreExtensionsToLoad = [ + 'scheduler', ]; - /** - * @var Importer - */ - protected $subject; + protected array $testExtensionsToLoad = [ + 'cobweb/svconnector', + 'cobweb/svconnector_csv', + 'cobweb/svconnector_feed', + 'cobweb/svconnector_json', + 'cobweb/external_import', + 'cobweb/externalimport_test', + ]; - public function __sleep(): array - { - return []; - } + protected Importer $subject; protected function setUp(): void { parent::setUp(); try { - $this->setUpBackendUserFromFixture(1); - // Connector services need a global LanguageService object - $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageService::class); + $this->initializeBackendUser(); + Bootstrap::initializeLanguageObject(); $this->subject = GeneralUtility::makeInstance(Importer::class); - $this->importDataSet(__DIR__ . '/Fixtures/StoragePage.xml'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/StoragePage.csv'); $this->subject->setForcedStoragePid(1); } catch (\Exception $e) { self::markTestSkipped( @@ -75,16 +72,15 @@ protected function setUp(): void * Imports the "tag" elements and checks whether we have the right count or not * (5 expected on a total of 6, because one is filtered away by * \Cobweb\ExternalimportTest\Service\TagsPreprocessor::preprocessRawRecordset()) - * - * @test */ + #[Test] public function importTagsWithImporterStoresFiveRecords(): void { $messages = $this->subject->synchronize( 'tx_externalimporttest_tag', 0 ); - $countRecords = $this->getDatabaseConnection()->selectCount( + $countRecords = $this->selectCount( 'uid', 'tx_externalimporttest_tag' ); @@ -99,9 +95,8 @@ public function importTagsWithImporterStoresFiveRecords(): void /** * Imports the "sys_category" elements and checks whether we have the right count or not * (3 expected) - * - * @test */ + #[Test] public function importCategoriesWithImporterStoresFourRecordsWithOneParentRelation(): void { $messages = $this->subject->synchronize( @@ -109,12 +104,12 @@ public function importCategoriesWithImporterStoresFourRecordsWithOneParentRelati 'product_categories' ); // Count imported categories - $countRecords = $this->getDatabaseConnection()->selectCount( + $countRecords = $this->selectCount( 'uid', 'sys_category' ); // Count records having a parent - $countChildren = $this->getDatabaseConnection()->selectCount( + $countChildren = $this->selectCount( 'uid', 'sys_category', 'parent > 0' @@ -128,9 +123,8 @@ public function importCategoriesWithImporterStoresFourRecordsWithOneParentRelati /** * Imports the "designers" and checks whether we have the right count or not (3 expected), * including relations to products. - * - * @test */ + #[Test] public function importDesignersWithImporterStoresThreeRecordsAndCreatesRelations(): void { $this->subject->synchronize( @@ -142,12 +136,12 @@ public function importDesignersWithImporterStoresThreeRecordsAndCreatesRelations 0 ); // Get the number of designers stored - $countDesigners = $this->getDatabaseConnection()->selectCount( + $countDesigners = $this->selectCount( 'uid', 'tx_externalimporttest_designer' ); // Count products relations - $countRelations = $this->getDatabaseConnection()->selectCount( + $countRelations = $this->selectCount( '*', 'tx_externalimporttest_product_designer_mm' ); @@ -159,9 +153,8 @@ public function importDesignersWithImporterStoresThreeRecordsAndCreatesRelations /** * Imports the "products" with the "base" configuration and checks whether we have the right count or not * (2 expected). Furthermore, relations with categories and tags are tested. - * - * @test */ + #[Test] public function importBaseProductsWithImporterStoresTwoRecordsAndCreatesRelations(): void { $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class); @@ -183,13 +176,12 @@ public function importBaseProductsWithImporterStoresTwoRecordsAndCreatesRelation 'base' ); // Get the number of products stored and their tag relations - /** @var \Doctrine\DBAL\Driver\Statement $databaseResult */ - $databaseResult = $this->getDatabaseConnection()->getDatabaseInstance() + $databaseResult = $this->getConnectionPool()->getQueryBuilderForTable('tx_externalimporttest_product') ->select('uid', 'tags') ->from('tx_externalimporttest_product') // Ensure consistent order for safe comparison ->orderBy('uid', 'ASC') - ->execute(); + ->executeQuery(); $countProducts = 0; $tagRelations = []; while ($row = $databaseResult->fetchAssociative()) { @@ -197,18 +189,18 @@ public function importBaseProductsWithImporterStoresTwoRecordsAndCreatesRelation $tagRelations[$row['uid']] = $row['tags']; } // Get the number of categories relations created - $countRelations = $this->getDatabaseConnection()->selectCount( + $countRelations = $this->selectCount( 'uid_local', 'sys_category_record_mm', 'tablenames = \'tx_externalimporttest_product\'' ); // Get the number and order of sys_file_reference records created - $databaseResult = $this->getDatabaseConnection()->getDatabaseInstance() + $databaseResult = $this->getConnectionPool()->getQueryBuilderForTable('sys_file_reference') ->select('uid', 'sorting_foreign') ->from('sys_file_reference') // Ensure consistent order for safe comparison ->orderBy('sorting_foreign', 'ASC') - ->execute(); + ->executeQuery(); $countFiles = 0; $sorting = []; while ($row = $databaseResult->fetchAssociative()) { @@ -238,9 +230,8 @@ public function importBaseProductsWithImporterStoresTwoRecordsAndCreatesRelation /** * Imports the "products" with the "more" configuration and checks whether we have the right count or not * (2 expected) - * - * @test */ + #[Test] public function importMoreProductsWithImporterStoresTwoRecords(): void { $messages = $this->subject->synchronize( @@ -248,7 +239,7 @@ public function importMoreProductsWithImporterStoresTwoRecords(): void 'more' ); // Get the number of products stored - $countProducts = $this->getDatabaseConnection()->selectCount( + $countProducts = $this->selectCount( 'uid', 'tx_externalimporttest_product' ); @@ -262,35 +253,34 @@ public function importMoreProductsWithImporterStoresTwoRecords(): void * * This test also checks that old MM relations are removed and that the useColumnIndex override has been taken * into account (product names are uppercase) - * - * @test */ + #[Test] public function importStableProductsWithImporterStoresTwoRecordsAndRemovesOldRelations(): void { // Create 1 category and 1 relation to it. The relation should be removed by the import process. - $this->importDataSet(__DIR__ . '/Fixtures/CategoriesMM.xml'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/CategoriesMM.csv'); $messages = $this->subject->synchronize( 'tx_externalimporttest_product', 'stable' ); // Get the number of products stored - $countProducts = $this->getDatabaseConnection()->selectCount( + $countProducts = $this->selectCount( 'uid', 'tx_externalimporttest_product' ); - $products = $this->getDatabaseConnection()->getDatabaseInstance() + $products = $this->getConnectionPool()->getQueryBuilderForTable('tx_externalimporttest_product') ->select('name') ->from('tx_externalimporttest_product') ->orderBy('sku', 'asc') - ->execute() + ->executeQuery() ->fetchAllAssociative(); // Get the categories relations - $relations = $this->getDatabaseConnection()->getDatabaseInstance() + $relations = $this->getConnectionPool()->getQueryBuilderForTable('sys_category_record_mm') ->select('uid_local', 'uid_foreign') ->from('sys_category_record_mm') ->where('tablenames = \'tx_externalimporttest_product\'') - ->execute() + ->executeQuery() ->fetchAllAssociative(); $countRelations = count($relations); $firstRelation = array_pop($relations); @@ -332,9 +322,8 @@ public function importStableProductsWithImporterStoresTwoRecordsAndRemovesOldRel * Imports the "products" with the "products for stores" configuration and checks whether we have * the right number of relations or not (6 expected). Also checks the "stock" which used the * "additionalFields" mechanism for MM relations. - * - * @test */ + #[Test] public function importProductsForStoresWithImporterCreatesSixRelations(): void { // First import products and stores, so that relations can be created @@ -356,12 +345,12 @@ public function importProductsForStoresWithImporterCreatesSixRelations(): void 'products_for_stores' ); // Get the number of relations created - $databaseResult = $this->getDatabaseConnection()->getDatabaseInstance() + $databaseResult = $this->getConnectionPool()->getQueryBuilderForTable('tx_externalimporttest_store_product') ->select('stock') ->from('tx_externalimporttest_store_product') // Ensure consistent order for safe comparison ->orderBy('stock', 'ASC') - ->execute(); + ->executeQuery(); $stocks = []; while ($row = $databaseResult->fetchAssociative()) { $stocks[] = $row['stock']; @@ -382,9 +371,8 @@ public function importProductsForStoresWithImporterCreatesSixRelations(): void * Imports the "bundles" and checks whether we have the right count or not * (3 expected out of 4, one does not have a referenceUid). Also checks relations between products and bundles, * including the order of the products inside the bundles. - * - * @test */ + #[Test] public function importBundlesWithImporterStoresThreeRecordsAndCreatesOrderedRelations(): void { // First import all products, so that relations can be created @@ -406,22 +394,22 @@ public function importBundlesWithImporterStoresThreeRecordsAndCreatesOrderedRela 0 ); // Get the number of bundles stored - $countBundles = $this->getDatabaseConnection()->selectCount( + $countBundles = $this->selectCount( 'uid', 'tx_externalimporttest_bundle' ); // Get the number of relations created /** @var \Doctrine\DBAL\Driver\Statement $databaseResult */ - $databaseResult = $this->getDatabaseConnection()->getDatabaseInstance() + $databaseResult = $this->getConnectionPool()->getQueryBuilderForTable('tx_externalimporttest_bundle_product_mm') ->select('uid_local', 'uid_foreign', 'sorting') ->from('tx_externalimporttest_bundle_product_mm') // Ensure consistent order for safe comparison ->orderBy('uid_local', 'ASC') ->addOrderBy('sorting', 'ASC') - ->execute(); + ->executeQuery(); $countRelations = 0; $sortedProducts = []; - while ($row = $databaseResult->fetch()) { + while ($row = $databaseResult->fetchAssociative()) { $countRelations++; $sortedProducts[] = $row['uid_foreign']; } @@ -437,13 +425,12 @@ public function importBundlesWithImporterStoresThreeRecordsAndCreatesOrderedRela /** * Imports the bundles with one bundle already existing in the database. * The notes field of that bundle are expected to be nulled. - * - * @test */ + #[Test] public function importBundlesWithImporterOnExistingBundleSetNull(): void { try { - $this->importDataSet(__DIR__ . '/Fixtures/Bundles.xml'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/Bundles.csv'); } catch (\Exception $e) { self::markTestSkipped( sprintf( @@ -457,26 +444,25 @@ public function importBundlesWithImporterOnExistingBundleSetNull(): void 'tx_externalimporttest_bundle', 0 ); - $updatedBundle = $this->getDatabaseConnection()->select( - 'notes', - 'tx_externalimporttest_bundle', - 'bundle_code = \'PAIN02\'' - ) - ->fetch(); - self::assertNull($updatedBundle['notes'], serialize($messages)); + $updatedBundle = $this->getConnectionPool()->getQueryBuilderForTable('tx_externalimporttest_bundle') + ->select('notes') + ->from('tx_externalimporttest_bundle') + ->where('bundle_code = \'PAIN02\'') + ->executeQuery() + ->fetchOne(); + self::assertNull($updatedBundle['notes'] ?? null, serialize($messages)); } /** * Imports the "orders" and checks whether we have the right count or not * (2 expected = 2 imported and 1 existing deleted). Also checks relations between products and orders, * including the "quantity" additional field. - * - * @test */ + #[Test] public function importOrdersWithImporterStoresThreeRecordsAndCreatesRelationsAndDeletesExistingOrder(): void { try { - $this->importDataSet(__DIR__ . '/Fixtures/Orders.xml'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/Orders.csv'); } catch (\Exception $e) { self::markTestSkipped( sprintf( @@ -505,21 +491,20 @@ public function importOrdersWithImporterStoresThreeRecordsAndCreatesRelationsAnd 0 ); // Get the number of orders stored - $countOrders = $this->getDatabaseConnection()->selectCount( + $countOrders = $this->selectCount( 'uid', 'tx_externalimporttest_order' ); // Get the number of relations created - /** @var \Doctrine\DBAL\Driver\Statement $databaseResult */ - $databaseResult = $this->getDatabaseConnection()->getDatabaseInstance() + $databaseResult = $this->getConnectionPool()->getQueryBuilderForTable('tx_externalimporttest_order_items') ->select('uid_local', 'quantity') ->from('tx_externalimporttest_order_items') // Ensure consistent order for safe comparison ->orderBy('uid_local', 'ASC') - ->execute(); + ->executeQuery(); $countRelations = 0; $quantities = []; - while ($row = $databaseResult->fetch()) { + while ($row = $databaseResult->fetchAssociative()) { $countRelations++; $quantities[] = $row['quantity']; } @@ -537,13 +522,12 @@ public function importOrdersWithImporterStoresThreeRecordsAndCreatesRelationsAnd * (3 expected). Also checks relations between products and stores, * including the "stock" additional field. One existing product for a given store * is expected to be deleted, because absent from the import. - * - * @test */ + #[Test] public function importStoresWithImporterStoresThreeRecordsAndCreatesRelations(): void { // Prepare one product in a store that has none in the imported data. It should get deleted. - $this->importDataSet(__DIR__ . '/Fixtures/ProductsInStores.xml'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/ProductsInStores.csv'); // First import products, so that relations can be created $this->subject->synchronize( @@ -556,17 +540,17 @@ public function importStoresWithImporterStoresThreeRecordsAndCreatesRelations(): 0 ); // Get the number of stores stored (NOTE: one already exists in the fixture) - $countStores = $this->getDatabaseConnection()->selectCount( + $countStores = $this->selectCount( 'uid', 'tx_externalimporttest_store' ); // Get the number of relations created - $databaseResult = $this->getDatabaseConnection()->getDatabaseInstance() + $databaseResult = $this->getConnectionPool()->getQueryBuilderForTable('tx_externalimporttest_store_product') ->select('stock') ->from('tx_externalimporttest_store_product') // Ensure consistent order for safe comparison ->orderBy('stock', 'ASC') - ->execute(); + ->executeQuery(); $stocks = []; while ($row = $databaseResult->fetchAssociative()) { $stocks[] = $row['stock']; @@ -590,16 +574,15 @@ public function importStoresWithImporterStoresThreeRecordsAndCreatesRelations(): /** * Imports the "invoices" elements and checks whether we have the right count or not * (3 expected). - * - * @test */ + #[Test] public function importInvoicesWithImporterStoresThreeRecords(): void { $messages = $this->subject->synchronize( 'tx_externalimporttest_invoice', 0 ); - $countRecords = $this->getDatabaseConnection()->selectCount( + $countRecords = $this->selectCount( 'uid', 'tx_externalimporttest_invoice' ); @@ -609,9 +592,8 @@ public function importInvoicesWithImporterStoresThreeRecords(): void /** * Imports the products as pages and checks whether the proper page tree has been created. - * - * @test */ + #[Test] public function importProductsAsPagesWithImporterCreatesProperPageTree(): void { $messages = $this->subject->synchronize( @@ -619,16 +601,11 @@ public function importProductsAsPagesWithImporterCreatesProperPageTree(): void 'product_pages' ); // Three new pages should be attached to the storage page - $parentPages = $this->getDatabaseConnection()->getDatabaseInstance() - ->select('uid', 'title') - ->from('pages') - ->where('pid = 1') - ->execute() - ->fetchAllAssociative(); - $countParentPages = $this->getDatabaseConnection()->selectCount( + $countParentPages = $this->selectCount( 'uid', 'pages', - 'pid = 1' + 'pid = 1', + true ); // NOTE: the serializing of the Importer messages is a quick way to debug anything gone wrong self::assertEquals(3, $countParentPages, serialize($messages)); @@ -649,10 +626,11 @@ public function importProductsAsPagesWithImporterCreatesProperPageTree(): void ], ]; foreach ($pageTree as $page) { - $children = $this->getDatabaseConnection()->selectCount( + $children = $this->selectCount( 'uid', 'pages', - 'pid IN (SELECT uid FROM pages WHERE title = \'' . $page['title'] . '\')' + 'pid IN (SELECT uid FROM pages WHERE title = \'' . $page['title'] . '\')', + true ); self::assertEquals($page['children'], $children); } @@ -660,13 +638,12 @@ public function importProductsAsPagesWithImporterCreatesProperPageTree(): void /** * Imports a product to a different page, thus moving the product. - * - * @test */ + #[Test] public function importUpdatedProductsWithImporterMovesProductsAndUpdatesSlugs(): void { try { - $this->importDataSet(__DIR__ . '/Fixtures/ExtraStoragePage.xml'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/ExtraStoragePage.csv'); } catch (\Exception $e) { self::markTestSkipped( sprintf( @@ -686,11 +663,13 @@ public function importUpdatedProductsWithImporterMovesProductsAndUpdatesSlugs(): 'tx_externalimporttest_product', 'updated_products' ); - $movedProducts = $this->getDatabaseConnection()->select( - 'name', - 'tx_externalimporttest_product', - 'pid = 2' - )->fetchAll(); + $queryBuilder = $this->getConnectionPool()->getQueryBuilderForTable('tx_externalimporttest_product'); + $queryBuilder->select('name') + ->from('tx_externalimporttest_product') + ->where( + $queryBuilder->expr()->eq('pid', 2) + ); + $movedProducts = $queryBuilder->executeQuery()->fetchAllAssociative(); // A single product should have been moved self::assertCount( 1, @@ -702,11 +681,13 @@ public function importUpdatedProductsWithImporterMovesProductsAndUpdatesSlugs(): 'Long sword (updated)', $movedProducts[0]['name'] ); - $movedProducts = $this->getDatabaseConnection()->select( - 'path_segment', - 'tx_externalimporttest_product', - 'pid = 2' - )->fetchAll(); + $queryBuilder = $this->getConnectionPool()->getQueryBuilderForTable('tx_externalimporttest_product'); + $queryBuilder->select('path_segment') + ->from('tx_externalimporttest_product') + ->where( + $queryBuilder->expr()->eq('pid', 2) + ); + $movedProducts = $queryBuilder->executeQuery()->fetchAllAssociative(); self::assertSame( 'long-sword-updated', $movedProducts[0]['path_segment'] @@ -715,31 +696,25 @@ public function importUpdatedProductsWithImporterMovesProductsAndUpdatesSlugs(): /** * Provides a list of erroneous import configurations. - * - * @return array */ - public function wrongConfigurationNames(): array + public static function wrongConfigurationNamesProvider(): array { return [ 'Wrong general configuration' => [ - 'tx_externalimporttest_product', - 'general_configuration_errors', + 'table' => 'tx_externalimporttest_product', + 'configuration' => 'general_configuration_errors', ], 'Wrong column configuration' => [ - 'sys_categories', - 'column_configuration_errors', + 'table' => 'sys_categories', + 'configuration' => 'column_configuration_errors', ], ]; } /** * Checks that running an erroneous configuration exits early with a single error message. - * - * @param string $table Name of the table to import into - * @param string $configuration Name of the configuration to check - * @test - * @dataProvider wrongConfigurationNames */ + #[Test] #[DataProvider('wrongConfigurationNamesProvider')] public function importWithErroneousConfigurationReturnsError(string $table, string $configuration): void { $messages = $this->subject->synchronize( @@ -752,7 +727,7 @@ public function importWithErroneousConfigurationReturnsError(string $table, stri // With a wrong configuration, we expect the import process to abort with a single message // of level "ERROR" // NOTE: the serializing of the Importer messages is a quick way to debug anything gone wrong - self::assertEquals(AbstractMessage::ERROR, $messageLevel, serialize($messages)); + self::assertEquals(ContextualFeedbackSeverity::ERROR->value, $messageLevel, serialize($messages)); self::assertCount(1, $messagesForLevel); } } diff --git a/Tests/Functional/Step/StoreDataStepTest.php b/Tests/Functional/Step/StoreDataStepTest.php index 8afa94f9..ad6d3677 100644 --- a/Tests/Functional/Step/StoreDataStepTest.php +++ b/Tests/Functional/Step/StoreDataStepTest.php @@ -19,12 +19,17 @@ use Cobweb\ExternalImport\Domain\Model\Configuration; use Cobweb\ExternalImport\Domain\Model\Data; +use Cobweb\ExternalImport\Domain\Model\Dto\ChildrenSorting; use Cobweb\ExternalImport\Domain\Repository\TemporaryKeyRepository; use Cobweb\ExternalImport\Domain\Repository\UidRepository; use Cobweb\ExternalImport\Importer; use Cobweb\ExternalImport\Step\StoreDataStep; -use Nimut\TestingFramework\TestCase\FunctionalTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; +use TYPO3\CMS\Core\EventDispatcher\EventDispatcher; +use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\MockEventDispatcher; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; /** * Test suite for the StoreDataStep class. @@ -33,30 +38,35 @@ */ class StoreDataStepTest extends FunctionalTestCase { - protected $testExtensionsToLoad = [ - 'typo3conf/ext/svconnector', - 'typo3conf/ext/external_import', - 'typo3conf/ext/externalimport_test', + protected array $coreExtensionsToLoad = [ + 'scheduler', ]; - /** - * @var StoreDataStep - */ - protected $subject; + protected array $testExtensionsToLoad = [ + 'cobweb/svconnector', + 'cobweb/svconnector_csv', + 'cobweb/svconnector_feed', + 'cobweb/svconnector_json', + 'cobweb/external_import', + 'cobweb/externalimport_test', + ]; - public function __sleep() - { - return []; - } + protected StoreDataStep $subject; public function setUp(): void { parent::setUp(); - $this->subject = GeneralUtility::makeInstance(StoreDataStep::class); - $this->subject->setData(GeneralUtility::makeInstance(Data::class)); + $this->subject = new StoreDataStep( + $this->getAccessibleMock( + EventDispatcher::class, + callOriginalConstructor: false + ), + new ChildrenSorting() + ); + $this->subject->setData(new Data()); } - public function dataToStoreProvider(): array + public static function dataToStoreProvider(): array { return [ 'no denormalized data' => [ @@ -436,18 +446,10 @@ public function dataToStoreProvider(): array ]; } - /** - * @test - * @dataProvider dataToStoreProvider - * @param array $generalConfiguration - * @param array $columnConfiguration - * @param array $input - * @param array $output - * @param array $existingUids - * @throws \TYPO3\CMS\Extbase\Object\Exception - */ + #[Test] #[DataProvider('dataToStoreProvider')] public function prepareDataToStoreReturnsPreparedData(array $generalConfiguration, array $columnConfiguration, array $input, array $output, array $existingUids): void { + /** @var Configuration $configuration */ $configuration = GeneralUtility::makeInstance(Configuration::class); $configuration->setGeneralConfiguration($generalConfiguration); $configuration->setColumnConfiguration($columnConfiguration); @@ -461,6 +463,7 @@ public function prepareDataToStoreReturnsPreparedData(array $generalConfiguratio $importer->method('getUidRepository')->willReturn($uidRepository); $temporaryKeyRepository = GeneralUtility::makeInstance(TemporaryKeyRepository::class); $temporaryKeyRepository->setTestMode(true); + $temporaryKeyRepository->resetForcedTemporaryKeySerial(); $importer->method('getTemporaryKeyRepository')->willReturn($temporaryKeyRepository); $this->subject->setImporter($importer); @@ -470,7 +473,7 @@ public function prepareDataToStoreReturnsPreparedData(array $generalConfiguratio ); } - public function childStructureProvider(): array + public static function childStructureProvider(): array { return [ 'orders' => [ @@ -501,20 +504,13 @@ public function childStructureProvider(): array ]; } - /** - * @test - * @dataProvider childStructureProvider - * @param array $childConfiguration - * @param mixed $parentId - * @param array $parentData - * @param array $result - * @throws \TYPO3\CMS\Extbase\Object\Exception - */ + #[Test] #[DataProvider('childStructureProvider')] public function prepareChildStructureReturnsChildData(array $childConfiguration, $parentId, array $parentData, array $result): void { $importer = $this->createMock(Importer::class); $temporaryKeyRepository = GeneralUtility::makeInstance(TemporaryKeyRepository::class); $temporaryKeyRepository->setTestMode(true); + $temporaryKeyRepository->resetForcedTemporaryKeySerial(); $importer->method('getTemporaryKeyRepository')->willReturn($temporaryKeyRepository); $importer->method('getExternalConfiguration')->willReturn( GeneralUtility::makeInstance(Configuration::class) diff --git a/Tests/Functional/Step/TransformDataStepTest.php b/Tests/Functional/Step/TransformDataStepTest.php index 3e2eab50..561416f9 100644 --- a/Tests/Functional/Step/TransformDataStepTest.php +++ b/Tests/Functional/Step/TransformDataStepTest.php @@ -21,33 +21,42 @@ use Cobweb\ExternalImport\Importer; use Cobweb\ExternalImport\Step\TransformDataStep; use Cobweb\ExternalImport\Transformation\DateTimeTransformation; -use Nimut\TestingFramework\TestCase\FunctionalTestCase; +use Cobweb\ExternalImport\Utility\MappingUtility; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Core\Localization\LanguageServiceFactory; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; /** * Test suite for the TransformDataStep class. */ class TransformDataStepTest extends FunctionalTestCase { - protected $testExtensionsToLoad = [ - 'typo3conf/ext/svconnector', - 'typo3conf/ext/external_import', - 'typo3conf/ext/externalimport_test', + protected array $coreExtensionsToLoad = [ + 'scheduler', ]; - /** - * @var TransformDataStep - */ - protected $subject; + protected array $testExtensionsToLoad = [ + 'cobweb/svconnector', + 'cobweb/svconnector_csv', + 'cobweb/svconnector_feed', + 'cobweb/svconnector_json', + 'cobweb/external_import', + 'cobweb/externalimport_test', + ]; + + protected TransformDataStep $subject; public function setUp(): void { parent::setUp(); - $this->subject = GeneralUtility::makeInstance(TransformDataStep::class); + $this->subject = new TransformDataStep(new MappingUtility()); $importer = $this->createMock(Importer::class); - $configuration = GeneralUtility::makeInstance(Configuration::class); - $configuration->setTable('foo'); +// $configuration = $this->getAccessibleMock(Configuration::class); + $configuration = $this->createMock(Configuration::class); + $configuration->method('getTable')->willReturn('foo'); +// $configuration->setTable('foo'); $importer->method('getExternalConfiguration')->willReturn($configuration); $this->subject->setImporter( $importer @@ -56,13 +65,13 @@ public function setUp(): void $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->create('en'); } - public function trimDataProvider(): array + public static function trimDataProvider(): array { return [ 'Trim data (true)' => [ - 'foo', - true, - [ + 'name' => 'foo', + 'configuration' => true, + 'records' => [ 0 => [ 'foo' => ' White space all around ', 'bar' => ' Not trimmed ', @@ -80,7 +89,7 @@ public function trimDataProvider(): array 'bar' => ' Not trimmed ', ], ], - [ + 'expected' => [ 0 => [ 'foo' => 'White space all around', 'bar' => ' Not trimmed ', @@ -100,9 +109,9 @@ public function trimDataProvider(): array ], ], 'Do not trim data (false)' => [ - 'foo', - false, - [ + 'name' => 'foo', + 'configuration' => false, + 'records' => [ 0 => [ 'foo' => ' White space all around ', 'bar' => ' Not trimmed ', @@ -112,7 +121,7 @@ public function trimDataProvider(): array 'bar' => ' Not trimmed ', ], ], - [ + 'expected' => [ 0 => [ 'foo' => ' White space all around ', 'bar' => ' Not trimmed ', @@ -124,9 +133,9 @@ public function trimDataProvider(): array ], ], 'Trim not string data' => [ - 'foo', - true, - [ + 'name' => 'foo', + 'configuration' => true, + 'records' => [ 0 => [ 'foo' => ['bar' => 'baz'], ], @@ -140,7 +149,7 @@ public function trimDataProvider(): array 'bar' => 'baz', ], ], - [ + 'expected' => [ 0 => [ 'foo' => ['bar' => 'baz'], ], @@ -158,16 +167,7 @@ public function trimDataProvider(): array ]; } - /** - * Tests the applyTrim() method. - * - * @param string $name Name of the column to transform - * @param bool $configuration True if data needs to be trimmed - * @param array $records Records to handle - * @param array $expected Expected results - * @test - * @dataProvider trimDataProvider - */ + #[Test] #[DataProvider('trimDataProvider')] public function applyTrimTrimsDataIfTrue(string $name, bool $configuration, array $records, array $expected): void { $result = $this->subject->applyTrim( @@ -178,17 +178,17 @@ public function applyTrimTrimsDataIfTrue(string $name, bool $configuration, arra self::assertSame($expected, $result); } - public function mappingDataProvider(): array + public static function mappingDataProvider(): array { return [ 'Map to sys_category with default value' => [ - 'foo', - [ + 'name' => 'foo', + 'configuration' => [ 'table' => 'sys_category', 'referenceField' => 'external_key', 'default' => 19, ], - [ + 'records' => [ 0 => [ 'foo' => 'USEFUL', 'bar' => 42, @@ -202,7 +202,7 @@ public function mappingDataProvider(): array 'bar' => 24, ], ], - [ + 'expected' => [ 0 => [ 'foo' => '1', 'bar' => 42, @@ -218,12 +218,12 @@ public function mappingDataProvider(): array ], ], 'Map to sys_category without default value' => [ - 'foo', - [ + 'name' => 'foo', + 'configuration' => [ 'table' => 'sys_category', 'referenceField' => 'external_key', ], - [ + 'records' => [ 0 => [ 'foo' => 'USEFUL', 'bar' => 42, @@ -237,7 +237,7 @@ public function mappingDataProvider(): array 'bar' => 24, ], ], - [ + 'expected' => [ 0 => [ 'foo' => '1', 'bar' => 42, @@ -254,20 +254,10 @@ public function mappingDataProvider(): array ]; } - /** - * Tests the applyMapping() method. - * - * @param string $name Name of the column to transform - * @param array $configuration Mapping configuration - * @param array $records Records to handle - * @param array $expected Expected results - * @test - * @dataProvider mappingDataProvider - * @throws \Nimut\TestingFramework\Exception\Exception - */ + #[Test] #[DataProvider('mappingDataProvider')] public function applyMappingMapsData(string $name, array $configuration, array $records, array $expected): void { - $this->importDataSet(__DIR__ . '/../Fixtures/Categories.xml'); + $this->importCSVDataSet(__DIR__ . '/../Fixtures/Categories.csv'); $result = $this->subject->applyMapping( $name, $configuration, @@ -276,11 +266,7 @@ public function applyMappingMapsData(string $name, array $configuration, array $ self::assertSame($expected, $result); } - /** - * Tests the applyValue() method. - * - * @test - */ + #[Test] public function applyValueAppliesValue(): void { $result = $this->subject->applyValue( @@ -312,11 +298,7 @@ public function applyValueAppliesValue(): void ); } - /** - * Tests the applyValue() method. - * - * @test - */ + #[Test] public function applyRteEnabledFlagAppliesFlag(): void { $result = $this->subject->applyRteEnabledFlag( @@ -350,12 +332,12 @@ public function applyRteEnabledFlagAppliesFlag(): void ); } - public function userFunctionDataProvider(): array + public static function userFunctionDataProvider(): array { return [ 'Valid configuration - data transformed' => [ - 'foo', - [ + 'name' => 'foo', + 'configuration' => [ 'class' => DateTimeTransformation::class, 'method' => 'parseDate', 'parameters' => [ @@ -363,13 +345,13 @@ public function userFunctionDataProvider(): array 'format' => 'U', ], ], - [ + 'records' => [ 0 => [ 'foo' => '2017-10-11T18:29:01+02:00', 'bar' => 4, ], ], - [ + 'expected' => [ 0 => [ 'foo' => '1507739341', 'bar' => 4, @@ -380,15 +362,9 @@ public function userFunctionDataProvider(): array } /** - * Tests the applyUserFunction() method. - * - * @param string $name Name of the column to transform - * @param array $configuration userFunction configuration - * @param array $records Records to handle - * @param array $expected Expected results - * @test - * @dataProvider userFunctionDataProvider + * @throws \Cobweb\ExternalImport\Exception\CriticalFailureException */ + #[Test] #[DataProvider('userFunctionDataProvider')] public function applyUserFunctionTransformsDataIfValid(string $name, array $configuration, array $records, array $expected): void { $result = $this->subject->applyUserFunction( @@ -399,7 +375,7 @@ public function applyUserFunctionTransformsDataIfValid(string $name, array $conf self::assertSame($expected, $result); } - public function isEmptyDataProvider(): array + public static function isEmptyDataProvider(): array { $emptyArray = [ 0 => [ @@ -587,16 +563,7 @@ public function isEmptyDataProvider(): array ]; } - /** - * Tests the applyIsEmpty() method. - * - * @param string $name Name of the column to transform - * @param array $configuration isEmpty configuration - * @param array $records Records to handle - * @param array $expected Expected results - * @test - * @dataProvider isEmptyDataProvider - */ + #[Test] #[DataProvider('isEmptyDataProvider')] public function applyIsEmptyFiltersRecordsOrSetsDefaultValue(string $name, array $configuration, array $records, array $expected): void { $result = $this->subject->applyIsEmpty( diff --git a/Tests/Functional/Utility/MappingUtilityTest.php b/Tests/Functional/Utility/MappingUtilityTest.php index f25754cd..22cc9ce9 100644 --- a/Tests/Functional/Utility/MappingUtilityTest.php +++ b/Tests/Functional/Utility/MappingUtilityTest.php @@ -18,8 +18,10 @@ */ use Cobweb\ExternalImport\Utility\MappingUtility; -use Nimut\TestingFramework\TestCase\FunctionalTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; /** * Test class for the MappingUtility. @@ -28,28 +30,32 @@ */ class MappingUtilityTest extends FunctionalTestCase { - protected $testExtensionsToLoad = [ - 'typo3conf/ext/svconnector', - 'typo3conf/ext/external_import', - 'typo3conf/ext/externalimport_test', + protected array $coreExtensionsToLoad = [ + 'scheduler', ]; - /** - * @var MappingUtility - */ - protected $subject; + protected array $testExtensionsToLoad = [ + 'cobweb/svconnector', + 'cobweb/svconnector_csv', + 'cobweb/svconnector_feed', + 'cobweb/svconnector_json', + 'cobweb/external_import', + 'cobweb/externalimport_test', + ]; + + protected MappingUtility $subject; public function setUp(): void { parent::setUp(); - $this->subject = GeneralUtility::makeInstance(MappingUtility::class); + $this->subject = new MappingUtility(); } - public function mappingConfigurationProvider(): array + public static function mappingInformationProvider(): array { return [ 'Value map takes precedence' => [ - [ + 'mappingInformation' => [ 'valueMap' => [ 'foo' => 1, 'bar' => 2, @@ -57,77 +63,71 @@ public function mappingConfigurationProvider(): array 'table' => 'sys_category', 'referenceField' => 'external_key', ], - [ + 'results' => [ 'foo' => 1, 'bar' => 2, ], ], 'All records (no valueField property)' => [ - [ + 'mappingInformation' => [ 'table' => 'sys_category', 'referenceField' => 'external_key', ], - [ + 'results' => [ 'CAT1' => 1, 'CAT2' => 2, '0' => 4, ], ], 'All records (with valueField property)' => [ - [ + 'mappingInformation' => [ 'table' => 'sys_category', 'referenceField' => 'external_key', 'valueField' => 'uid', ], - [ + 'results' => [ 'CAT1' => 1, 'CAT2' => 2, '0' => 4, ], ], 'All records (with non-uid valueField property)' => [ - [ + 'mappingInformation' => [ 'table' => 'sys_category', 'referenceField' => 'external_key', 'valueField' => 'title', ], - [ + 'results' => [ 'CAT1' => 'Category 1', 'CAT2' => 'Category 2', '0' => 'Category 4', ], ], 'Filtered records' => [ - [ + 'mappingInformation' => [ 'table' => 'sys_category', 'referenceField' => 'external_key', 'whereClause' => 'pid = 1', ], - [ + 'results' => [ 'CAT1' => 1, ], ], ]; } - /** - * @test - * @dataProvider mappingConfigurationProvider - * @param array $mappingConfiguration - * @param array $results - * @throws \Nimut\TestingFramework\Exception\Exception - */ - public function getMappingReturnsRecordsToMap(array $mappingConfiguration, array $results): void + #[Test] #[DataProvider('mappingInformationProvider')] + public function getMappingReturnsRecordsToMap(array $mappingInformation, array $results): void { - $this->importDataSet(__DIR__ . '/../Fixtures/Mappings.xml'); - $mappings = $this->subject->getMapping($mappingConfiguration); + $this->importCSVDataSet(__DIR__ . '/../Fixtures/Mappings.csv'); + $mappings = $this->subject->getMapping($mappingInformation); self::assertSame( $results, $mappings ); } - public function dataToMapProvider(): array + public static function dataToMapProvider(): array { return [ 'Default value gets applied' => [ @@ -145,8 +145,8 @@ public function dataToMapProvider(): array ], ], 'table' => 'pages', - 'field' => 'categories', - 'mappingConfiguration' => [ + 'columnName' => 'categories', + 'mappingInformation' => [ 'default' => 1, 'table' => 'sys_category', 'referenceField' => 'external_key', @@ -181,8 +181,8 @@ public function dataToMapProvider(): array ], ], 'table' => 'pages', - 'field' => 'categories', - 'mappingConfiguration' => [ + 'columnName' => 'categories', + 'mappingInformation' => [ 'table' => 'sys_category', 'referenceField' => 'external_key', ], @@ -211,8 +211,8 @@ public function dataToMapProvider(): array ], ], 'table' => 'pages', - 'field' => 'categories', - 'mappingConfiguration' => [ + 'columnName' => 'categories', + 'mappingInformation' => [ 'table' => 'sys_category', 'referenceField' => 'external_key', 'multipleValuesSeparator' => ',', @@ -231,16 +231,7 @@ public function dataToMapProvider(): array ]; } - /** - * @test - * @dataProvider dataToMapProvider - * @param array $records Records to handle - * @param string $table Name of the table the records belong to - * @param string $columnName Name of the column whose values must be mapped - * @param array $mappingInformation Mapping configuration - * @param array $result Mapped records (expected result) - * @throws \Nimut\TestingFramework\Exception\Exception - */ + #[Test] #[DataProvider('dataToMapProvider')] public function mapDataMapsDataAndAppliesDefaultValueIfDefined( array $records, string $table, @@ -248,7 +239,7 @@ public function mapDataMapsDataAndAppliesDefaultValueIfDefined( array $mappingInformation, array $result ): void { - $this->importDataSet(__DIR__ . '/../Fixtures/Mappings.xml'); + $this->importCSVDataSet(__DIR__ . '/../Fixtures/Mappings.csv'); $mappedRecords = $this->subject->mapData($records, $table, $columnName, $mappingInformation); self::assertSame( $result, diff --git a/Tests/Functional/Utility/SlugUtilityTest.php b/Tests/Functional/Utility/SlugUtilityTest.php index 9169f50c..30e6a956 100644 --- a/Tests/Functional/Utility/SlugUtilityTest.php +++ b/Tests/Functional/Utility/SlugUtilityTest.php @@ -19,37 +19,42 @@ use Cobweb\ExternalImport\Importer; use Cobweb\ExternalImport\Utility\SlugUtility; -use Nimut\TestingFramework\TestCase\FunctionalTestCase; +use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; /** * Test class for the SlugUtility. */ class SlugUtilityTest extends FunctionalTestCase { - protected $testExtensionsToLoad = [ - 'typo3conf/ext/svconnector', - 'typo3conf/ext/external_import', - 'typo3conf/ext/externalimport_test', + protected array $coreExtensionsToLoad = [ + 'scheduler', ]; - /** - * @var SlugUtility - */ - protected $subject; + protected array $testExtensionsToLoad = [ + 'cobweb/svconnector', + 'cobweb/svconnector_csv', + 'cobweb/svconnector_feed', + 'cobweb/svconnector_json', + 'cobweb/external_import', + 'cobweb/externalimport_test', + ]; + + protected SlugUtility $subject; public function setUp(): void { parent::setUp(); - $this->subject = GeneralUtility::makeInstance( - SlugUtility::class, - GeneralUtility::makeInstance(Importer::class) + $this->subject = new SlugUtility( + $this->getAccessibleMock( + Importer::class, + callOriginalConstructor: false + ), ); } - /** - * @test - */ + #[Test] public function resolveSlugFieldNamesFindsListOfSlugFields(): void { self::assertSame( diff --git a/Tests/Functional/Validator/ColumnConfigurationValidatorTest.php b/Tests/Functional/Validator/ColumnConfigurationValidatorTest.php index 648fe545..26dfd356 100644 --- a/Tests/Functional/Validator/ColumnConfigurationValidatorTest.php +++ b/Tests/Functional/Validator/ColumnConfigurationValidatorTest.php @@ -18,82 +18,85 @@ */ use Cobweb\ExternalImport\Domain\Model\Configuration; +use Cobweb\ExternalImport\Testing\FunctionalTestCaseWithDatabaseTools; use Cobweb\ExternalImport\Validator\ColumnConfigurationValidator; -use Nimut\TestingFramework\TestCase\FunctionalTestCase; -use TYPO3\CMS\Core\Localization\LanguageService; -use TYPO3\CMS\Core\Messaging\AbstractMessage; +use Cobweb\ExternalImport\Validator\ValidationResult; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; +use TYPO3\CMS\Core\Core\Bootstrap; +use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity; use TYPO3\CMS\Core\Utility\GeneralUtility; -class ColumnConfigurationValidatorTest extends FunctionalTestCase +class ColumnConfigurationValidatorTest extends FunctionalTestCaseWithDatabaseTools { - protected $testExtensionsToLoad = [ - 'typo3conf/ext/svconnector', - 'typo3conf/ext/external_import', + protected array $coreExtensionsToLoad = [ + 'scheduler', ]; - /** - * @var ColumnConfigurationValidator - */ - protected $subject; + protected array $testExtensionsToLoad = [ + 'cobweb/svconnector', + 'cobweb/external_import', + ]; + + protected ColumnConfigurationValidator $subject; public function setUp(): void { parent::setUp(); - // Connector services need a global LanguageService object - $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageService::class); - $GLOBALS['LANG']->init('en'); + $this->initializeBackendUser(); + Bootstrap::initializeLanguageObject(); - $this->subject = GeneralUtility::makeInstance(ColumnConfigurationValidator::class); + $this->subject = new ColumnConfigurationValidator(new ValidationResult()); } - public function validConfigurationProvider(): array + public static function validConfigurationProvider(): array { return [ 'Data type "array": using property "field" (string)' => [ - [ + 'generalConfiguration' => [ 'data' => 'array', ], - [ + 'columnConfiguration' => [ 'col' => [ 'field' => 'foo', ], ], ], 'Data type "array": using property "field" (positive integer)' => [ - [ + 'generalConfiguration' => [ 'data' => 'array', ], - [ + 'columnConfiguration' => [ 'col' => [ 'field' => 42, ], ], ], 'Data type "array": using property "field" (zero)' => [ - [ + 'generalConfiguration' => [ 'data' => 'array', ], - [ + 'columnConfiguration' => [ 'col' => [ 'field' => 0, ], ], ], 'Data type "array": using column property "value" (number)' => [ - [ + 'generalConfiguration' => [ 'data' => 'array', ], - [ + 'columnConfiguration' => [ 'col' => [ 'value' => 17, ], ], ], 'Data type "array": using transformations property "value" (number)' => [ - [ + 'generalConfiguration' => [ 'data' => 'array', ], - [ + 'columnConfiguration' => [ 'col' => [ 'transformations' => [ 10 => [ @@ -104,20 +107,20 @@ public function validConfigurationProvider(): array ], ], 'Data type "array": using column property "value" (string)' => [ - [ + 'generalConfiguration' => [ 'data' => 'array', ], - [ + 'columnConfiguration' => [ 'col' => [ 'value' => 'bar', ], ], ], 'Data type "array": using transformations property "value" (string)' => [ - [ + 'generalConfiguration' => [ 'data' => 'array', ], - [ + 'columnConfiguration' => [ 'col' => [ 'transformations' => [ 10 => [ @@ -128,40 +131,40 @@ public function validConfigurationProvider(): array ], ], 'Data type "array": using property "arrayPath"' => [ - [ + 'generalConfiguration' => [ 'data' => 'array', ], - [ + 'columnConfiguration' => [ 'col' => [ 'arrayPath' => 'foo/bar', ], ], ], 'Data type "xml": using property "field" (string)' => [ - [ + 'generalConfiguration' => [ 'data' => 'xml', ], - [ + 'columnConfiguration' => [ 'col' => [ 'field' => 'foo', ], ], ], 'Data type "xml": using column property "value" (number)' => [ - [ + 'generalConfiguration' => [ 'data' => 'xml', ], - [ + 'columnConfiguration' => [ 'col' => [ 'value' => 17, ], ], ], 'Data type "xml": using transformations property "value" (number)' => [ - [ + 'generalConfiguration' => [ 'data' => 'xml', ], - [ + 'columnConfiguration' => [ 'col' => [ 'transformations' => [ 10 => [ @@ -172,20 +175,20 @@ public function validConfigurationProvider(): array ], ], 'Data type "xml": using column property "value" (string)' => [ - [ + 'generalConfiguration' => [ 'data' => 'xml', ], - [ + 'columnConfiguration' => [ 'col' => [ 'value' => 'bar', ], ], ], 'Data type "xml": using transformations property "value" (string)' => [ - [ + 'generalConfiguration' => [ 'data' => 'xml', ], - [ + 'columnConfiguration' => [ 'col' => [ 'transformations' => [ 10 => [ @@ -196,30 +199,32 @@ public function validConfigurationProvider(): array ], ], 'Data type "xml": using property "attribute" (string)' => [ - [ + 'generalConfiguration' => [ 'data' => 'xml', ], - [ + 'columnConfiguration' => [ 'col' => [ 'field' => 'baz', ], ], ], 'Data type "xml": using property "xpath" (string)' => [ - [ + 'generalConfiguration' => [ 'data' => 'xml', ], - [ + 'columnConfiguration' => [ 'col' => [ 'field' => 'hello', ], ], ], 'Children definition' => [ - // No need for a general configuration - [], - [ + 'generalConfiguration' => [ + 'data' => 'array', + ], + 'columnConfiguration' => [ 'col' => [ + 'field' => 'foo', 'children' => [ 'table' => 'foo', 'columns' => [ @@ -230,15 +235,17 @@ public function validConfigurationProvider(): array 'field' => 'baz', ], ], + 'controlColumnsForUpdate' => 'column1', + 'controlColumnsForDelete' => 'column2', ], ], ], ], 'Substructure fields: valid structure and properties for "array" data type' => [ - [ + 'generalConfiguration' => [ 'data' => 'array', ], - [ + 'columnConfiguration' => [ 'col' => [ 'field' => 'foo', 'substructureFields' => [ @@ -250,10 +257,10 @@ public function validConfigurationProvider(): array ], ], 'Substructure fields: valid structure and properties for "xml" data type' => [ - [ + 'generalConfiguration' => [ 'data' => 'xml', ], - [ + 'columnConfiguration' => [ 'col' => [ 'substructureFields' => [ 'foo' => [ @@ -266,12 +273,7 @@ public function validConfigurationProvider(): array ]; } - /** - * @param array $generalConfiguration - * @param array $columnConfiguration - * @test - * @dataProvider validConfigurationProvider - */ + #[Test] #[DataProvider('validConfigurationProvider')] public function isValidReturnsTrueForValidConfiguration( array $generalConfiguration, array $columnConfiguration @@ -288,28 +290,28 @@ public function isValidReturnsTrueForValidConfiguration( ); } - public function invalidConfigurationProvider(): array + public static function invalidConfigurationProvider(): array { return [ 'Data type "array": missing data-setting properties' => [ - [ + 'generalConfiguration' => [ 'data' => 'array', ], - [], - AbstractMessage::ERROR, + 'columnConfiguration' => [], + 'severity' => ContextualFeedbackSeverity::ERROR, ], 'Data type "xml": missing data-setting properties' => [ - [ + 'generalConfiguration' => [ 'data' => 'xml', ], - [], - AbstractMessage::NOTICE, + 'columnConfiguration' => [], + 'severity' => ContextualFeedbackSeverity::NOTICE, ], 'Data type "array": conflicting data-setting properties' => [ - [ + 'generalConfiguration' => [ 'data' => 'array', ], - [ + 'columnConfiguration' => [ 'col' => [ 'field' => 'foo', 'transformations' => [ @@ -319,13 +321,13 @@ public function invalidConfigurationProvider(): array ], ], ], - AbstractMessage::NOTICE, + 'severity' => ContextualFeedbackSeverity::NOTICE, ], 'Data type "xml": conflicting data-setting properties' => [ - [ + 'generalConfiguration' => [ 'data' => 'xml', ], - [ + 'columnConfiguration' => [ 'col' => [ 'xpath' => 'item', 'transformations' => [ @@ -335,12 +337,13 @@ public function invalidConfigurationProvider(): array ], ], ], - AbstractMessage::NOTICE, + 'severity' => ContextualFeedbackSeverity::NOTICE, ], 'Children definition: no "table" property' => [ - // No need for a general configuration - [], - [ + 'generalConfiguration' => [ + 'data' => 'array', + ], + 'columnConfiguration' => [ 'col' => [ 'children' => [ 'columns' => [ @@ -356,24 +359,26 @@ public function invalidConfigurationProvider(): array ], ], ], - AbstractMessage::ERROR, + 'severity' => ContextualFeedbackSeverity::ERROR, ], 'Children definition: no "columns" property' => [ - // No need for a general configuration - [], - [ + 'generalConfiguration' => [ + 'data' => 'array', + ], + 'columnConfiguration' => [ 'col' => [ 'children' => [ 'table' => 'foo', ], ], ], - AbstractMessage::ERROR, + 'severity' => ContextualFeedbackSeverity::ERROR, ], 'Children definition: "columns" sub-property not an array' => [ - // No need for a general configuration - [], - [ + 'generalConfiguration' => [ + 'data' => 'array', + ], + 'columnConfiguration' => [ 'col' => [ 'children' => [ 'table' => 'foo', @@ -385,12 +390,13 @@ public function invalidConfigurationProvider(): array ], ], ], - AbstractMessage::ERROR, + 'severity' => ContextualFeedbackSeverity::ERROR, ], 'Children definition: wrong "columns" sub-property' => [ - // No need for a general configuration - [], - [ + 'generalConfiguration' => [ + 'data' => 'array', + ], + 'columnConfiguration' => [ 'col' => [ 'children' => [ 'table' => 'foo', @@ -404,12 +410,13 @@ public function invalidConfigurationProvider(): array ], ], ], - AbstractMessage::ERROR, + 'severity' => ContextualFeedbackSeverity::ERROR, ], 'Children definition: wrong "controlColumnsForUpdate" sub-property' => [ - // No need for a general configuration - [], - [ + 'generalConfiguration' => [ + 'data' => 'array', + ], + 'columnConfiguration' => [ 'col' => [ 'children' => [ 'table' => 'foo', @@ -422,12 +429,13 @@ public function invalidConfigurationProvider(): array ], ], ], - AbstractMessage::ERROR, + 'severity' => ContextualFeedbackSeverity::ERROR, ], 'Children definition: wrong "controlColumnsForDelete" sub-property' => [ - // No need for a general configuration - [], - [ + 'generalConfiguration' => [ + 'data' => 'array', + ], + 'columnConfiguration' => [ 'col' => [ 'children' => [ 'table' => 'foo', @@ -440,13 +448,13 @@ public function invalidConfigurationProvider(): array ], ], ], - AbstractMessage::ERROR, + 'severity' => ContextualFeedbackSeverity::ERROR, ], 'Substructure fields: wrong structure' => [ - [ + 'generalConfiguration' => [ 'data' => 'array', ], - [ + 'columnConfiguration' => [ 'col' => [ 'field' => 'foo', 'substructureFields' => [ @@ -454,13 +462,13 @@ public function invalidConfigurationProvider(): array ], ], ], - AbstractMessage::ERROR, + 'severity' => ContextualFeedbackSeverity::ERROR, ], 'Substructure fields: empty configuration for "array" data type' => [ - [ + 'generalConfiguration' => [ 'data' => 'array', ], - [ + 'columnConfiguration' => [ 'col' => [ 'field' => 'foo', 'substructureFields' => [ @@ -468,13 +476,13 @@ public function invalidConfigurationProvider(): array ], ], ], - AbstractMessage::ERROR, + 'severity' => ContextualFeedbackSeverity::ERROR, ], 'Substructure fields: invalid properties for "array" data type' => [ - [ + 'generalConfiguration' => [ 'data' => 'array', ], - [ + 'columnConfiguration' => [ 'col' => [ 'field' => 'foo', 'substructureFields' => [ @@ -484,13 +492,13 @@ public function invalidConfigurationProvider(): array ], ], ], - AbstractMessage::ERROR, + 'severity' => ContextualFeedbackSeverity::ERROR, ], 'Substructure fields: invalid properties for "xml" data type' => [ - [ + 'generalConfiguration' => [ 'data' => 'xml', ], - [ + 'columnConfiguration' => [ 'col' => [ 'field' => 'foo', 'substructureFields' => [ @@ -500,22 +508,16 @@ public function invalidConfigurationProvider(): array ], ], ], - AbstractMessage::ERROR, + 'severity' => ContextualFeedbackSeverity::ERROR, ], ]; } - /** - * @param array $generalConfiguration - * @param array $columnConfiguration - * @param int $severity - * @test - * @dataProvider invalidConfigurationProvider - */ + #[Test] #[DataProvider('invalidConfigurationProvider')] public function isValidRaisesMessageForInvalidConfiguration( array $generalConfiguration, array $columnConfiguration, - int $severity + ContextualFeedbackSeverity $severity ): void { $configuration = GeneralUtility::makeInstance(Configuration::class); $configuration->setGeneralConfiguration($generalConfiguration); diff --git a/Tests/Functional/Validator/GeneralConfigurationValidatorTest.php b/Tests/Functional/Validator/GeneralConfigurationValidatorTest.php index 3303901f..15c3db88 100644 --- a/Tests/Functional/Validator/GeneralConfigurationValidatorTest.php +++ b/Tests/Functional/Validator/GeneralConfigurationValidatorTest.php @@ -19,53 +19,55 @@ use Cobweb\ExternalImport\Domain\Model\Configuration; use Cobweb\ExternalImport\Importer; +use Cobweb\ExternalImport\Testing\FunctionalTestCaseWithDatabaseTools; +use Cobweb\ExternalImport\Utility\StepUtility; use Cobweb\ExternalImport\Validator\GeneralConfigurationValidator; -use Nimut\TestingFramework\TestCase\FunctionalTestCase; -use TYPO3\CMS\Core\Localization\LanguageService; -use TYPO3\CMS\Core\Messaging\AbstractMessage; -use TYPO3\CMS\Core\Messaging\FlashMessage; +use Cobweb\ExternalImport\Validator\ValidationResult; +use Cobweb\Svconnector\Registry\ConnectorRegistry; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; +use TYPO3\CMS\Core\Core\Bootstrap; +use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity; use TYPO3\CMS\Core\Utility\GeneralUtility; -class GeneralConfigurationValidatorTest extends FunctionalTestCase +class GeneralConfigurationValidatorTest extends FunctionalTestCaseWithDatabaseTools { - protected $testExtensionsToLoad = [ - 'typo3conf/ext/external_import', - 'typo3conf/ext/svconnector', + protected array $coreExtensionsToLoad = [ + 'scheduler', ]; - /** - * @var GeneralConfigurationValidator - */ - protected $subject; + protected array $testExtensionsToLoad = [ + 'cobweb/external_import', + 'cobweb/svconnector', + ]; + + protected GeneralConfigurationValidator $subject; public function setUp(): void { parent::setUp(); - // Localized validation messages need a global LanguageService object - $GLOBALS['LANG'] = $this->getAccessibleMock( - LanguageService::class, - [], - [], - '', - // Don't call the original constructor to avoid a cascade of dependencies - false - ); + $this->initializeBackendUser(); + Bootstrap::initializeLanguageObject(); - $this->subject = GeneralUtility::makeInstance(GeneralConfigurationValidator::class); + $this->subject = new GeneralConfigurationValidator( + new ValidationResult(), + new StepUtility(), + new ConnectorRegistry([]) + ); } - public function validConfigurationProvider(): array + public static function validConfigurationProvider(): array { return [ 'Typical configuration for array type' => [ - [ + 'configuration' => [ 'data' => 'array', 'referenceUid' => 'external_id', 'pid' => 12, ], ], 'Typical configuration for xml type (nodetype)' => [ - [ + 'configuration' => [ 'data' => 'xml', 'nodetype' => 'foo', 'referenceUid' => 'external_id', @@ -73,7 +75,7 @@ public function validConfigurationProvider(): array ], ], 'Typical configuration for xml type (nodepath)' => [ - [ + 'configuration' => [ 'data' => 'xml', 'nodepath' => '//foo', 'referenceUid' => 'external_id', @@ -83,11 +85,7 @@ public function validConfigurationProvider(): array ]; } - /** - * @param array $configuration - * @test - * @dataProvider validConfigurationProvider - */ + #[Test] #[DataProvider('validConfigurationProvider')] public function isValidReturnsTrueForValidConfiguration(array $configuration): void { self::assertTrue( @@ -100,40 +98,36 @@ public function isValidReturnsTrueForValidConfiguration(array $configuration): v ); } - public function invalidConfigurationProvider(): array + public static function invalidConfigurationProvider(): array { return [ 'Missing data property' => [ - [ + 'configuration' => [ 'reference_uid' => 'external_id', ], ], 'Invalid data property' => [ - [ + 'configuration' => [ 'data' => 'foo', 'reference_uid' => 'external_id', ], ], 'Invalid connector property' => [ - [ + 'configuration' => [ 'data' => 'array', 'reference_uid' => 'external_id', 'connector' => uniqid('', true), ], ], 'Missing reference_uid property' => [ - [ + 'configuration' => [ 'data' => 'array', ], ], ]; } - /** - * @param array $configuration - * @test - * @dataProvider invalidConfigurationProvider - */ + #[Test] #[DataProvider('invalidConfigurationProvider')] public function isValidReturnsFalseForInvalidConfiguration(array $configuration): void { self::assertFalse( @@ -146,25 +140,21 @@ public function isValidReturnsFalseForInvalidConfiguration(array $configuration) ); } - public function invalidDataPropertyConfigurationProvider(): array + public static function invalidDataPropertyConfigurationProvider(): array { return [ 'Missing data property' => [ - [], + 'configuration' => [], ], 'Invalid data property' => [ - [ + 'configuration' => [ 'data' => 'foo', ], ], ]; } - /** - * @param array $configuration - * @test - * @dataProvider invalidDataPropertyConfigurationProvider - */ + #[Test] #[DataProvider('invalidDataPropertyConfigurationProvider')] public function validateDataPropertyWithInvalidValueRaisesError(array $configuration): void { $this->subject->isValid( @@ -175,20 +165,19 @@ public function validateDataPropertyWithInvalidValueRaisesError(array $configura ); $results = $this->subject->getResults()->getForProperty('data'); self::assertSame( - FlashMessage::ERROR, + ContextualFeedbackSeverity::ERROR, $results[0]['severity'] ); } - /** - * @test - */ + #[Test] public function validateConnectorPropertyWithInvalidValueRaisesError(): void { $this->subject->isValid( $this->prepareConfigurationObject( 'tt_content', [ + 'data' => 'array', // Some random connector name 'connector' => uniqid('', true), ] @@ -196,32 +185,30 @@ public function validateConnectorPropertyWithInvalidValueRaisesError(): void ); $results = $this->subject->getResults()->getForProperty('connector'); self::assertSame( - FlashMessage::ERROR, + ContextualFeedbackSeverity::ERROR, $results[0]['severity'] ); } - public function invalidDataHandlerPropertyConfigurationProvider(): array + public static function invalidDataHandlerPropertyConfigurationProvider(): array { return [ 'Not existing class' => [ - [ + 'configuration' => [ + 'data' => 'array', 'dataHandler' => 'Cobweb\\ExternalImport\\' . time(), ], ], 'Class not implementing proper interface' => [ - [ + 'configuration' => [ + 'data' => 'array', 'dataHandler' => Importer::class, ], ], ]; } - /** - * @param array $configuration - * @test - * @dataProvider invalidDataHandlerPropertyConfigurationProvider - */ + #[Test] #[DataProvider('invalidDataHandlerPropertyConfigurationProvider')] public function validateDataHandlerPropertyWithInvalidValueRaisesNotice(array $configuration): void { $this->subject->isValid( @@ -232,14 +219,12 @@ public function validateDataHandlerPropertyWithInvalidValueRaisesNotice(array $c ); $results = $this->subject->getResults()->getForProperty('dataHandler'); self::assertSame( - AbstractMessage::NOTICE, + ContextualFeedbackSeverity::NOTICE, $results[0]['severity'] ); } - /** - * @test - */ + #[Test] public function validateNodetypePropertyForXmlDataWithEmptyValueRaisesError(): void { $this->subject->isValid( @@ -252,58 +237,56 @@ public function validateNodetypePropertyForXmlDataWithEmptyValueRaisesError(): v ); $results = $this->subject->getResults()->getForProperty('nodetype'); self::assertSame( - AbstractMessage::ERROR, + ContextualFeedbackSeverity::ERROR, $results[0]['severity'] ); } - /** - * @test - */ + #[Test] public function validateReferenceUidPropertyWithEmptyValueRaisesError(): void { $this->subject->isValid( $this->prepareConfigurationObject( 'tt_content', - [] + [ + 'data' => 'array', + ] ) ); $results = $this->subject->getResults()->getForProperty('referenceUid'); self::assertSame( - FlashMessage::ERROR, + ContextualFeedbackSeverity::ERROR, $results[0]['severity'] ); } - /** - * @test - */ + #[Test] public function validatePriorityPropertyWithEmptyValueRaisesNotice(): void { $this->subject->isValid( $this->prepareConfigurationObject( 'tt_content', [ - 'connector' => 'foo', + 'connector' => 'csv', + 'data' => 'array', ] ) ); $results = $this->subject->getResults()->getForProperty('priority'); self::assertSame( - AbstractMessage::NOTICE, + ContextualFeedbackSeverity::NOTICE, $results[0]['severity'] ); } - /** - * @test - */ + #[Test] public function validatePidPropertyWithEmptyValueForRootTableRaisesNotice(): void { $this->subject->isValid( $this->prepareConfigurationObject( 'be_users', [ + 'data' => 'array', // NOTE: normally, configuration is parsed by the ConfigurationRepository and pid would // be set to 0 if missing from configuration 'pid' => 0, @@ -312,43 +295,41 @@ public function validatePidPropertyWithEmptyValueForRootTableRaisesNotice(): voi ); $results = $this->subject->getResults()->getForProperty('pid'); self::assertSame( - AbstractMessage::NOTICE, + ContextualFeedbackSeverity::NOTICE, $results[0]['severity'] ); } - public function invalidPidPropertyConfigurationProvider(): array + public static function invalidPidPropertyConfigurationProvider(): array { return [ 'Missing pid, non-root table' => [ - 'tt_content', - [ + 'table' => 'tt_content', + 'configuration' => [ + 'data' => 'array', // NOTE: normally, configuration is parsed by the ConfigurationRepository and pid would // be set to 0 if missing from configuration 'pid' => 0, ], ], 'Negative pid' => [ - 'tt_content', - [ + 'table' => 'tt_content', + 'configuration' => [ + 'data' => 'array', 'pid' => -12, ], ], 'Positive pid, root table' => [ - 'be_users', - [ + 'table' => 'be_users', + 'configuration' => [ + 'data' => 'array', 'pid' => 12, ], ], ]; } - /** - * @param string $table Table name - * @param array $configuration Configuration - * @test - * @dataProvider invalidPidPropertyConfigurationProvider - */ + #[Test] #[DataProvider('invalidPidPropertyConfigurationProvider')] public function validatePidPropertyWithInvalidValueRaisesError(string $table, array $configuration): void { $this->subject->isValid( @@ -359,40 +340,38 @@ public function validatePidPropertyWithInvalidValueRaisesError(string $table, ar ); $results = $this->subject->getResults()->getForProperty('pid'); self::assertSame( - AbstractMessage::ERROR, + ContextualFeedbackSeverity::ERROR, $results[0]['severity'] ); } - /** - * @test - */ + #[Test] public function validateUseColumnIndexPropertyWithInvalidValueRaisesError(): void { $this->subject->isValid( $this->prepareConfigurationObject( 'tt_content', [ + 'data' => 'array', 'useColumnIndex' => 'foo', ] ) ); $results = $this->subject->getResults()->getForProperty('useColumnIndex'); self::assertSame( - AbstractMessage::ERROR, + ContextualFeedbackSeverity::ERROR, $results[0]['severity'] ); } - /** - * @test - */ + #[Test] public function validateColumnsOrderPropertyWithDuplicateValuesRaisesNotice(): void { $this->subject->isValid( $this->prepareConfigurationObject( 'tt_content', [ + 'data' => 'array', 'columnsOrder' => 'bb, aa, aa', ], [ @@ -407,17 +386,13 @@ public function validateColumnsOrderPropertyWithDuplicateValuesRaisesNotice(): v ); $results = $this->subject->getResults()->getForProperty('columnsOrder'); self::assertSame( - AbstractMessage::NOTICE, + ContextualFeedbackSeverity::NOTICE, $results[0]['severity'] ); } /** * Prepares a configuration object with the usual parameters used in this test suite. - * - * @param string $table - * @param array $configuration - * @return Configuration */ protected function prepareConfigurationObject(string $table, array $configuration, array $columnConfiguration = []): Configuration { @@ -427,4 +402,10 @@ protected function prepareConfigurationObject(string $table, array $configuratio $configurationObject->setColumnConfiguration($columnConfiguration); return $configurationObject; } + + public function tearDown(): void + { + parent::tearDown(); + restore_error_handler(); + } } diff --git a/Tests/Unit/Domain/Model/ChildrenConfigurationTest.php b/Tests/Unit/Domain/Model/ChildrenConfigurationTest.php index 3ba260be..372a0a5d 100644 --- a/Tests/Unit/Domain/Model/ChildrenConfigurationTest.php +++ b/Tests/Unit/Domain/Model/ChildrenConfigurationTest.php @@ -18,8 +18,10 @@ namespace Cobweb\ExternalImport\Tests\Unit\Domain\Model; use Cobweb\ExternalImport\Domain\Model\ChildrenConfiguration; -use Nimut\TestingFramework\TestCase\UnitTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; class ChildrenConfigurationTest extends UnitTestCase { @@ -31,9 +33,7 @@ public function setUp(): void $this->subject = GeneralUtility::makeInstance(ChildrenConfiguration::class); } - /** - * @test - */ + #[Test] public function getBaseDataInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -42,9 +42,7 @@ public function getBaseDataInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function setBaseDataSetsDataArray(): void { $this->subject->setBaseData(['table' => 'foo']); @@ -54,7 +52,7 @@ public function setBaseDataSetsDataArray(): void ); } - public function propertyProvider(): array + public static function propertyProvider(): array { return [ 'empty base data' => [ @@ -79,14 +77,8 @@ public function propertyProvider(): array ]; } - /** - * @test - * @dataProvider propertyProvider - * @param array $baseData - * @param string $property - * @param $result - */ - public function getBaseDataPropertyReturnsValueOrNull(array $baseData, string $property, $result): void + #[Test] #[DataProvider('propertyProvider')] + public function getBaseDataPropertyReturnsValueOrNull(array $baseData, string $property, mixed $result): void { $this->subject->setBaseData($baseData); self::assertSame( @@ -95,9 +87,7 @@ public function getBaseDataPropertyReturnsValueOrNull(array $baseData, string $p ); } - /** - * @test - */ + #[Test] public function getControlColumnsForDeleteInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -106,9 +96,7 @@ public function getControlColumnsForDeleteInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function setControlColumnsForDeleteSetsArray(): void { $this->subject->setControlColumnsForDelete(['foo', 'bar']); @@ -118,9 +106,7 @@ public function setControlColumnsForDeleteSetsArray(): void ); } - /** - * @test - */ + #[Test] public function getControlColumnsForUpdateInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -129,9 +115,7 @@ public function getControlColumnsForUpdateInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function setControlColumnsForUpdateSetsArray(): void { $this->subject->setControlColumnsForUpdate(['foo', 'bar']); @@ -141,9 +125,7 @@ public function setControlColumnsForUpdateSetsArray(): void ); } - /** - * @test - */ + #[Test] public function isDeleteAllowedInitiallyReturnsTrue(): void { self::assertTrue( @@ -151,9 +133,7 @@ public function isDeleteAllowedInitiallyReturnsTrue(): void ); } - /** - * @test - */ + #[Test] public function setDeleteAllowedInitiallySetsBoolean(): void { $this->subject->setDeleteAllowed(false); @@ -162,9 +142,7 @@ public function setDeleteAllowedInitiallySetsBoolean(): void ); } - /** - * @test - */ + #[Test] public function isInsertAllowedInitiallyReturnsTrue(): void { self::assertTrue( @@ -172,9 +150,7 @@ public function isInsertAllowedInitiallyReturnsTrue(): void ); } - /** - * @test - */ + #[Test] public function setInsertAllowedInitiallySetsBoolean(): void { $this->subject->setInsertAllowed(false); @@ -183,9 +159,7 @@ public function setInsertAllowedInitiallySetsBoolean(): void ); } - /** - * @test - */ + #[Test] public function isUpdateAllowedInitiallyReturnsTrue(): void { self::assertTrue( @@ -193,9 +167,7 @@ public function isUpdateAllowedInitiallyReturnsTrue(): void ); } - /** - * @test - */ + #[Test] public function setUpdateAllowedInitiallySetsBoolean(): void { $this->subject->setUpdateAllowed(false); @@ -204,7 +176,7 @@ public function setUpdateAllowedInitiallySetsBoolean(): void ); } - public function allowedOperationsProvider(): array + public static function allowedOperationsProvider(): array { return [ 'set delete to true' => [ @@ -222,12 +194,7 @@ public function allowedOperationsProvider(): array ]; } - /** - * @test - * @dataProvider allowedOperationsProvider - * @param string $operation - * @param bool $flag - */ + #[Test] #[DataProvider('allowedOperationsProvider')] public function setAllowedOperationSetExpectedFlag(string $operation, bool $flag): void { $this->subject->setAllowedOperation($operation, $flag); @@ -248,9 +215,7 @@ public function setAllowedOperationSetExpectedFlag(string $operation, bool $flag ); } - /** - * @test - */ + #[Test] public function getSortingInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -259,9 +224,7 @@ public function getSortingInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function setSortingSetsArray(): void { $this->subject->setSorting( diff --git a/Tests/Unit/Domain/Model/ConfigurationKeyTest.php b/Tests/Unit/Domain/Model/ConfigurationKeyTest.php index 25c81c6d..8123ac37 100644 --- a/Tests/Unit/Domain/Model/ConfigurationKeyTest.php +++ b/Tests/Unit/Domain/Model/ConfigurationKeyTest.php @@ -1,5 +1,7 @@ subject = new ConfigurationKey(); } - /** - * @test - */ + #[Test] public function getConfigurationKeyInitiallyReturnsEmptyString(): void { self::assertEquals('', $this->subject->getConfigurationKey()); } - /** - * @test - */ + #[Test] public function getIndexInitiallyReturnsEmptyString(): void { self::assertEquals('', $this->subject->getIndex()); } - /** - * @test - */ + #[Test] public function getTableInitiallyReturnsEmptyString(): void { self::assertEquals('', $this->subject->getTable()); } - public function configurationProvider(): array + public static function configurationProvider(): array { return [ - 'standard table name, numerical index' => [ - 'table' => 'tx_foo', - 'index' => 1, - 'key' => 'tx_foo***1', - ], - 'standard table name, numerical index with value 0' => [ - 'table' => 'tx_foo', - 'index' => 0, - 'key' => 'tx_foo***0', - ], - 'standard table name, string index' => [ - 'table' => 'tx_foo', - 'index' => 'bar', - 'key' => 'tx_foo***bar', - ], - 'table name with hyphen, string index' => [ - 'table' => 'tx-foo', - 'index' => 'bar', - 'key' => 'tx-foo***bar', - ], - 'group name' => [ - 'table' => 'group:foo', - 'index' => '', - 'key' => 'group:foo', - ], - 'all tables' => [ - 'table' => 'all', - 'index' => '', - 'key' => 'all', - ], + 'standard table name, numerical index' => [ + 'table' => 'tx_foo', + 'index' => 1, + 'key' => 'tx_foo***1', + ], + 'standard table name, numerical index with value 0' => [ + 'table' => 'tx_foo', + 'index' => 0, + 'key' => 'tx_foo***0', + ], + 'standard table name, string index' => [ + 'table' => 'tx_foo', + 'index' => 'bar', + 'key' => 'tx_foo***bar', + ], + 'table name with hyphen, string index' => [ + 'table' => 'tx-foo', + 'index' => 'bar', + 'key' => 'tx-foo***bar', + ], + 'group name' => [ + 'table' => 'group:foo', + 'index' => '', + 'key' => 'group:foo', + ], + 'all tables' => [ + 'table' => 'all', + 'index' => '', + 'key' => 'all', + ], ]; } - /** - * @test - * @dataProvider configurationProvider - * @param string $table - * @param mixed $index - * @param string $key - */ + #[Test] #[DataProvider('configurationProvider')] public function setConfigurationKeySetsTableAndIndex(string $table, $index, string $key): void { $this->subject->setConfigurationKey($key); @@ -108,13 +97,7 @@ public function setConfigurationKeySetsTableAndIndex(string $table, $index, stri self::assertEquals($index, $this->subject->getIndex()); } - /** - * @test - * @dataProvider configurationProvider - * @param string $table - * @param mixed $index - * @param string $key - */ + #[Test] #[DataProvider('configurationProvider')] public function setTableAndIndexSetsConfigurationKey(string $table, $index, string $key): void { $this->subject->setTableAndIndex($table, (string)$index); diff --git a/Tests/Unit/Domain/Model/ConfigurationTest.php b/Tests/Unit/Domain/Model/ConfigurationTest.php index cab19964..2ae13258 100644 --- a/Tests/Unit/Domain/Model/ConfigurationTest.php +++ b/Tests/Unit/Domain/Model/ConfigurationTest.php @@ -22,15 +22,14 @@ use Cobweb\ExternalImport\Step\StoreDataStep; use Cobweb\Svconnector\Service\ConnectorBase; use Cobweb\SvconnectorFeed\Service\ConnectorFeed; -use Nimut\TestingFramework\TestCase\UnitTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; class ConfigurationTest extends UnitTestCase { - /** - * @var Configuration - */ - protected $subject; + protected Configuration $subject; public function setUp(): void { @@ -38,9 +37,7 @@ public function setUp(): void $this->subject = GeneralUtility::makeInstance(Configuration::class); } - /** - * @test - */ + #[Test] public function getAdditionalFieldsInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -49,9 +46,7 @@ public function getAdditionalFieldsInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function getColumnConfigurationInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -60,9 +55,7 @@ public function getColumnConfigurationInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function getConfigurationForColumnInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -71,9 +64,7 @@ public function getConfigurationForColumnInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function getConnectorInitiallyReturnsNull(): void { self::assertNull( @@ -81,9 +72,7 @@ public function getConnectorInitiallyReturnsNull(): void ); } - /** - * @test - */ + #[Test] public function getCountAdditionalFieldsInitiallyReturnsZero(): void { self::assertSame( @@ -92,9 +81,7 @@ public function getCountAdditionalFieldsInitiallyReturnsZero(): void ); } - /** - * @test - */ + #[Test] public function getGenerallConfigurationInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -103,9 +90,7 @@ public function getGenerallConfigurationInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function getGenerallConfigurationPropertyInitiallyReturnsNull(): void { self::assertNull( @@ -113,9 +98,7 @@ public function getGenerallConfigurationPropertyInitiallyReturnsNull(): void ); } - /** - * @test - */ + #[Test] public function getIndexInitiallyReturnsNull(): void { self::assertNull( @@ -123,9 +106,7 @@ public function getIndexInitiallyReturnsNull(): void ); } - /** - * @test - */ + #[Test] public function getStepsInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -134,9 +115,7 @@ public function getStepsInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function hasParametersForStepInitiallyReturnsFalse(): void { self::assertFalse( @@ -144,9 +123,7 @@ public function hasParametersForStepInitiallyReturnsFalse(): void ); } - /** - * @test - */ + #[Test] public function getParametersForStepInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -155,9 +132,7 @@ public function getParametersForStepInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function setParametersForStepSetsParameters(): void { $parameters = ['foo', 'bar' => 'baz']; @@ -171,9 +146,7 @@ public function setParametersForStepSetsParameters(): void ); } - /** - * @test - */ + #[Test] public function getStoragePidInitiallyReturnsNull(): void { self::assertNull( @@ -181,9 +154,7 @@ public function getStoragePidInitiallyReturnsNull(): void ); } - /** - * @test - */ + #[Test] public function getTableInitiallyReturnsNull(): void { self::assertNull( @@ -191,26 +162,21 @@ public function getTableInitiallyReturnsNull(): void ); } - public function ctrlConfigurationProvider(): array + public static function ctrlConfigurationProvider(): array { return [ - 'sample configuration' => [ - [ - 'connector' => 'feed', - 'pid' => 42, - 'additionalFields' => 'foo,bar', - ], - 42, + 'sample configuration' => [ + 'configuration' => [ + 'connector' => 'feed', + 'pid' => 42, + 'additionalFields' => 'foo,bar', ], + 'pid' => 42, + ], ]; } - /** - * @test - * @param array $configuration - * @param int $pid - * @dataProvider ctrlConfigurationProvider - */ + #[Test] #[DataProvider('ctrlConfigurationProvider')] public function setGeneralConfigurationSetsGeneralConfigurationAndMore(array $configuration, int $pid): void { $this->subject->setGeneralConfiguration($configuration); @@ -228,73 +194,66 @@ public function setGeneralConfigurationSetsGeneralConfigurationAndMore(array $co ); } - public function columnConfigurationProvider(): array + public static function columnConfigurationProvider(): array { return [ - 'configuration without additional fields' => [ - [], - [ - 'foo' => [ - 'field' => 'bar', - 'transformations' => [ - 20 => [ - 'value' => 3, - ], - 10 => [ - 'value' => 4, - ], - ], - ], - ], - 'foo', - [ - 'field' => 'bar', - 'transformations' => [ - 10 => [ - 'value' => 4, - ], - 20 => [ - 'value' => 3, - ], - ], + 'configuration without additional fields' => [ + 'additionalFieldsConfiguration' => [], + 'columnConfiguration' => [ + 'foo' => [ + 'field' => 'bar', + 'transformations' => [ + 20 => [ + 'value' => 3, + ], + 10 => [ + 'value' => 4, + ], ], + ], ], - 'configuration with additional fields' => [ - [ - 'baz' => [ - 'field' => 'baz', - ], + 'columnName' => 'foo', + 'processedConfiguration' => [ + 'field' => 'bar', + 'transformations' => [ + 10 => [ + 'value' => 4, ], - [ - 'foo' => [ - 'field' => 'bar', - 'transformations' => [ - 20 => [ - 'value' => 3, - ], - 10 => [ - 'value' => 4, - ], - ], - ], + 20 => [ + 'value' => 3, ], - 'baz', - [ - 'field' => 'baz', - Configuration::DO_NOT_SAVE_KEY => true, + ], + ], + ], + 'configuration with additional fields' => [ + 'additionalFieldsConfiguration' => [ + 'baz' => [ + 'field' => 'baz', + ], + ], + 'columnConfiguration' => [ + 'foo' => [ + 'field' => 'bar', + 'transformations' => [ + 20 => [ + 'value' => 3, + ], + 10 => [ + 'value' => 4, + ], ], + ], ], + 'columnName' => 'baz', + 'processedConfiguration' => [ + 'field' => 'baz', + Configuration::DO_NOT_SAVE_KEY => true, + ], + ], ]; } - /** - * @test - * @dataProvider columnConfigurationProvider - * @param array $additionalFieldsConfiguration - * @param array $columnConfiguration - * @param string $columnName - * @param array $processedConfiguration - */ + #[Test] #[DataProvider('columnConfigurationProvider')] public function setColumnConfigurationSetsConfigurationAndSortsTransformations(array $additionalFieldsConfiguration, array $columnConfiguration, string $columnName, array $processedConfiguration): void { if (count($additionalFieldsConfiguration) > 0) { @@ -307,18 +266,16 @@ public function setColumnConfigurationSetsConfigurationAndSortsTransformations(a ); } - /** - * @test - */ + #[Test] public function setAdditionalFieldsSetsFieldsAndCount(): void { $additionalFields = [ - 'foo' => [ - 'field' => 'foo', - ], - 'bar' => [ - 'field' => 'bar', - ], + 'foo' => [ + 'field' => 'foo', + ], + 'bar' => [ + 'field' => 'bar', + ], ]; $this->subject->setAdditionalFields($additionalFields); // When set, additional fields get extra data attached to them @@ -334,9 +291,7 @@ public function setAdditionalFieldsSetsFieldsAndCount(): void ); } - /** - * @test - */ + #[Test] public function setConnectorSetsConnector(): void { // Use a mock as full initialization requires to be in a functional testing environment @@ -355,9 +310,7 @@ public function setConnectorSetsConnector(): void ); } - /** - * @test - */ + #[Test] public function setCountAdditionalFieldsSetsCount(): void { $countAdditionalFields = 2; @@ -368,9 +321,7 @@ public function setCountAdditionalFieldsSetsCount(): void ); } - /** - * @test - */ + #[Test] public function setIndexSetsIndex(): void { $index = 2; @@ -381,9 +332,7 @@ public function setIndexSetsIndex(): void ); } - /** - * @test - */ + #[Test] public function setStoragePidSetsPid(): void { $storagePid = 2; @@ -394,9 +343,7 @@ public function setStoragePidSetsPid(): void ); } - /** - * @test - */ + #[Test] public function setTableSetsTable(): void { $table = 'tx_foo_bar'; @@ -407,7 +354,7 @@ public function setTableSetsTable(): void ); } - public function sortColumnsProvider(): array + public static function sortColumnsProvider(): array { return [ 'No sorting - output ordered by key, as per default' => [ @@ -417,7 +364,7 @@ public function sortColumnsProvider(): array 'cc' => 'baz', 'dd' => 'foo2', ], - 'sorting' => '', + 'order' => '', 'orderedColumns' => [ 'aa' => 'bar', 'bb' => 'foo', @@ -432,7 +379,7 @@ public function sortColumnsProvider(): array 'cc' => 'baz', 'dd' => 'foo2', ], - 'sorting' => 'dd, aa, bb, cc', + 'order' => 'dd, aa, bb, cc', 'orderedColumns' => [ 'dd' => 'foo2', 'aa' => 'bar', @@ -447,7 +394,7 @@ public function sortColumnsProvider(): array 'cc' => 'baz', 'dd' => 'foo2', ], - 'sorting' => 'bb, cc', + 'order' => 'bb, cc', 'orderedColumns' => [ 'bb' => 'foo', 'cc' => 'baz', @@ -462,7 +409,7 @@ public function sortColumnsProvider(): array 'cc' => 'baz', 'dd' => 'foo2', ], - 'sorting' => 'bb, ff, cc', + 'order' => 'bb, ff, cc', 'orderedColumns' => [ 'bb' => 'foo', 'cc' => 'baz', @@ -477,7 +424,7 @@ public function sortColumnsProvider(): array 'cc' => 'baz', 'dd' => 'foo2', ], - 'sorting' => 'bb, cc, bb', + 'order' => 'bb, cc, bb', 'orderedColumns' => [ 'bb' => 'foo', 'cc' => 'baz', @@ -488,13 +435,7 @@ public function sortColumnsProvider(): array ]; } - /** - * @test - * @dataProvider sortColumnsProvider - * @param array $columns - * @param string $order - * @param array $orderedColumns - */ + #[Test] #[DataProvider('sortColumnsProvider')] public function sortColumnsSortsColumns(array $columns, string $order, array $orderedColumns): void { self::assertSame( diff --git a/Tests/Unit/Domain/Model/DataTest.php b/Tests/Unit/Domain/Model/DataTest.php index fd398538..f4a5018e 100644 --- a/Tests/Unit/Domain/Model/DataTest.php +++ b/Tests/Unit/Domain/Model/DataTest.php @@ -1,5 +1,7 @@ subject = new Data(); } - /** - * @test - */ + #[Test] public function getRawDataInitiallyReturnsNull(): void { self::assertNull($this->subject->getRawData()); } - /** - * @test - */ + #[Test] public function setRawDataSetsRawData(): void { $this->subject->setRawData('foo'); @@ -54,9 +50,7 @@ public function setRawDataSetsRawData(): void ); } - /** - * @test - */ + #[Test] public function getExtraDataInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -65,9 +59,7 @@ public function getExtraDataInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function setExtraDataOverwritesExistingExtraData(): void { $this->subject->setExtraData(['foo']); @@ -78,9 +70,7 @@ public function setExtraDataOverwritesExistingExtraData(): void ); } - /** - * @test - */ + #[Test] public function addExtraDataAddsExtraData(): void { $this->subject->addExtraData('entry1', 'foo'); @@ -91,9 +81,7 @@ public function addExtraDataAddsExtraData(): void ); } - /** - * @test - */ + #[Test] public function getRecordsInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -102,9 +90,7 @@ public function getRecordsInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function setRecordsSetsRecords(): void { $this->subject->setRecords([1, 2]); @@ -114,9 +100,7 @@ public function setRecordsSetsRecords(): void ); } - /** - * @test - */ + #[Test] public function getDownloadableInitiallyReturnsFalse(): void { self::assertFalse( @@ -124,9 +108,7 @@ public function getDownloadableInitiallyReturnsFalse(): void ); } - /** - * @test - */ + #[Test] public function setDownloadableSetsBooleanValue(): void { $this->subject->setDownloadable(true); diff --git a/Tests/Unit/Domain/Model/Dto/ChildrenSortingTest.php b/Tests/Unit/Domain/Model/Dto/ChildrenSortingTest.php index 9e1808a4..fcded82f 100644 --- a/Tests/Unit/Domain/Model/Dto/ChildrenSortingTest.php +++ b/Tests/Unit/Domain/Model/Dto/ChildrenSortingTest.php @@ -1,5 +1,7 @@ subject = GeneralUtility::makeInstance(ChildrenSorting::class); } - /** - * @test - */ + #[Test] public function hasSortingInformationInitiallyReturnsFalse(): void { self::assertFalse( @@ -45,14 +44,14 @@ public function hasSortingInformationInitiallyReturnsFalse(): void ); } - public function hasSortingInformationProvider(): array + public static function hasSortingInformationProvider(): array { return [ 'one table - empty' => [ 'structure' => [ 'foo' => [], ], - 'result' => false, + 'expectedResult' => false, ], 'one table - one item' => [ 'structure' => [ @@ -64,7 +63,7 @@ public function hasSortingInformationProvider(): array ], ], ], - 'result' => true, + 'expectedResult' => true, ], 'two tables - one empty, one not' => [ 'structure' => [ @@ -77,15 +76,12 @@ public function hasSortingInformationProvider(): array ], 'bar' => [], ], - 'result' => true, + 'expectedResult' => true, ], ]; } - /** - * @test - * @dataProvider hasSortingInformationProvider - */ + #[Test] #[DataProvider('hasSortingInformationProvider')] public function hasSortingInformationInitiallyReturnsBooleanValue(array $structure, bool $expectedResult): void { foreach ($structure as $table => $items) { @@ -99,9 +95,7 @@ public function hasSortingInformationInitiallyReturnsBooleanValue(array $structu ); } - /** - * @test - */ + #[Test] public function getSortingInformationInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -110,9 +104,7 @@ public function getSortingInformationInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function getSortingInformationReturnsEmptyArrayAfterReset(): void { $this->subject->addSortingInformation('foo', 2, 'sorting', 1); @@ -123,9 +115,7 @@ public function getSortingInformationReturnsEmptyArrayAfterReset(): void ); } - /** - * @test - */ + #[Test] public function addSortingInformationExpandsArray(): void { $this->subject->addSortingInformation('foo', 2, 'sorting', 1); @@ -175,9 +165,7 @@ public function addSortingInformationExpandsArray(): void ); } - /** - * @test - */ + #[Test] public function replaceIdReplacesChildId(): void { $this->subject->addSortingInformation('foo', 'tempKey', 'sorting', 1); @@ -198,9 +186,7 @@ public function replaceIdReplacesChildId(): void ); } - /** - * @test - */ + #[Test] public function replaceAllNewIdsReplacesNewMarkers(): void { // "NEW" id, will be replaced diff --git a/Tests/Unit/Domain/Model/Dto/QueryParametersTest.php b/Tests/Unit/Domain/Model/Dto/QueryParametersTest.php index e9bdbbda..a4b1d9dc 100644 --- a/Tests/Unit/Domain/Model/Dto/QueryParametersTest.php +++ b/Tests/Unit/Domain/Model/Dto/QueryParametersTest.php @@ -1,5 +1,7 @@ subject = GeneralUtility::makeInstance(QueryParameters::class); } - /** - * @test - */ + #[Test] public function getDrawInitiallyReturnsZero(): void { self::assertSame( @@ -47,9 +46,7 @@ public function getDrawInitiallyReturnsZero(): void ); } - /** - * @test - */ + #[Test] public function getSearchInitiallyReturnsEmptyString(): void { self::assertSame( @@ -58,9 +55,7 @@ public function getSearchInitiallyReturnsEmptyString(): void ); } - /** - * @test - */ + #[Test] public function getSearchColumnsInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -69,9 +64,7 @@ public function getSearchColumnsInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function getLimitInitiallyReturnsZero(): void { self::assertSame( @@ -80,9 +73,7 @@ public function getLimitInitiallyReturnsZero(): void ); } - /** - * @test - */ + #[Test] public function getOffsetInitiallyReturnsZero(): void { self::assertSame( @@ -91,9 +82,7 @@ public function getOffsetInitiallyReturnsZero(): void ); } - /** - * @test - */ + #[Test] public function getOrderInitiallyReturnsEmptyString(): void { self::assertSame( @@ -102,9 +91,7 @@ public function getOrderInitiallyReturnsEmptyString(): void ); } - /** - * @test - */ + #[Test] public function getDirectionInitiallyReturnsDesc(): void { self::assertSame( @@ -113,9 +100,7 @@ public function getDirectionInitiallyReturnsDesc(): void ); } - /** - * @test - */ + #[Test] public function setDrawSetsValue(): void { $this->subject->setDraw(2); @@ -125,9 +110,7 @@ public function setDrawSetsValue(): void ); } - /** - * @test - */ + #[Test] public function setSearchSetsValue(): void { $this->subject->setSearch('foo'); @@ -137,25 +120,23 @@ public function setSearchSetsValue(): void ); } - /** - * @test - */ + #[Test] public function setSearchColumnsKeepsOnlySearchableColumns(): void { $this->subject->setSearchColumns( [ - [ - 'searchable' => 'true', - 'name' => 'foo', - ], - [ - 'searchable' => 'false', - 'name' => 'not me', - ], - [ - 'searchable' => 'true', - 'name' => 'bar', - ], + [ + 'searchable' => 'true', + 'name' => 'foo', + ], + [ + 'searchable' => 'false', + 'name' => 'not me', + ], + [ + 'searchable' => 'true', + 'name' => 'bar', + ], ] ); self::assertSame( @@ -164,9 +145,7 @@ public function setSearchColumnsKeepsOnlySearchableColumns(): void ); } - /** - * @test - */ + #[Test] public function setLimitSetsValue(): void { $this->subject->setLimit(2); @@ -176,9 +155,7 @@ public function setLimitSetsValue(): void ); } - /** - * @test - */ + #[Test] public function setOffsetSetsValue(): void { $this->subject->setOffset(2); @@ -188,9 +165,7 @@ public function setOffsetSetsValue(): void ); } - /** - * @test - */ + #[Test] public function setOrderSetsValue(): void { $this->subject->setOrder('foo'); @@ -200,34 +175,29 @@ public function setOrderSetsValue(): void ); } - public function directionValueProvider(): array + public static function directionValueProvider(): array { return [ - 'ASC is ASC' => [ - 'ASC', - QueryInterface::ORDER_ASCENDING, - ], - 'DESC is DESC' => [ - 'DESC', - QueryInterface::ORDER_DESCENDING, - ], - 'asc is DESC' => [ - 'asc', - QueryInterface::ORDER_DESCENDING, - ], - 'wathever is DESC' => [ - 'foo', - QueryInterface::ORDER_DESCENDING, - ], + 'ASC is ASC' => [ + 'value' => 'ASC', + 'expected' => QueryInterface::ORDER_ASCENDING, + ], + 'DESC is DESC' => [ + 'value' => 'DESC', + 'expected' => QueryInterface::ORDER_DESCENDING, + ], + 'asc is DESC' => [ + 'value' => 'asc', + 'expected' => QueryInterface::ORDER_DESCENDING, + ], + 'wathever is DESC' => [ + 'value' => 'foo', + 'expected' => QueryInterface::ORDER_DESCENDING, + ], ]; } - /** - * @test - * @dataProvider directionValueProvider - * @param string $value - * @param string $expected - */ + #[Test] #[DataProvider('directionValueProvider')] public function setDirectionSetsSanitizedValue(string $value, string $expected): void { $this->subject->setDirection($value); diff --git a/Tests/Unit/Domain/Model/ProcessedConfigurationTest.php b/Tests/Unit/Domain/Model/ProcessedConfigurationTest.php index 00fa5908..75f46a67 100644 --- a/Tests/Unit/Domain/Model/ProcessedConfigurationTest.php +++ b/Tests/Unit/Domain/Model/ProcessedConfigurationTest.php @@ -19,8 +19,9 @@ use Cobweb\ExternalImport\Domain\Model\ChildrenConfiguration; use Cobweb\ExternalImport\Domain\Model\ProcessedConfiguration; -use Nimut\TestingFramework\TestCase\UnitTestCase; +use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; class ProcessedConfigurationTest extends UnitTestCase { @@ -32,9 +33,7 @@ public function setUp(): void $this->subject = GeneralUtility::makeInstance(ProcessedConfiguration::class); } - /** - * @test - */ + #[Test] public function getFieldsExcludedFromInsertsInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -43,9 +42,7 @@ public function getFieldsExcludedFromInsertsInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function addFieldExcludedFromInsertsAddsColumn(): void { $this->subject->addFieldExcludedFromInserts('foo'); @@ -60,9 +57,7 @@ public function addFieldExcludedFromInsertsAddsColumn(): void ); } - /** - * @test - */ + #[Test] public function setFieldsExcludedFromInsertsSetsArray(): void { $this->subject->setFieldsExcludedFromInserts(['foo', 'bar']); @@ -72,9 +67,7 @@ public function setFieldsExcludedFromInsertsSetsArray(): void ); } - /** - * @test - */ + #[Test] public function getFieldsExcludedFromUpdatesInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -83,9 +76,7 @@ public function getFieldsExcludedFromUpdatesInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function addFieldExcludedFromUpdatesAddsColumn(): void { $this->subject->addFieldExcludedFromUpdates('foo'); @@ -100,9 +91,7 @@ public function addFieldExcludedFromUpdatesAddsColumn(): void ); } - /** - * @test - */ + #[Test] public function setFieldsExcludedFromUpdatesSetsArray(): void { $this->subject->setFieldsExcludedFromUpdates(['foo', 'bar']); @@ -112,9 +101,7 @@ public function setFieldsExcludedFromUpdatesSetsArray(): void ); } - /** - * @test - */ + #[Test] public function getChildColumnsInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -123,9 +110,7 @@ public function getChildColumnsInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function addChildColumnAddsChildrenConfigurationObject(): void { $childA = new ChildrenConfiguration(); @@ -144,9 +129,7 @@ public function addChildColumnAddsChildrenConfigurationObject(): void ); } - /** - * @test - */ + #[Test] public function setChildColumnsSetsChildrenConfigurationArrayt(): void { $childA = new ChildrenConfiguration(); @@ -160,9 +143,7 @@ public function setChildColumnsSetsChildrenConfigurationArrayt(): void ); } - /** - * @test - */ + #[Test] public function hasChildColumnsInitiallyReturnsFalse(): void { self::assertFalse( @@ -170,9 +151,7 @@ public function hasChildColumnsInitiallyReturnsFalse(): void ); } - /** - * @test - */ + #[Test] public function hasChildColumnsReturnsTrueAfterAddingColumn(): void { $this->subject->addChildColumn( @@ -184,9 +163,7 @@ public function hasChildColumnsReturnsTrueAfterAddingColumn(): void ); } - /** - * @test - */ + #[Test] public function getNullableColumnsInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -195,9 +172,7 @@ public function getNullableColumnsInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function setNullableColumnsSetsColumnsList(): void { $this->subject->setNullableColumns(['foo', 'bar']); @@ -207,9 +182,7 @@ public function setNullableColumnsSetsColumnsList(): void ); } - /** - * @test - */ + #[Test] public function addNullableColumnAddsColumnToList(): void { $this->subject->setNullableColumns(['foo']); @@ -220,9 +193,7 @@ public function addNullableColumnAddsColumnToList(): void ); } - /** - * @test - */ + #[Test] public function isNullableColumnReturnsBoolean(): void { $this->subject->setNullableColumns(['foo', 'bar']); diff --git a/Tests/Unit/Domain/Repository/TemporaryKeyRepositoryTest.php b/Tests/Unit/Domain/Repository/TemporaryKeyRepositoryTest.php index f7e4375a..9fdac148 100644 --- a/Tests/Unit/Domain/Repository/TemporaryKeyRepositoryTest.php +++ b/Tests/Unit/Domain/Repository/TemporaryKeyRepositoryTest.php @@ -1,5 +1,7 @@ subject->setTestMode(true); } - /** - * @test - */ + #[Test] public function hasTemporaryKeyInitiallyReturnsFalse(): void { self::assertFalse( @@ -46,9 +44,7 @@ public function hasTemporaryKeyInitiallyReturnsFalse(): void ); } - /** - * @test - */ + #[Test] public function hasTemporaryKeyReturnsTrueIfKeyExists(): void { $this->subject->addTemporaryKey( @@ -61,9 +57,7 @@ public function hasTemporaryKeyReturnsTrueIfKeyExists(): void ); } - /** - * @test - */ + #[Test] public function getTemporaryKeysInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -72,9 +66,7 @@ public function getTemporaryKeysInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function getTemporaryKeysReturnsArrayOfKeys(): void { $this->subject->resetForcedTemporaryKeySerial(); @@ -90,20 +82,18 @@ public function getTemporaryKeysReturnsArrayOfKeys(): void ); self::assertSame( [ - 'foo' => [ - 1 => 'NEW1', - ], - 'bar' => [ - 2 => 'NEW2', - ], + 'foo' => [ + 1 => 'NEW1', + ], + 'bar' => [ + 2 => 'NEW2', + ], ], $this->subject->getTemporaryKeys() ); } - /** - * @test - */ + #[Test] public function generateTemporaryKeyGeneratesSequenceInTestMode(): void { $this->subject->resetForcedTemporaryKeySerial(); @@ -117,9 +107,7 @@ public function generateTemporaryKeyGeneratesSequenceInTestMode(): void ); } - /** - * @test - */ + #[Test] public function getTemporaryKeyForValueInitiallyReturnsNull(): void { self::assertNull( @@ -127,9 +115,7 @@ public function getTemporaryKeyForValueInitiallyReturnsNull(): void ); } - /** - * @test - */ + #[Test] public function getTemporaryKeyForValueReturnsExpectedKeyForValueAndTable(): void { $this->subject->resetForcedTemporaryKeySerial(); diff --git a/Tests/Unit/Event/CmdmapPostprocessEventTest.php b/Tests/Unit/Event/CmdmapPostprocessEventTest.php index c0e1bb96..8727fd41 100644 --- a/Tests/Unit/Event/CmdmapPostprocessEventTest.php +++ b/Tests/Unit/Event/CmdmapPostprocessEventTest.php @@ -19,22 +19,16 @@ use Cobweb\ExternalImport\Event\CmdmapPostprocessEvent; use Cobweb\ExternalImport\Importer; -use Nimut\TestingFramework\TestCase\UnitTestCase; +use PHPUnit\Framework\Attributes\Test; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Test suite for the InsertRecordPreprocessEvent class */ class CmdmapPostprocessEventTest extends UnitTestCase { - /** - * @var CmdmapPostprocessEvent - */ protected CmdmapPostprocessEvent $subject; - - /** - * @var Importer - */ - protected $importer; + protected Importer $importer; public function setUp(): void { @@ -52,9 +46,7 @@ public function setUp(): void ); } - /** - * @test - */ + #[Test] public function getRecordsInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -63,9 +55,7 @@ public function getRecordsInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function getImporterInitiallyReturnsOriginalObject(): void { self::assertSame( diff --git a/Tests/Unit/Event/DatamapPostprocessEventTest.php b/Tests/Unit/Event/DatamapPostprocessEventTest.php index b30a93dc..f03641ca 100644 --- a/Tests/Unit/Event/DatamapPostprocessEventTest.php +++ b/Tests/Unit/Event/DatamapPostprocessEventTest.php @@ -19,22 +19,16 @@ use Cobweb\ExternalImport\Event\DatamapPostprocessEvent; use Cobweb\ExternalImport\Importer; -use Nimut\TestingFramework\TestCase\UnitTestCase; +use PHPUnit\Framework\Attributes\Test; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Test suite for the InsertRecordPreprocessEvent class */ class DatamapPostprocessEventTest extends UnitTestCase { - /** - * @var DatamapPostprocessEvent - */ protected DatamapPostprocessEvent $subject; - - /** - * @var Importer - */ - protected $importer; + protected Importer $importer; public function setUp(): void { @@ -53,9 +47,7 @@ public function setUp(): void ); } - /** - * @test - */ + #[Test] public function getDataInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -64,9 +56,7 @@ public function getDataInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function getStructuredDataInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -75,9 +65,7 @@ public function getStructuredDataInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function getImporterInitiallyReturnsOriginalObject(): void { self::assertSame( diff --git a/Tests/Unit/Event/DeleteRecordPreprocessEventTest.php b/Tests/Unit/Event/DeleteRecordPreprocessEventTest.php index 78feb1db..466aff71 100644 --- a/Tests/Unit/Event/DeleteRecordPreprocessEventTest.php +++ b/Tests/Unit/Event/DeleteRecordPreprocessEventTest.php @@ -19,22 +19,16 @@ use Cobweb\ExternalImport\Event\DeleteRecordsPreprocessEvent; use Cobweb\ExternalImport\Importer; -use Nimut\TestingFramework\TestCase\UnitTestCase; +use PHPUnit\Framework\Attributes\Test; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Test suite for the InsertRecordPreprocessEvent class */ class DeleteRecordPreprocessEventTest extends UnitTestCase { - /** - * @var DeleteRecordsPreprocessEvent - */ protected DeleteRecordsPreprocessEvent $subject; - - /** - * @var Importer - */ - protected $importer; + protected Importer $importer; public function setUp(): void { @@ -52,9 +46,7 @@ public function setUp(): void ); } - /** - * @test - */ + #[Test] public function getRecordsInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -63,9 +55,7 @@ public function getRecordsInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function setRecordsSetsRecords(): void { $record = ['foo', 'bar']; @@ -76,9 +66,7 @@ public function setRecordsSetsRecords(): void ); } - /** - * @test - */ + #[Test] public function getImporterInitiallyReturnsOriginalObject(): void { self::assertSame( diff --git a/Tests/Unit/Event/InsertRecordPreprocessEventTest.php b/Tests/Unit/Event/InsertRecordPreprocessEventTest.php index a0943132..7ff9b559 100644 --- a/Tests/Unit/Event/InsertRecordPreprocessEventTest.php +++ b/Tests/Unit/Event/InsertRecordPreprocessEventTest.php @@ -19,22 +19,16 @@ use Cobweb\ExternalImport\Event\InsertRecordPreprocessEvent; use Cobweb\ExternalImport\Importer; -use Nimut\TestingFramework\TestCase\UnitTestCase; +use PHPUnit\Framework\Attributes\Test; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Test suite for the InsertRecordPreprocessEvent class */ class InsertRecordPreprocessEventTest extends UnitTestCase { - /** - * @var InsertRecordPreprocessEvent - */ protected InsertRecordPreprocessEvent $subject; - - /** - * @var Importer - */ - protected $importer; + protected Importer $importer; public function setUp(): void { @@ -52,9 +46,7 @@ public function setUp(): void ); } - /** - * @test - */ + #[Test] public function getRecordInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -63,9 +55,7 @@ public function getRecordInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function setRecordSetsRecord(): void { $record = ['foo', 'bar']; @@ -76,9 +66,7 @@ public function setRecordSetsRecord(): void ); } - /** - * @test - */ + #[Test] public function getImporterInitiallyReturnsOriginalObject(): void { self::assertSame( diff --git a/Tests/Unit/Event/ProcessConnectorParametersEventTest.php b/Tests/Unit/Event/ProcessConnectorParametersEventTest.php index 1241b5d9..02930de7 100644 --- a/Tests/Unit/Event/ProcessConnectorParametersEventTest.php +++ b/Tests/Unit/Event/ProcessConnectorParametersEventTest.php @@ -19,21 +19,15 @@ use Cobweb\ExternalImport\Domain\Model\Configuration; use Cobweb\ExternalImport\Event\ProcessConnectorParametersEvent; -use Nimut\TestingFramework\TestCase\UnitTestCase; +use PHPUnit\Framework\Attributes\Test; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Test suite for the ProcessConnectorParametersEvent class */ class ProcessConnectorParametersEventTest extends UnitTestCase { - /** - * @var ProcessConnectorParametersEvent - */ protected ProcessConnectorParametersEvent $subject; - - /** - * @var Configuration - */ protected Configuration $configuration; public function setUp(): void @@ -46,9 +40,7 @@ public function setUp(): void ); } - /** - * @test - */ + #[Test] public function getParametersInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -57,9 +49,7 @@ public function getParametersInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function setParametersSetsParameters(): void { $parameters = ['foo' => 'bar']; @@ -70,9 +60,7 @@ public function setParametersSetsParameters(): void ); } - /** - * @test - */ + #[Test] public function getExternalConfigurationInitiallyReturnsOriginalConfiguration(): void { self::assertSame( diff --git a/Tests/Unit/Event/UpdateRecordPreprocessEventTest.php b/Tests/Unit/Event/UpdateRecordPreprocessEventTest.php index 9b941783..1d97ecc7 100644 --- a/Tests/Unit/Event/UpdateRecordPreprocessEventTest.php +++ b/Tests/Unit/Event/UpdateRecordPreprocessEventTest.php @@ -19,22 +19,16 @@ use Cobweb\ExternalImport\Event\UpdateRecordPreprocessEvent; use Cobweb\ExternalImport\Importer; -use Nimut\TestingFramework\TestCase\UnitTestCase; +use PHPUnit\Framework\Attributes\Test; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Test suite for the UpdateRecordPreprocessEvent class */ class UpdateRecordPreprocessEventTest extends UnitTestCase { - /** - * @var UpdateRecordPreprocessEvent - */ protected UpdateRecordPreprocessEvent $subject; - - /** - * @var Importer - */ - protected $importer; + protected Importer $importer; public function setUp(): void { @@ -53,9 +47,7 @@ public function setUp(): void ); } - /** - * @test - */ + #[Test] public function getUidInitiallyReturnsInteger(): void { self::assertSame( @@ -64,9 +56,7 @@ public function getUidInitiallyReturnsInteger(): void ); } - /** - * @test - */ + #[Test] public function getRecordInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -75,9 +65,7 @@ public function getRecordInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function setRecordSetsRecord(): void { $record = ['foo', 'bar']; @@ -88,9 +76,7 @@ public function setRecordSetsRecord(): void ); } - /** - * @test - */ + #[Test] public function getImporterInitiallyReturnsOriginalObject(): void { self::assertSame( diff --git a/Tests/Unit/Handler/ArrayHandlerTest.php b/Tests/Unit/Handler/ArrayHandlerTest.php index e5942376..1b05d14e 100644 --- a/Tests/Unit/Handler/ArrayHandlerTest.php +++ b/Tests/Unit/Handler/ArrayHandlerTest.php @@ -20,17 +20,16 @@ use Cobweb\ExternalImport\Domain\Model\Configuration; use Cobweb\ExternalImport\Handler\ArrayHandler; use Cobweb\ExternalImport\Importer; -use Nimut\TestingFramework\TestCase\UnitTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Core\EventDispatcher\EventDispatcher; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Test suite for the ArrayHandler class. */ class ArrayHandlerTest extends UnitTestCase { - /** - * @var ArrayHandler - */ protected ArrayHandler $subject; public function setUp(): void @@ -41,7 +40,7 @@ public function setUp(): void ); } - public function getValueSuccessProvider(): array + public static function getValueSuccessProvider(): array { $sampleStructureComplexity1 = [ 'test' => [ @@ -513,10 +512,7 @@ public function getValueSuccessProvider(): array ]; } - /** - * @test - * @dataProvider getValueSuccessProvider - */ + #[Test] #[DataProvider('getValueSuccessProvider')] public function getValueReturnsValueIfFound(array $record, array $configuration, mixed $result): void { $value = $this->subject->getValue($record, $configuration); @@ -526,7 +522,7 @@ public function getValueReturnsValueIfFound(array $record, array $configuration, ); } - public function getValueFailsWithInvalidArgumentExceptionProvider(): array + public static function getValueFailsWithInvalidArgumentExceptionProvider(): array { return [ 'direct simple value' => [ @@ -608,19 +604,14 @@ public function getValueFailsWithInvalidArgumentExceptionProvider(): array ]; } - /** - * @test - * @dataProvider getValueFailsWithInvalidArgumentExceptionProvider - * @param array $record - * @param array $configuration - */ + #[Test] #[DataProvider('getValueFailsWithInvalidArgumentExceptionProvider')] public function getValueThrowsInvalidArgumentExceptionIfValueNotFound(array $record, array $configuration): void { $this->expectException(\InvalidArgumentException::class); $value = $this->subject->getValue($record, $configuration); } - public function getSubstructureProvider(): array + public static function getSubstructureProvider(): array { return [ [ @@ -665,13 +656,7 @@ public function getSubstructureProvider(): array ]; } - /** - * @test - * @dataProvider getSubstructureProvider - * @param array $structure - * @param array $configuration - * @param array $result - */ + #[Test] #[DataProvider('getSubstructureProvider')] public function getSubstructureValuesReturnsExpectedRows(array $structure, array $configuration, array $result): void { self::assertSame( @@ -680,7 +665,7 @@ public function getSubstructureValuesReturnsExpectedRows(array $structure, array ); } - public function rawDataProvider(): array + public static function rawDataProvider(): array { return [ 'empty raw data' => [ @@ -856,12 +841,9 @@ public function rawDataProvider(): array } /** - * @test - * @param array $generalConfiguration - * @param array $rawData - * @param array $expectedStructure - * @dataProvider rawDataProvider + * @throws \PHPUnit\Framework\MockObject\Exception */ + #[Test] #[DataProvider('rawDataProvider')] public function handleDataReturnsStructureData(array $generalConfiguration, array $rawData, array $expectedStructure): void { $configuration = $this->createMock(Configuration::class); diff --git a/Tests/Unit/Handler/XmlHandlerTest.php b/Tests/Unit/Handler/XmlHandlerTest.php index cf7e8f9d..234bacfd 100644 --- a/Tests/Unit/Handler/XmlHandlerTest.php +++ b/Tests/Unit/Handler/XmlHandlerTest.php @@ -18,17 +18,16 @@ */ use Cobweb\ExternalImport\Handler\XmlHandler; -use Nimut\TestingFramework\TestCase\UnitTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Core\EventDispatcher\EventDispatcher; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Test suite for the XmlHandler class. */ class XmlHandlerTest extends UnitTestCase { - /** - * @var XmlHandler - */ protected XmlHandler $subject; public function setUp(): void @@ -39,7 +38,7 @@ public function setUp(): void ); } - public function getValueSuccessProvider(): array + public static function getValueSuccessProvider(): array { return [ 'fixed value - number zero' => [ @@ -103,10 +102,9 @@ public function getValueSuccessProvider(): array } /** - * @test - * @dataProvider getValueSuccessProvider * @throws \Exception */ + #[Test] #[DataProvider('getValueSuccessProvider')] public function getValueReturnsValueIfFound(string $structure, array $configuration, mixed $result): void { // Load the XML into a DOM object @@ -121,7 +119,7 @@ public function getValueReturnsValueIfFound(string $structure, array $configurat ); } - public function getSubstructureProvider(): array + public static function getSubstructureProvider(): array { return [ [ @@ -153,13 +151,9 @@ public function getSubstructureProvider(): array } /** - * @test - * @dataProvider getSubstructureProvider - * @param string $structure - * @param array $configuration - * @param array $result * @throws \Exception */ + #[Test] #[DataProvider('getSubstructureProvider')] public function getSubstructureValuesReturnsExpectedRows(string $structure, array $configuration, array $result): void { // Load the XML into a DOM object diff --git a/Tests/Unit/ImporterTest.php b/Tests/Unit/ImporterTest.php index 8d9a2d57..ee3a8a9a 100644 --- a/Tests/Unit/ImporterTest.php +++ b/Tests/Unit/ImporterTest.php @@ -1,5 +1,7 @@ createMock(ExtensionConfiguration::class); + $extensionConfiguration->method('get') + ->willReturn( + [ + 'debug' => 0, + ] + ); $this->subject = GeneralUtility::makeInstance( Importer::class, - $this->getAccessibleMock(ConfigurationRepository::class), + $this->getAccessibleMock( + ConfigurationRepository::class, + [], + [], + '', + // Don't call the original constructor to avoid a cascade of dependencies + false + ), $this->getAccessibleMock( ReportingUtility::class, [], @@ -51,32 +67,12 @@ protected function setUp(): void ), $this->getAccessibleMock(UidRepository::class), $this->getAccessibleMock(TemporaryKeyRepository::class), - new ExtensionConfiguration() + $extensionConfiguration ); + $this->resetSingletonInstances = true; } - /** - * @test - */ - public function getExtensionConfigurationInitiallyReturnsDefaultConfiguration(): void - { - self::assertSame( - [ - 'storagePID' => '0', - 'logStorage' => '0', - 'timelimit' => '-1', - 'reportEmail' => '', - 'reportSubject' => '', - 'debug' => '0', - 'disableLog' => '0', - ], - $this->subject->getExtensionConfiguration() - ); - } - - /** - * @test - */ + #[Test] public function getExternalConfigurationInitiallyReturnsNull(): void { self::assertNull( @@ -84,24 +80,22 @@ public function getExternalConfigurationInitiallyReturnsNull(): void ); } - /** - * @test - */ + #[Test] public function getMessagesInitiallyReturnsEmptyStructure(): void { self::assertSame( [ ContextualFeedbackSeverity::ERROR->value => [], ContextualFeedbackSeverity::WARNING->value => [], + ContextualFeedbackSeverity::INFO->value => [], + ContextualFeedbackSeverity::NOTICE->value => [], ContextualFeedbackSeverity::OK->value => [], ], $this->subject->getMessages() ); } - /** - * @test - */ + #[Test] public function addMessagesAddsMessage(): void { $this->subject->addMessage('foo', ContextualFeedbackSeverity::WARNING); @@ -111,9 +105,7 @@ public function addMessagesAddsMessage(): void ); } - /** - * @test - */ + #[Test] public function resetMessagesInitiallyPreparesEmptyStructure(): void { $this->subject->addMessage('foo', ContextualFeedbackSeverity::WARNING); @@ -130,9 +122,7 @@ public function resetMessagesInitiallyPreparesEmptyStructure(): void ); } - /** - * @test - */ + #[Test] public function getContextInitiallyReturnsManualContext(): void { self::assertSame( @@ -141,9 +131,7 @@ public function getContextInitiallyReturnsManualContext(): void ); } - /** - * @test - */ + #[Test] public function setContextSetsContext(): void { $this->subject->setContext('cli'); @@ -153,43 +141,33 @@ public function setContextSetsContext(): void ); } - /** - * @test - */ + #[Test] public function isDebugInitiallyReturnsFalse(): void { self::assertFalse($this->subject->isDebug()); } - /** - * @test - */ + #[Test] public function setDebugSetsDebugFlag(): void { $this->subject->setDebug(true); self::assertTrue($this->subject->isDebug()); } - /** - * @test - */ + #[Test] public function isVerboseInitiallyReturnsFalse(): void { self::assertFalse($this->subject->isVerbose()); } - /** - * @test - */ + #[Test] public function setVerboseSetsVerboseFlag(): void { $this->subject->setVerbose(true); self::assertTrue($this->subject->isVerbose()); } - /** - * @test - */ + #[Test] public function isTestModeInitiallyReturnsFalse(): void { self::assertFalse( @@ -197,9 +175,7 @@ public function isTestModeInitiallyReturnsFalse(): void ); } - /** - * @test - */ + #[Test] public function setTestModeSetsTestMode(): void { $this->subject->setTestMode(true); @@ -208,17 +184,13 @@ public function setTestModeSetsTestMode(): void ); } - /** - * @test - */ + #[Test] public function isPreviewInitiallyReturnsFalse(): void { self::assertFalse($this->subject->isPreview()); } - /** - * @test - */ + #[Test] public function getPreviewStepInitiallyReturnsEmptyString(): void { self::assertSame( @@ -227,9 +199,7 @@ public function getPreviewStepInitiallyReturnsEmptyString(): void ); } - /** - * @test - */ + #[Test] public function setPreviewStepSetsPreviewStep(): void { $this->subject->setPreviewStep('foo'); @@ -239,22 +209,20 @@ public function setPreviewStepSetsPreviewStep(): void ); } - /** - * @test - */ + #[Test] public function getPreviewDataInitiallyReturnsNull(): void { self::assertNull($this->subject->getPreviewData()); } - public function previewDataProvider(): array + public static function previewDataProvider(): array { return [ 'string' => [ - 'foo', + 'data' => 'foo', ], 'array' => [ - [ + 'data' => [ 'name' => 'Foo', 'title' => 'Bar', ], @@ -262,10 +230,7 @@ public function previewDataProvider(): array ]; } - /** - * @test - * @dataProvider previewDataProvider - */ + #[Test] #[DataProvider('previewDataProvider')] public function setPreviewDataSetsPreviewData(mixed $data): void { $this->subject->setPreviewData($data); @@ -275,9 +240,7 @@ public function setPreviewDataSetsPreviewData(mixed $data): void ); } - /** - * @test - */ + #[Test] public function resetPreviewDataSetsPreviewDataToNull(): void { $this->subject->resetPreviewData(); @@ -286,9 +249,7 @@ public function resetPreviewDataSetsPreviewDataToNull(): void ); } - /** - * @test - */ + #[Test] public function getStartTimeInitiallyReturnsZero(): void { self::assertEquals( @@ -297,9 +258,7 @@ public function getStartTimeInitiallyReturnsZero(): void ); } - /** - * @test - */ + #[Test] public function setStartTimeSetsStartTime(): void { $now = time(); @@ -310,9 +269,7 @@ public function setStartTimeSetsStartTime(): void ); } - /** - * @test - */ + #[Test] public function getEndTimeInitiallyReturnsZero(): void { self::assertEquals( @@ -321,9 +278,7 @@ public function getEndTimeInitiallyReturnsZero(): void ); } - /** - * @test - */ + #[Test] public function setEndTimeSetsEndTime(): void { $now = time(); diff --git a/Tests/Unit/Step/CheckPermissionsStepTest.php b/Tests/Unit/Step/CheckPermissionsStepTest.php index 11ab3475..0c4120da 100644 --- a/Tests/Unit/Step/CheckPermissionsStepTest.php +++ b/Tests/Unit/Step/CheckPermissionsStepTest.php @@ -1,5 +1,7 @@ subject = GeneralUtility::makeInstance(CheckPermissionsStep::class); } - /** - * @test - */ + #[Test] public function getDataInitiallyReturnsNull(): void { self::assertNull( @@ -47,9 +46,7 @@ public function getDataInitiallyReturnsNull(): void ); } - /** - * @test - */ + #[Test] public function setDataSetsDataObject(): void { $data = new Data(); @@ -60,9 +57,7 @@ public function setDataSetsDataObject(): void ); } - /** - * @test - */ + #[Test] public function isAbortFlagInitiallyReturnsFalse(): void { self::assertFalse( @@ -70,9 +65,7 @@ public function isAbortFlagInitiallyReturnsFalse(): void ); } - /** - * @test - */ + #[Test] public function setAbortFlagSetsBooleanFlag(): void { $this->subject->setAbortFlag(true); @@ -81,9 +74,7 @@ public function setAbortFlagSetsBooleanFlag(): void ); } - /** - * @test - */ + #[Test] public function getParametersInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -92,9 +83,7 @@ public function getParametersInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function setParametersSetsArray(): void { $this->subject->setParameters( @@ -106,34 +95,28 @@ public function setParametersSetsArray(): void ); } - public function parametersProvider(): array + public static function parametersProvider(): array { return [ - 'initially returns null - no matter what key' => [ - 'parameters' => null, - 'key' => 'foo', - 'expected' => null, - ], - 'returns expected value with valid key' => [ - 'parameters' => ['foo' => 'bar'], - 'key' => 'foo', - 'expected' => 'bar', - ], - 'returns null with invalid key' => [ - 'parameters' => ['foo' => 'bar'], - 'key' => 'baz', - 'expected' => null, - ], + 'initially returns null - no matter what key' => [ + 'parameters' => null, + 'key' => 'foo', + 'expected' => null, + ], + 'returns expected value with valid key' => [ + 'parameters' => ['foo' => 'bar'], + 'key' => 'foo', + 'expected' => 'bar', + ], + 'returns null with invalid key' => [ + 'parameters' => ['foo' => 'bar'], + 'key' => 'baz', + 'expected' => null, + ], ]; } - /** - * @param $parameters - * @param $key - * @param $expected - * @test - * @dataProvider parametersProvider - */ + #[Test] #[DataProvider('parametersProvider')] public function getParameterReturnsExpectedValueForKey($parameters, $key, $expected): void { if (is_array($parameters)) { diff --git a/Tests/Unit/Step/StoreDataStepTest.php b/Tests/Unit/Step/StoreDataStepTest.php index 1e745eb6..bd7dc3f8 100644 --- a/Tests/Unit/Step/StoreDataStepTest.php +++ b/Tests/Unit/Step/StoreDataStepTest.php @@ -1,5 +1,7 @@ [ - [ - 34 => [ - 'title' => 'Foo', - 'pid' => 23, - ], - 42 => [ - 'title' => 'Bar', - 'pid' => 34, - ], - ], - [ - 34 => [ - 'title' => 'Foo', - 'pid' => 23, - ], - 42 => [ - 'title' => 'Bar', - 'pid' => 34, - ], - ], + 'No new pages - no sorting needed' => [ + 'input' => [ + 34 => [ + 'title' => 'Foo', + 'pid' => 23, + ], + 42 => [ + 'title' => 'Bar', + 'pid' => 34, + ], + ], + 'expected' => [ + 34 => [ + 'title' => 'Foo', + 'pid' => 23, + ], + 42 => [ + 'title' => 'Bar', + 'pid' => 34, + ], + ], + ], + 'New pages, not nested - no sorting needed' => [ + 'input' => [ + 'NEW1' => [ + 'title' => 'Parent 1', + 'pid' => 4, + ], + 'NEW2' => [ + 'title' => 'Parent 2', + 'pid' => 4, + ], + 'NEW3' => [ + 'title' => 'Parent 3', + 'pid' => 10, + ], + ], + 'expected' => [ + 'NEW1' => [ + 'title' => 'Parent 1', + 'pid' => 4, + ], + 'NEW2' => [ + 'title' => 'Parent 2', + 'pid' => 4, + ], + 'NEW3' => [ + 'title' => 'Parent 3', + 'pid' => 10, + ], + ], + ], + 'New pages, nested' => [ + 'input' => [ + 'NEW1' => [ + 'title' => 'Parent 1', + 'pid' => 0, + ], + 'NEW2' => [ + 'title' => 'Child 1.1', + 'pid' => 'NEW1', + ], + 'NEW3' => [ + 'title' => 'Child 1.2', + 'pid' => 'NEW1', + ], + 'NEW4' => [ + 'title' => 'Parent 2', + 'pid' => 0, + ], + 'NEW5' => [ + 'title' => 'Child 2.1', + 'pid' => 'NEW4', + ], + 'NEW6' => [ + 'title' => 'Child 2.1.1', + 'pid' => 'NEW5', + ], + 'NEW7' => [ + 'title' => 'Child 2.2', + 'pid' => 'NEW4', + ], ], - 'New pages, not nested - no sorting needed' => [ - [ - 'NEW1' => [ - 'title' => 'Parent 1', - 'pid' => 4, - ], - 'NEW2' => [ - 'title' => 'Parent 2', - 'pid' => 4, - ], - 'NEW3' => [ - 'title' => 'Parent 3', - 'pid' => 10, - ], - ], - [ - 'NEW1' => [ - 'title' => 'Parent 1', - 'pid' => 4, - ], - 'NEW2' => [ - 'title' => 'Parent 2', - 'pid' => 4, - ], - 'NEW3' => [ - 'title' => 'Parent 3', - 'pid' => 10, - ], - ], + 'expected' => [ + 'NEW6' => [ + 'title' => 'Child 2.1.1', + 'pid' => 'NEW5', + ], + 'NEW2' => [ + 'title' => 'Child 1.1', + 'pid' => 'NEW1', + ], + 'NEW3' => [ + 'title' => 'Child 1.2', + 'pid' => 'NEW1', + ], + 'NEW5' => [ + 'title' => 'Child 2.1', + 'pid' => 'NEW4', + ], + 'NEW7' => [ + 'title' => 'Child 2.2', + 'pid' => 'NEW4', + ], + 'NEW1' => [ + 'title' => 'Parent 1', + 'pid' => 0, + ], + 'NEW4' => [ + 'title' => 'Parent 2', + 'pid' => 0, + ], ], - 'New pages, nested' => [ - [ - 'NEW1' => [ - 'title' => 'Parent 1', - 'pid' => 0, - ], - 'NEW2' => [ - 'title' => 'Child 1.1', - 'pid' => 'NEW1', - ], - 'NEW3' => [ - 'title' => 'Child 1.2', - 'pid' => 'NEW1', - ], - 'NEW4' => [ - 'title' => 'Parent 2', - 'pid' => 0, - ], - 'NEW5' => [ - 'title' => 'Child 2.1', - 'pid' => 'NEW4', - ], - 'NEW6' => [ - 'title' => 'Child 2.1.1', - 'pid' => 'NEW5', - ], - 'NEW7' => [ - 'title' => 'Child 2.2', - 'pid' => 'NEW4', - ], - ], - [ - 'NEW6' => [ - 'title' => 'Child 2.1.1', - 'pid' => 'NEW5', - ], - 'NEW2' => [ - 'title' => 'Child 1.1', - 'pid' => 'NEW1', - ], - 'NEW3' => [ - 'title' => 'Child 1.2', - 'pid' => 'NEW1', - ], - 'NEW5' => [ - 'title' => 'Child 2.1', - 'pid' => 'NEW4', - ], - 'NEW7' => [ - 'title' => 'Child 2.2', - 'pid' => 'NEW4', - ], - 'NEW1' => [ - 'title' => 'Parent 1', - 'pid' => 0, - ], - 'NEW4' => [ - 'title' => 'Parent 2', - 'pid' => 0, - ], - ], + ], + 'Page updated to new parent' => [ + 'input' => [ + 24 => [ + 'title' => 'Existing page', + 'pid' => 'NEW1', + ], + 'NEW1' => [ + 'title' => 'Parent 1', + 'pid' => 0, + ], ], - 'Page updated to new parent' => [ - [ - 24 => [ - 'title' => 'Existing page', - 'pid' => 'NEW1', - ], - 'NEW1' => [ - 'title' => 'Parent 1', - 'pid' => 0, - ], - ], - [ - 24 => [ - 'title' => 'Existing page', - 'pid' => 'NEW1', - ], - 'NEW1' => [ - 'title' => 'Parent 1', - 'pid' => 0, - ], - ], + 'expected' => [ + 24 => [ + 'title' => 'Existing page', + 'pid' => 'NEW1', + ], + 'NEW1' => [ + 'title' => 'Parent 1', + 'pid' => 0, + ], ], + ], ]; } - /** - * @param array $input - * @param array $expected - * @test - * @dataProvider sortPagesProvider - */ + #[Test] #[DataProvider('sortPagesProvider')] public function sortPagesDataSortsParentAndChildren(array $input, array $expected): void { $sortedData = $this->subject->sortPagesData($input); diff --git a/Tests/Unit/Utility/CsvUtilityTest.php b/Tests/Unit/Utility/CsvUtilityTest.php index b6477658..93f1257d 100644 --- a/Tests/Unit/Utility/CsvUtilityTest.php +++ b/Tests/Unit/Utility/CsvUtilityTest.php @@ -18,8 +18,10 @@ */ use Cobweb\ExternalImport\Utility\CsvUtility; -use Nimut\TestingFramework\TestCase\UnitTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; class CsvUtilityTest extends UnitTestCase { @@ -27,10 +29,11 @@ class CsvUtilityTest extends UnitTestCase public function setUp(): void { + parent::setUp(); $this->subject = GeneralUtility::makeInstance(CsvUtility::class); } - public function arrayDataProvider(): array + public static function arrayDataProvider(): array { return [ 'simple case - all values for all indices' => [ @@ -112,10 +115,7 @@ public function arrayDataProvider(): array ]; } - /** - * @test - * @dataProvider arrayDataProvider - */ + #[Test] #[DataProvider('arrayDataProvider')] public function ensureCompleteStructureCompletesStructureAsNeeded(array $input, array $output): void { $result = $this->subject->ensureCompleteStructure($input); diff --git a/Tests/Unit/Utility/MappingUtilityTest.php b/Tests/Unit/Utility/MappingUtilityTest.php index 98b73584..67133307 100644 --- a/Tests/Unit/Utility/MappingUtilityTest.php +++ b/Tests/Unit/Utility/MappingUtilityTest.php @@ -1,5 +1,7 @@ mappingUtility = GeneralUtility::makeInstance(MappingUtility::class); } /** * Provide data for soft matching with strpos * (currently provides only one data set, but could provide more in the future) - * - * @return array */ - public function mappingTestWithStrposProvider(): array + public static function mappingTestWithStrposProvider(): array { return [ - 'australia' => [ - 'inputData' => 'Australia', - 'mappingTable' => [ - 'Commonwealth of Australia' => 'AU', - 'Kingdom of Spain' => 'ES', - ], - 'mappingConfiguration' => [ - 'matchMethod' => 'strpos', - 'matchSymmetric' => false, - ], - 'result' => 'AU', + 'australia' => [ + 'inputData' => 'Australia', + 'mappingTable' => [ + 'Commonwealth of Australia' => 'AU', + 'Kingdom of Spain' => 'ES', + ], + 'mappingConfiguration' => [ + 'matchMethod' => 'strpos', + 'matchSymmetric' => false, ], + 'expectedResult' => 'AU', + ], ]; } - /** - * Test soft-matching method with strpos - * - * @test - * @dataProvider mappingTestWithStrposProvider - * @param string $inputData - * @param array $mappingTable - * @param array $mappingConfiguration - * @param string $expectedResult - */ + #[Test] #[DataProvider('mappingTestWithStrposProvider')] public function matchWordsWithStrposNotSymmetric(string $inputData, array $mappingTable, array $mappingConfiguration, string $expectedResult): void { $actualResult = $this->mappingUtility->matchSingleField($inputData, $mappingConfiguration, $mappingTable); @@ -77,39 +66,28 @@ public function matchWordsWithStrposNotSymmetric(string $inputData, array $mappi } /** - * Provide data for soft matching with strpos + * Provide data for soft matching with strpos with symmetric matching * (currently provides only one data set, but could provide more in the future) - * - * @return array */ - public function mappingTestWithStrposSymmetricProvider(): array + public static function mappingTestWithStrposSymmetricProvider(): array { return [ - 'australia' => [ - 'inputData' => 'Commonwealth of Australia', - 'mappingTable' => [ - 'Australia' => 'AU', - 'Spain' => 'ES', - ], - 'mappingConfiguration' => [ - 'matchMethod' => 'strpos', - 'matchSymmetric' => true, - ], - 'result' => 'AU', + 'australia' => [ + 'inputData' => 'Commonwealth of Australia', + 'mappingTable' => [ + 'Australia' => 'AU', + 'Spain' => 'ES', ], + 'mappingConfiguration' => [ + 'matchMethod' => 'strpos', + 'matchSymmetric' => true, + ], + 'expectedResult' => 'AU', + ], ]; } - /** - * Test soft-matching method with strpos and symmetric flag - * - * @test - * @dataProvider mappingTestWithStrposSymmetricProvider - * @param string $inputData - * @param array $mappingTable - * @param array $mappingConfiguration - * @param string $expectedResult - */ + #[Test] #[DataProvider('mappingTestWithStrposSymmetricProvider')] public function matchWordsWithStrposSymmetric(string $inputData, array $mappingTable, array $mappingConfiguration, string $expectedResult): void { $actualResult = $this->mappingUtility->matchSingleField($inputData, $mappingConfiguration, $mappingTable); @@ -117,46 +95,38 @@ public function matchWordsWithStrposSymmetric(string $inputData, array $mappingT } /** - * Provide data for soft matching with strpos - * - * @return array + * Provide data for soft matching with strpos that will not match */ - public function mappingTestWithStrposWithBadMappingTableProvider(): array + public static function mappingTestWithStrposWithBadMappingTableProvider(): array { return [ // Case doesn't match in this data set 'wrong case' => [ - 'inputData' => 'australia', - 'mappingTable' => [ - 'Commonwealth of Australia' => 'AU', - 'Kingdom of Spain' => 'ES', - ], - 'mappingConfiguration' => [ - 'matchMethod' => 'strpos', - 'matchSymmetric' => false, - ], + 'inputData' => 'australia', + 'mappingTable' => [ + 'Commonwealth of Australia' => 'AU', + 'Kingdom of Spain' => 'ES', + ], + 'mappingConfiguration' => [ + 'matchMethod' => 'strpos', + 'matchSymmetric' => false, + ], ], 'no matching data' => [ - 'inputData' => 'Swaziland', - 'mappingTable' => [ - 'Commonwealth of Australia' => 'AU', - 'Kingdom of Spain' => 'ES', - ], - 'mappingConfiguration' => [ - 'matchMethod' => 'strpos', - 'matchSymmetric' => false, - ], + 'inputData' => 'Swaziland', + 'mappingTable' => [ + 'Commonwealth of Australia' => 'AU', + 'Kingdom of Spain' => 'ES', + ], + 'mappingConfiguration' => [ + 'matchMethod' => 'strpos', + 'matchSymmetric' => false, + ], ], ]; } - /** - * @test - * @dataProvider mappingTestWithStrposWithBadMappingTableProvider - * @param string $inputData - * @param array $mappingTable - * @param array $mappingConfiguration - */ + #[Test] #[DataProvider('mappingTestWithStrposWithBadMappingTableProvider')] public function failMatchWordsWithStrposNotSymmetric(string $inputData, array $mappingTable, array $mappingConfiguration): void { $this->expectException(\UnexpectedValueException::class); @@ -164,39 +134,27 @@ public function failMatchWordsWithStrposNotSymmetric(string $inputData, array $m } /** - * Provide data that will not match for strpos - * - * @return array + * Provide data that will not match for stripos */ - public function mappingTestWithStriposProvider(): array + public static function mappingTestWithStriposProvider(): array { - $data = [ - 'australia' => [ - 'inputData' => 'australia', - 'mappingTable' => [ - 'Commonwealth of Australia' => 'AU', - 'Kingdom of Spain' => 'ES', - ], - 'mappingConfiguration' => [ - 'matchMethod' => 'stripos', - 'matchSymmetric' => false, - ], - 'result' => 'AU', + return [ + 'australia' => [ + 'inputData' => 'australia', + 'mappingTable' => [ + 'Commonwealth of Australia' => 'AU', + 'Kingdom of Spain' => 'ES', + ], + 'mappingConfiguration' => [ + 'matchMethod' => 'stripos', + 'matchSymmetric' => false, ], + 'expectedResult' => 'AU', + ], ]; - return $data; } - /** - * Test soft-matching method with stripos - * - * @test - * @dataProvider mappingTestWithStriposProvider - * @param string $inputData - * @param array $mappingTable - * @param array $mappingConfiguration - * @param string $expectedResult - */ + #[Test] #[DataProvider('mappingTestWithStriposProvider')] public function matchWordsWithStirposNotSymmetric(string $inputData, array $mappingTable, array $mappingConfiguration, string $expectedResult): void { $actualResult = $this->mappingUtility->matchSingleField($inputData, $mappingConfiguration, $mappingTable); @@ -204,36 +162,28 @@ public function matchWordsWithStirposNotSymmetric(string $inputData, array $mapp } /** - * Provide data for soft matching with strpos + * Provide data for soft matching with stripos that will not match * (currently provides only one data set, but could provide more in the future) - * - * @return array */ - public function mappingTestWithStriposWithBadMappingTableProvider(): array + public static function mappingTestWithStriposWithBadMappingTableProvider(): array { return [ // Case doesn't match in this data set 'no matching data' => [ - 'inputData' => 'Swaziland', - 'mappingTable' => [ - 'Commonwealth of Australia' => 'AU', - 'Kingdom of Spain' => 'ES', - ], - 'mappingConfiguration' => [ - 'matchMethod' => 'strpos', - 'matchSymmetric' => false, - ], + 'inputData' => 'Swaziland', + 'mappingTable' => [ + 'Commonwealth of Australia' => 'AU', + 'Kingdom of Spain' => 'ES', + ], + 'mappingConfiguration' => [ + 'matchMethod' => 'strpos', + 'matchSymmetric' => false, + ], ], ]; } - /** - * @test - * @dataProvider mappingTestWithStriposWithBadMappingTableProvider - * @param string $inputData - * @param array $mappingTable - * @param array $mappingConfiguration - */ + #[Test] #[DataProvider('mappingTestWithStriposWithBadMappingTableProvider')] public function failMatchWordsWithStriposNotSymmetric(string $inputData, array $mappingTable, array $mappingConfiguration): void { $this->expectException(\UnexpectedValueException::class); diff --git a/Tests/Unit/Utility/ReportingUtilityTest.php b/Tests/Unit/Utility/ReportingUtilityTest.php index d5fd5cd6..715eec1d 100644 --- a/Tests/Unit/Utility/ReportingUtilityTest.php +++ b/Tests/Unit/Utility/ReportingUtilityTest.php @@ -21,23 +21,22 @@ use Cobweb\ExternalImport\Domain\Repository\LogRepository; use Cobweb\ExternalImport\Step\StoreDataStep; use Cobweb\ExternalImport\Utility\ReportingUtility; -use Nimut\TestingFramework\TestCase\UnitTestCase; +use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Test suite for simple methods from the reporting utility. */ class ReportingUtilityTest extends UnitTestCase { - /** - * @var ReportingUtility - */ - protected $subject; + protected ReportingUtility $subject; public function setUp(): void { parent::setUp(); + $this->resetSingletonInstances = true; $this->subject = GeneralUtility::makeInstance( ReportingUtility::class, $this->getAccessibleMock( @@ -60,18 +59,14 @@ public function setUp(): void ); } - /** - * @test - */ + #[Test] public function getValueForStepForUnknownKeyThrowsException(): void { $this->expectException(\Cobweb\ExternalImport\Exception\UnknownReportingKeyException::class); $this->subject->getValueForStep('foo', 'bar'); } - /** - * @test - */ + #[Test] public function getValueForStepReturnsExpectedValue(): void { $this->subject->setValueForStep( diff --git a/Tests/Unit/Utility/StepUtilityTest.php b/Tests/Unit/Utility/StepUtilityTest.php index afb15d19..c5024ed3 100644 --- a/Tests/Unit/Utility/StepUtilityTest.php +++ b/Tests/Unit/Utility/StepUtilityTest.php @@ -20,18 +20,17 @@ use Cobweb\ExternalImport\Importer; use Cobweb\ExternalImport\Step; use Cobweb\ExternalImport\Utility\StepUtility; -use Nimut\TestingFramework\TestCase\UnitTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Test case for the Step utility. */ class StepUtilityTest extends UnitTestCase { - /** - * @var StepUtility - */ - protected $subject; + protected StepUtility $subject; protected function setUp(): void { @@ -39,22 +38,16 @@ protected function setUp(): void $this->subject = GeneralUtility::makeInstance(StepUtility::class); } - /** - * @return array - */ - public function customStepsGoodConfigurationProvider(): array + public static function customStepsGoodConfigurationProvider(): array { return [ 'insert step before first step' => [ - // Current steps - Importer::SYNCHRONYZE_DATA_STEPS, - // New step configuration - [ + 'currentSteps' => Importer::SYNCHRONYZE_DATA_STEPS, + 'configuration' => [ 'class' => Step\HandleDataStep::class, 'position' => 'before:' . Step\CheckPermissionsStep::class, ], - // Resulting steps - [ + 'resultingSteps' => [ Step\HandleDataStep::class, Step\CheckPermissionsStep::class, Step\ValidateConfigurationStep::class, @@ -70,15 +63,12 @@ public function customStepsGoodConfigurationProvider(): array ], ], 'insert step after transform data' => [ - // Current steps - Importer::SYNCHRONYZE_DATA_STEPS, - // New step configuration - [ + 'currentSteps' => Importer::SYNCHRONYZE_DATA_STEPS, + 'configuration' => [ 'class' => Step\HandleDataStep::class, 'position' => 'after:' . Step\TransformDataStep::class, ], - // Resulting steps - [ + 'resultingSteps' => [ Step\CheckPermissionsStep::class, Step\ValidateConfigurationStep::class, Step\ValidateConnectorStep::class, @@ -94,12 +84,12 @@ public function customStepsGoodConfigurationProvider(): array ], ], 'insert step before validate data step' => [ - Importer::IMPORT_DATA_STEPS, - [ + 'currentSteps' => Importer::IMPORT_DATA_STEPS, + 'configuration' => [ 'class' => Step\HandleDataStep::class, 'position' => 'before:' . Step\ValidateDataStep::class, ], - [ + 'resultingSteps' => [ Step\CheckPermissionsStep::class, Step\ValidateConfigurationStep::class, Step\HandleDataStep::class, @@ -112,15 +102,12 @@ public function customStepsGoodConfigurationProvider(): array ], ], 'insert step after last step' => [ - // Current steps - Importer::SYNCHRONYZE_DATA_STEPS, - // New step configuration - [ + 'currentSteps' => Importer::SYNCHRONYZE_DATA_STEPS, + 'configuration' => [ 'class' => Step\HandleDataStep::class, 'position' => 'after:' . Step\ReportStep::class, ], - // Resulting steps - [ + 'resultingSteps' => [ Step\CheckPermissionsStep::class, Step\ValidateConfigurationStep::class, Step\ValidateConnectorStep::class, @@ -138,13 +125,7 @@ public function customStepsGoodConfigurationProvider(): array ]; } - /** - * @test - * @dataProvider customStepsGoodConfigurationProvider - * @param array $currentSteps - * @param array $configuration - * @param array $resultingSteps - */ + #[Test] #[DataProvider('customStepsGoodConfigurationProvider')] public function insertStepInsertsCustomStepAtCorrectLocation( array $currentSteps, array $configuration, @@ -159,69 +140,52 @@ public function insertStepInsertsCustomStepAtCorrectLocation( ); } - /** - * @return array - */ - public function customStepsWrongConfigurationProvider(): array + public static function customStepsWrongConfigurationProvider(): array { return [ 'insert step with missing class information' => [ - // Current steps - Importer::SYNCHRONYZE_DATA_STEPS, - // New step configuration - [ + 'currentSteps' => Importer::SYNCHRONYZE_DATA_STEPS, + 'configuration' => [ 'position' => 'after:' . Step\TransformDataStep::class, ], ], 'insert step with missing position information' => [ - // Current steps - Importer::SYNCHRONYZE_DATA_STEPS, - // New step configuration - [ + 'currentSteps' => Importer::SYNCHRONYZE_DATA_STEPS, + 'configuration' => [ 'class' => Step\HandleDataStep::class, ], ], 'insert step with wrong syntax for position' => [ - // Current steps - Importer::SYNCHRONYZE_DATA_STEPS, - // New step configuration - [ + 'currentSteps' => Importer::SYNCHRONYZE_DATA_STEPS, + 'configuration' => [ 'class' => Step\HandleDataStep::class, 'position' => Step\TransformDataStep::class, ], ], 'insert step with wrong keyword for position' => [ - // Current steps - Importer::SYNCHRONYZE_DATA_STEPS, - // New step configuration - [ + 'currentSteps' => Importer::SYNCHRONYZE_DATA_STEPS, + 'configuration' => [ 'class' => Step\HandleDataStep::class, 'position' => 'next:' . Step\TransformDataStep::class, ], ], 'insert step with unknown class' => [ - // Current steps - Importer::IMPORT_DATA_STEPS, - // New step configuration - [ + 'currentSteps' => Importer::IMPORT_DATA_STEPS, + 'configuration' => [ 'class' => 'Foo\\Bar\\Baz', 'position' => 'after:' . Step\TransformDataStep::class, ], ], 'insert step after unregistered step' => [ - // Current steps - Importer::IMPORT_DATA_STEPS, - // New step configuration - [ + 'currentSteps' => Importer::IMPORT_DATA_STEPS, + 'configuration' => [ 'class' => Step\HandleDataStep::class, 'position' => 'after:' . Step\ReadDataStep::class, ], ], 'insert step after unknown step' => [ - // Current steps - Importer::SYNCHRONYZE_DATA_STEPS, - // New step configuration - [ + 'currentSteps' => Importer::SYNCHRONYZE_DATA_STEPS, + 'configuration' => [ 'class' => Step\HandleDataStep::class, 'position' => 'before:Not\\Known\\Step', ], @@ -230,12 +194,7 @@ public function customStepsWrongConfigurationProvider(): array ]; } - /** - * @test - * @dataProvider customStepsWrongConfigurationProvider - * @param array $currentSteps - * @param array $configuration - */ + #[Test] #[DataProvider('customStepsWrongConfigurationProvider')] public function validateCustomStepConfigurationWithWrongInformationThrowsException( array $currentSteps, array $configuration @@ -247,12 +206,7 @@ public function validateCustomStepConfigurationWithWrongInformationThrowsExcepti ); } - /** - * @test - * @dataProvider customStepsWrongConfigurationProvider - * @param array $currentSteps - * @param array $configuration - */ + #[Test] #[DataProvider('customStepsWrongConfigurationProvider')] public function insertStepWithWrongInformationReturnsCurrentSteps(array $currentSteps, array $configuration): void { self::assertSame( diff --git a/Tests/Unit/Validator/ValidationResultTest.php b/Tests/Unit/Validator/ValidationResultTest.php index 26f54c1d..0cbb3449 100644 --- a/Tests/Unit/Validator/ValidationResultTest.php +++ b/Tests/Unit/Validator/ValidationResultTest.php @@ -16,17 +16,16 @@ */ use Cobweb\ExternalImport\Validator\ValidationResult; -use Nimut\TestingFramework\TestCase\UnitTestCase; -use TYPO3\CMS\Core\Messaging\AbstractMessage; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; +use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Test case for the ValidationResult class. */ class ValidationResultTest extends UnitTestCase { - /** - * @var ValidationResult - */ protected ValidationResult $subject; public function setUp(): void @@ -35,9 +34,7 @@ public function setUp(): void $this->subject = new ValidationResult(); } - /** - * @test - */ + #[Test] public function getAllInitiallyReturnsEmptyArray(): void { self::assertSame( @@ -46,12 +43,10 @@ public function getAllInitiallyReturnsEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function resetSetsResultsToEmptyArray(): void { - $this->subject->add('foo', 'This is a validation result', AbstractMessage::NOTICE); + $this->subject->add('foo', 'This is a validation result', ContextualFeedbackSeverity::NOTICE); $this->subject->reset(); self::assertSame( [], @@ -59,9 +54,7 @@ public function resetSetsResultsToEmptyArray(): void ); } - /** - * @test - */ + #[Test] public function getForPropertyInitiallyReturnsNull(): void { self::assertNull( @@ -69,14 +62,12 @@ public function getForPropertyInitiallyReturnsNull(): void ); } - /** - * @test - */ + #[Test] public function getForSeverityInitiallyReturnsEmptyArray(): void { self::assertSame( [], - $this->subject->getForSeverity(AbstractMessage::NOTICE) + $this->subject->getForSeverity(ContextualFeedbackSeverity::NOTICE) ); } @@ -85,151 +76,146 @@ public function getForSeverityInitiallyReturnsEmptyArray(): void * * @return \array[][][] */ - public function getSampleMessages(): array + public static function getSampleMessages(): array { return [ - 'single message' => [ - 'messages' => [ - [ - 'property' => 'foo', - 'message' => 'This is a validation result', - 'severity' => AbstractMessage::NOTICE, - ], - ], + 'single message' => [ + 'messages' => [ + [ + 'property' => 'foo', + 'message' => 'This is a validation result', + 'severity' => ContextualFeedbackSeverity::NOTICE, + ], ], - 'single message, not requested property, not requested severity' => [ - 'messages' => [ - [ - 'property' => 'baz', - 'message' => 'This is a baz validation result', - 'severity' => AbstractMessage::ERROR, - ], - ], + ], + 'single message, not requested property, not requested severity' => [ + 'messages' => [ + [ + 'property' => 'baz', + 'message' => 'This is a baz validation result', + 'severity' => ContextualFeedbackSeverity::ERROR, + ], ], - 'two messages, same property, same severity' => [ - 'messages' => [ - [ - 'property' => 'foo', - 'message' => 'This is a validation result', - 'severity' => AbstractMessage::NOTICE, - ], - [ - 'property' => 'foo', - 'message' => 'This is a second validation result', - 'severity' => AbstractMessage::NOTICE, - ], - ], + ], + 'two messages, same property, same severity' => [ + 'messages' => [ + [ + 'property' => 'foo', + 'message' => 'This is a validation result', + 'severity' => ContextualFeedbackSeverity::NOTICE, + ], + [ + 'property' => 'foo', + 'message' => 'This is a second validation result', + 'severity' => ContextualFeedbackSeverity::NOTICE, + ], ], - 'two messages, same property, different severity' => [ - 'messages' => [ - [ - 'property' => 'foo', - 'message' => 'This is a notice validation result', - 'severity' => AbstractMessage::NOTICE, - ], - [ - 'property' => 'foo', - 'message' => 'This is a warning validation result', - 'severity' => AbstractMessage::WARNING, - ], - ], + ], + 'two messages, same property, different severity' => [ + 'messages' => [ + [ + 'property' => 'foo', + 'message' => 'This is a notice validation result', + 'severity' => ContextualFeedbackSeverity::NOTICE, + ], + [ + 'property' => 'foo', + 'message' => 'This is a warning validation result', + 'severity' => ContextualFeedbackSeverity::WARNING, + ], ], - 'two messages, different property, same severity' => [ - 'messages' => [ - [ - 'property' => 'foo', - 'message' => 'This is a foo validation result', - 'severity' => AbstractMessage::NOTICE, - ], - [ - 'property' => 'bar', - 'message' => 'This is a bar validation result', - 'severity' => AbstractMessage::NOTICE, - ], - ], + ], + 'two messages, different property, same severity' => [ + 'messages' => [ + [ + 'property' => 'foo', + 'message' => 'This is a foo validation result', + 'severity' => ContextualFeedbackSeverity::NOTICE, + ], + [ + 'property' => 'bar', + 'message' => 'This is a bar validation result', + 'severity' => ContextualFeedbackSeverity::NOTICE, + ], ], + ], ]; } - public function allResultsProvider(): array + public static function allResultsProvider(): array { return array_merge_recursive( - $this->getSampleMessages(), + self::getSampleMessages(), [ - 'single message' => [ - 'expected' => [ - 'foo' => [ - [ - 'severity' => AbstractMessage::NOTICE, - 'message' => 'This is a validation result', - ], - ], + 'single message' => [ + 'expectedStructure' => [ + 'foo' => [ + [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'message' => 'This is a validation result', ], + ], ], - 'single message, not requested property, not requested severity' => [ - 'expected' => [ - 'baz' => [ - [ - 'severity' => AbstractMessage::ERROR, - 'message' => 'This is a baz validation result', - ], - ], + ], + 'single message, not requested property, not requested severity' => [ + 'expectedStructure' => [ + 'baz' => [ + [ + 'severity' => ContextualFeedbackSeverity::ERROR, + 'message' => 'This is a baz validation result', ], + ], ], - 'two messages, same property, same severity' => [ - 'expected' => [ - 'foo' => [ - [ - 'severity' => AbstractMessage::NOTICE, - 'message' => 'This is a validation result', - ], - [ - 'severity' => AbstractMessage::NOTICE, - 'message' => 'This is a second validation result', - ], - ], + ], + 'two messages, same property, same severity' => [ + 'expectedStructure' => [ + 'foo' => [ + [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'message' => 'This is a validation result', ], + [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'message' => 'This is a second validation result', + ], + ], ], - 'two messages, same property, different severity' => [ - 'expected' => [ - 'foo' => [ - [ - 'severity' => AbstractMessage::WARNING, - 'message' => 'This is a warning validation result', - ], - [ - 'severity' => AbstractMessage::NOTICE, - 'message' => 'This is a notice validation result', - ], - ], + ], + 'two messages, same property, different severity' => [ + 'expectedStructure' => [ + 'foo' => [ + [ + 'severity' => ContextualFeedbackSeverity::WARNING, + 'message' => 'This is a warning validation result', ], + [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'message' => 'This is a notice validation result', + ], + ], ], - 'two messages, different property, same severity' => [ - 'expected' => [ - 'foo' => [ - [ - 'severity' => AbstractMessage::NOTICE, - 'message' => 'This is a foo validation result', - ], - ], - 'bar' => [ - [ - 'severity' => AbstractMessage::NOTICE, - 'message' => 'This is a bar validation result', - ], - ], + ], + 'two messages, different property, same severity' => [ + 'expectedStructure' => [ + 'foo' => [ + [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'message' => 'This is a foo validation result', + ], + ], + 'bar' => [ + [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'message' => 'This is a bar validation result', ], + ], ], + ], ] ); } - /** - * @test - * @dataProvider allResultsProvider - * @param array $messages - * @param array $expectedStructure - */ + #[Test] #[DataProvider('allResultsProvider')] public function addAddsResultToList(array $messages, array $expectedStructure): void { $this->loadMessages($messages); @@ -242,12 +228,8 @@ public function addAddsResultToList(array $messages, array $expectedStructure): /** * This is currently the same as addAddsResultToList() above, but it was still separated * to clarify coverage and in case some variant is needed in the future. - * - * @test - * @dataProvider allResultsProvider - * @param array $messages - * @param array $expectedStructure */ + #[Test] #[DataProvider('allResultsProvider')] public function getAllReturnsAllMessages(array $messages, array $expectedStructure): void { $this->loadMessages($messages); @@ -257,70 +239,64 @@ public function getAllReturnsAllMessages(array $messages, array $expectedStructu ); } - public function forPropertyProvider(): array + public static function forPropertyProvider(): array { return array_merge_recursive( - $this->getSampleMessages(), + self::getSampleMessages(), [ - 'single message' => [ - 'property' => 'foo', - 'expected' => [ - [ - 'severity' => AbstractMessage::NOTICE, - 'message' => 'This is a validation result', - ], - ], - ], - 'single message, not requested property, not requested severity' => [ - 'property' => 'foo', - 'expected' => null, + 'single message' => [ + 'property' => 'foo', + 'expectedStructure' => [ + [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'message' => 'This is a validation result', + ], ], - 'two messages, same property, same severity' => [ - 'property' => 'foo', - 'expected' => [ - [ - 'severity' => AbstractMessage::NOTICE, - 'message' => 'This is a validation result', - ], - [ - 'severity' => AbstractMessage::NOTICE, - 'message' => 'This is a second validation result', - ], - ], + ], + 'single message, not requested property, not requested severity' => [ + 'property' => 'foo', + 'expectedStructure' => null, + ], + 'two messages, same property, same severity' => [ + 'property' => 'foo', + 'expectedStructure' => [ + [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'message' => 'This is a validation result', + ], + [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'message' => 'This is a second validation result', + ], ], - 'two messages, same property, different severity' => [ - 'property' => 'foo', - 'expected' => [ - [ - 'severity' => AbstractMessage::WARNING, - 'message' => 'This is a warning validation result', - ], - [ - 'severity' => AbstractMessage::NOTICE, - 'message' => 'This is a notice validation result', - ], - ], + ], + 'two messages, same property, different severity' => [ + 'property' => 'foo', + 'expectedStructure' => [ + [ + 'severity' => ContextualFeedbackSeverity::WARNING, + 'message' => 'This is a warning validation result', + ], + [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'message' => 'This is a notice validation result', + ], ], - 'two messages, different property, same severity' => [ - 'property' => 'foo', - 'expected' => [ - [ - 'severity' => AbstractMessage::NOTICE, - 'message' => 'This is a foo validation result', - ], - ], + ], + 'two messages, different property, same severity' => [ + 'property' => 'foo', + 'expectedStructure' => [ + [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'message' => 'This is a foo validation result', + ], ], + ], ] ); } - /** - * @test - * @dataProvider forPropertyProvider - * @param array $messages - * @param string $property - * @param array|null $expectedStructure - */ + #[Test] #[DataProvider('forPropertyProvider')] public function getForPropertyReturnsAllMessagesForProperty(array $messages, string $property, ?array $expectedStructure): void { $this->loadMessages($messages); @@ -330,65 +306,59 @@ public function getForPropertyReturnsAllMessagesForProperty(array $messages, str ); } - public function forSeverityProvider(): array + public static function forSeverityProvider(): array { return array_merge_recursive( - $this->getSampleMessages(), + self::getSampleMessages(), [ - 'single message' => [ - 'severity' => AbstractMessage::NOTICE, - 'expected' => [ - 'foo' => [ - 'This is a validation result', - ], - ], + 'single message' => [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'expectedStructure' => [ + 'foo' => [ + 'This is a validation result', + ], ], - 'single message, not requested property, not requested severity' => [ - 'severity' => AbstractMessage::NOTICE, - 'expected' => [ - 'baz' => [], - ], + ], + 'single message, not requested property, not requested severity' => [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'expectedStructure' => [ + 'baz' => [], ], - 'two messages, same property, same severity' => [ - 'severity' => AbstractMessage::NOTICE, - 'expected' => [ - 'foo' => [ - 'This is a validation result', - 'This is a second validation result', - ], - ], + ], + 'two messages, same property, same severity' => [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'expectedStructure' => [ + 'foo' => [ + 'This is a validation result', + 'This is a second validation result', + ], ], - 'two messages, same property, different severity' => [ - 'severity' => AbstractMessage::NOTICE, - 'expected' => [ - 'foo' => [ - 'This is a notice validation result', - ], - ], + ], + 'two messages, same property, different severity' => [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'expectedStructure' => [ + 'foo' => [ + 'This is a notice validation result', + ], ], - 'two messages, different property, same severity' => [ - 'severity' => AbstractMessage::NOTICE, - 'expected' => [ - 'foo' => [ - 'This is a foo validation result', - ], - 'bar' => [ - 'This is a bar validation result', - ], - ], + ], + 'two messages, different property, same severity' => [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'expectedStructure' => [ + 'foo' => [ + 'This is a foo validation result', + ], + 'bar' => [ + 'This is a bar validation result', + ], ], + ], ] ); } - /** - * @test - * @dataProvider forSeverityProvider - * @param array $messages - * @param int $severity - * @param array $expectedStructure - */ - public function getForSeverityReturnsAllMessagesForSeverity(array $messages, int $severity, array $expectedStructure): void + #[Test] #[DataProvider('forSeverityProvider')] + public function getForSeverityReturnsAllMessagesForSeverity(array $messages, ContextualFeedbackSeverity $severity, array $expectedStructure): void { $this->loadMessages($messages); self::assertSame( @@ -397,42 +367,36 @@ public function getForSeverityReturnsAllMessagesForSeverity(array $messages, int ); } - public function countForPropertyProvider(): array + public static function countForPropertyProvider(): array { return array_merge_recursive( - $this->getSampleMessages(), + self::getSampleMessages(), [ - 'single message' => [ - 'property' => 'foo', - 'expected' => 1, - ], - 'single message, not requested property, not requested severity' => [ - 'property' => 'foo', - 'expected' => 0, - ], - 'two messages, same property, same severity' => [ - 'property' => 'foo', - 'expected' => 2, - ], - 'two messages, same property, different severity' => [ - 'property' => 'foo', - 'expected' => 2, - ], - 'two messages, different property, same severity' => [ - 'property' => 'foo', - 'expected' => 1, - ], + 'single message' => [ + 'property' => 'foo', + 'expectedTotal' => 1, + ], + 'single message, not requested property, not requested severity' => [ + 'property' => 'foo', + 'expectedTotal' => 0, + ], + 'two messages, same property, same severity' => [ + 'property' => 'foo', + 'expectedTotal' => 2, + ], + 'two messages, same property, different severity' => [ + 'property' => 'foo', + 'expectedTotal' => 2, + ], + 'two messages, different property, same severity' => [ + 'property' => 'foo', + 'expectedTotal' => 1, + ], ] ); } - /** - * @test - * @dataProvider countForPropertyProvider - * @param array $messages - * @param string $property - * @param int $expectedTotal - */ + #[Test] #[DataProvider('countForPropertyProvider')] public function countForPropertyReturnsTotalMessagesForProperty(array $messages, string $property, int $expectedTotal): void { $this->loadMessages($messages); @@ -442,43 +406,37 @@ public function countForPropertyReturnsTotalMessagesForProperty(array $messages, ); } - public function countForSeverityProvider(): array + public static function countForSeverityProvider(): array { return array_merge_recursive( - $this->getSampleMessages(), + self::getSampleMessages(), [ - 'single message' => [ - 'severity' => AbstractMessage::NOTICE, - 'expected' => 1, - ], - 'single message, not requested property, not requested severity' => [ - 'severity' => AbstractMessage::NOTICE, - 'expected' => 0, - ], - 'two messages, same property, same severity' => [ - 'severity' => AbstractMessage::NOTICE, - 'expected' => 2, - ], - 'two messages, same property, different severity' => [ - 'severity' => AbstractMessage::NOTICE, - 'expected' => 1, - ], - 'two messages, different property, same severity' => [ - 'severity' => AbstractMessage::NOTICE, - 'expected' => 2, - ], + 'single message' => [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'expectedTotal' => 1, + ], + 'single message, not requested property, not requested severity' => [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'expectedTotal' => 0, + ], + 'two messages, same property, same severity' => [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'expectedTotal' => 2, + ], + 'two messages, same property, different severity' => [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'expectedTotal' => 1, + ], + 'two messages, different property, same severity' => [ + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'expectedTotal' => 2, + ], ] ); } - /** - * @test - * @dataProvider countForSeverityProvider - * @param array $messages - * @param int $severity - * @param int $expectedTotal - */ - public function countForSeverityReturnsTotalMessagesForSeverity(array $messages, int $severity, int $expectedTotal): void + #[Test] #[DataProvider('countForSeverityProvider')] + public function countForSeverityReturnsTotalMessagesForSeverity(array $messages, ContextualFeedbackSeverity $severity, int $expectedTotal): void { $this->loadMessages($messages); self::assertSame( @@ -487,49 +445,42 @@ public function countForSeverityReturnsTotalMessagesForSeverity(array $messages, ); } - public function getForPropertyAndSeverityProvider(): array + public static function getForPropertyAndSeverityProvider(): array { return array_merge_recursive( - $this->getSampleMessages(), + self::getSampleMessages(), [ - 'single message' => [ - 'property' => 'foo', - 'severity' => AbstractMessage::NOTICE, - 'count' => 1, - ], - 'single message, not requested property, not requested severity' => [ - 'property' => 'foo', - 'severity' => AbstractMessage::NOTICE, - 'count' => 0, - ], - 'two messages, same property, same severity' => [ - 'property' => 'foo', - 'severity' => AbstractMessage::NOTICE, - 'count' => 2, - ], - 'two messages, same property, different severity' => [ - 'property' => 'foo', - 'severity' => AbstractMessage::NOTICE, - 'count' => 1, - ], - 'two messages, different property, same severity' => [ - 'property' => 'foo', - 'severity' => AbstractMessage::NOTICE, - 'count' => 1, - ], + 'single message' => [ + 'property' => 'foo', + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'count' => 1, + ], + 'single message, not requested property, not requested severity' => [ + 'property' => 'foo', + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'count' => 0, + ], + 'two messages, same property, same severity' => [ + 'property' => 'foo', + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'count' => 2, + ], + 'two messages, same property, different severity' => [ + 'property' => 'foo', + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'count' => 1, + ], + 'two messages, different property, same severity' => [ + 'property' => 'foo', + 'severity' => ContextualFeedbackSeverity::NOTICE, + 'count' => 1, + ], ] ); } - /** - * @test - * @dataProvider getForPropertyAndSeverityProvider - * @param array $messages - * @param string $property - * @param int $severity - * @param int $count - */ - public function getForPropertyAndSeverityReturnsAllMessagesForPropertyAndSeverity(array $messages, string $property, int $severity, int $count): void + #[Test] #[DataProvider('getForPropertyAndSeverityProvider')] + public function getForPropertyAndSeverityReturnsAllMessagesForPropertyAndSeverity(array $messages, string $property, ContextualFeedbackSeverity $severity, int $count): void { $this->loadMessages($messages); self::assertCount( diff --git a/composer.json b/composer.json index e1acca01..cb254376 100644 --- a/composer.json +++ b/composer.json @@ -32,12 +32,13 @@ "cobweb/svconnector": "^6.0" }, "require-dev": { - "cobweb/externalimport_test": "^0.14.0", + "cobweb/externalimport_test": "dev-next", "cobweb/svconnector_csv": "^5.0", "cobweb/svconnector_feed": "^5.0", + "cobweb/svconnector_json": "^5.0", "ergebnis/composer-normalize": "~2.42.0", "friendsofphp/php-cs-fixer": "^3.52", - "nimut/testing-framework": "^6.0", + "typo3/testing-framework": "^8.2", "phpstan/phpstan": "^1.10" }, "extra": {