Skip to content

Commit

Permalink
[TASK] Migrate all tests to typo3/testing-framework (2 tests skipped),
Browse files Browse the repository at this point in the history
…resolves #359
  • Loading branch information
fsuter committed Jan 20, 2025
1 parent 007de75 commit 377b493
Show file tree
Hide file tree
Showing 70 changed files with 1,802 additions and 2,684 deletions.
15 changes: 7 additions & 8 deletions Build/Scripts/runTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
;;
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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=$?
;;
Expand Down
4 changes: 0 additions & 4 deletions Build/phpstan/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,3 @@ parameters:

excludePaths:
- '../../ext_emconf.php'
# Todo: Drop exclude after dropping v11 support
- '../../Classes/Reaction'
- '../../Classes/Message'

6 changes: 3 additions & 3 deletions Build/rector/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2025-01-20 Francois Suter (Idéative) <[email protected]>

* Migrate all tests to typo3/testing-framework, resolves #359

2025-01-10 Francois Suter (Idéative) <[email protected]>

* Update datatables, drop RequireJS, use Luxon instead of Moment, resolves #358
Expand Down
65 changes: 65 additions & 0 deletions Classes/Testing/FunctionalTestCaseWithDatabaseTools.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

namespace Cobweb\ExternalImport\Testing;

use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Http\NormalizedParams;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

class FunctionalTestCaseWithDatabaseTools extends FunctionalTestCase
{
/**
* @throws \TYPO3\TestingFramework\Core\Exception
*/
protected function initializeBackendUser(): void
{
$this->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();
}
}
28 changes: 14 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 377b493

Please sign in to comment.