Skip to content

Commit

Permalink
Merge pull request #14 from AOEpeople/feature/php83
Browse files Browse the repository at this point in the history
feat: [CD-306292] Adding PHP 8.3 support and code-style updates
  • Loading branch information
sourcesoldier authored Mar 11, 2024
2 parents 5dbbe42 + 7d1fd06 commit a2f55b1
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 193 deletions.
49 changes: 22 additions & 27 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@ jobs:
strategy:
fail-fast: false
matrix:
typo3: [ '^10.4', '^11.5' ]
php: [ '7.4' ]
include:
- typo3: ^11.5
php: '8.0'
experimental: false
- typo3: ^11.5
php: '8.1'
experimental: false
typo3: [ '^11.5' ]
php: ['8.0', '8.1', '8.2', '8.3']

steps:
- name: Start database server
run: sudo /etc/init.d/mysql start

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 10

- name: Set up PHP Version ${{ matrix.php }}
uses: shivammathur/setup-php@v2
Expand All @@ -49,22 +45,22 @@ jobs:
run: find . -name \*.php ! -path "./.Build/*" ! -path "./scripts/*" ! -path "./typo3_src/*" | parallel --gnu php -d display_errors=stderr -l {} > /dev/null \;

- name: Unit Tests without coverage
if: matrix.typo3 != '^11.5' && matrix.php != '7.4'
if: matrix.typo3 != '^11.5' && matrix.php != '8.3'
run: |
export "UNIT_XML"=.Build/vendor/nimut/testing-framework/res/Configuration/UnitTests.xml
export "UNIT_XML"=.Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTests.xml
.Build/bin/phpunit --colors -c $UNIT_XML Tests/Unit
- name: Unit Tests with coverage
if: matrix.typo3 == '^11.5' && matrix.php == '7.4'
if: matrix.typo3 == '^11.5' && matrix.php == '8.3'
run: |
export "UNIT_XML"=.Build/vendor/nimut/testing-framework/res/Configuration/UnitTests.xml
.Build/bin/phpunit --whitelist Classes --coverage-clover=unittest-coverage.clover --colors -c $UNIT_XML Tests/Unit
export "UNIT_XML"=.Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTests-v10.xml
.Build/bin/phpunit --coverage-filter Classes --coverage-clover=unittest-coverage.clover --colors -c $UNIT_XML Tests/Unit
- name: Functional Tests without coverage
run: |
export "FUNCTIONAL_XML"=.Build/vendor/nimut/testing-framework/res/Configuration/FunctionalTests.xml
.Build/bin/phpunit --whitelist Classes --colors -c $FUNCTIONAL_XML Tests/Functional
if: matrix.typo3 != '^11.5' && matrix.php != '7.4'
export "FUNCTIONAL_XML"=.Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTests-v10.xml
.Build/bin/phpunit --coverage-filter Classes --colors -c $FUNCTIONAL_XML Tests/Functional
if: matrix.typo3 != '^11.5' && matrix.php != '8.3'
env:
typo3DatabaseHost: 127.0.0.1
typo3DatabaseName: typo3
Expand All @@ -73,18 +69,17 @@ jobs:

- name: Functional Tests with coverage
run: |
export "FUNCTIONAL_XML"=.Build/vendor/nimut/testing-framework/res/Configuration/FunctionalTests.xml
.Build/bin/phpunit --whitelist Classes --coverage-clover=functional-coverage.clover --colors -c $FUNCTIONAL_XML Tests/Functional
if: matrix.typo3 == '^11.5' && matrix.php == '7.4'
export "FUNCTIONAL_XML"=.Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTests-v10.xml
.Build/bin/phpunit --coverage-filter Classes --coverage-clover=functional-coverage.clover --colors -c $FUNCTIONAL_XML Tests/Functional
if: matrix.typo3 == '^11.5' && matrix.php == '8.3'
env:
typo3DatabaseHost: 127.0.0.1
typo3DatabaseName: typo3
typo3DatabasePassword: root
typo3DatabaseUsername: root

- name: Upload coverage results to Scrutinizer
if: matrix.typo3 == '^11.5' && matrix.php == '7.4'
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover unittest-coverage.clover
php ocular.phar code-coverage:upload --format=php-clover functional-coverage.clover
- name: Upload functional coverage results to Scrutinizer
uses: sudo-bot/action-scrutinizer@latest
if: matrix.typo3 == '^11.5' && matrix.php == '8.3'
with:
cli-args: "--format=php-clover functional-coverage.clover --revision=${{ github.event.pull_request.head.sha || github.sha }}"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ nbproject
.Build
composer.lock
.php_cs.cache
var
var
.cache
28 changes: 13 additions & 15 deletions Classes/Controller/BackendModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ public function detailAction(): void
{
try {
$cacheId = $this->request->getArgument('cacheId');
} catch (NoSuchArgumentException $noSuchArgumentException) {
} catch (NoSuchArgumentException) {
$this->showFlashMessage($this->getNoCacheFoundMessage());
$this->forward('index');
}

$cache = $this->cacheManager->getCache($cacheId);
$backend = $cache->getBackend();

Expand All @@ -104,8 +105,8 @@ public function detailAction(): void
[
'cacheId' => $cacheId,
'cacheInformation' => [
'Frontend Classname' => get_class($cache),
'Backend Classname' => get_class($backend),
'Frontend Classname' => $cache::class,
'Backend Classname' => $backend::class,
],
'fileBackend' => $fileBackend,
'cacheCount' => $cacheCount,
Expand All @@ -119,10 +120,11 @@ public function flushAction(): void
{
try {
$cacheId = $this->request->getArgument('cacheId');
} catch (NoSuchArgumentException $noSuchArgumentException) {
} catch (NoSuchArgumentException) {
$this->showFlashMessage($this->getNoCacheFoundMessage());
$this->forward('index');
}

$cache = $this->cacheManager->getCache($cacheId);
$cache->flush();
$this->showFlashMessage($this->getFlushCacheMessage($cacheId));
Expand Down Expand Up @@ -187,12 +189,14 @@ private function getBackendCacheProperties(BackendInterface $backend): array
if ($properties[$key]->isInitialized($backend)) {
$value = $properties[$key]->getValue($backend);
if (is_object($value)) {
$value = 'Object: ' . get_class($value);
$value = 'Object: ' . $value::class;
}

// remove elements that are not a string
$propertiesArray[$properties[$key]->getName()] = is_string($value) ? $value : '';
}
}

return $propertiesArray;
}

Expand All @@ -209,14 +213,14 @@ private function getFileBackendInfo(BackendInterface $backend): ?string
. '</span>';
}
}

return $fileBackend;
}

/**
* @param $backend
* @return array<string, mixed>
*/
private function getCacheCount($backend): array
private function getCacheCount(BackendInterface $backend): array
{
$cacheTableRepository = GeneralUtility::makeInstance(CacheTableRepository::class);

Expand All @@ -227,14 +231,11 @@ private function getCacheCount($backend): array
$cacheCount['Cache Tags Table'] = $backend->getTagsTable();
$cacheCount['Cache Tags Entry Count'] = $cacheTableRepository->countRowsInTable($backend->getTagsTable());
}

return $cacheCount;
}

/**
* @param $cacheId
* @return object|FlashMessage
*/
private function getFlushCacheMessage($cacheId): object
private function getFlushCacheMessage(string $cacheId): object
{
return GeneralUtility::makeInstance(
FlashMessage::class,
Expand All @@ -252,9 +253,6 @@ private function getFlushCacheMessage($cacheId): object
);
}

/**
* @return object|FlashMessage
*/
private function getNoCacheFoundMessage(): object
{
return GeneralUtility::makeInstance(
Expand Down
2 changes: 2 additions & 0 deletions Classes/Utility/CacheUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static function getCacheType(string $cacheId): string
if (!isset($conf['frontend'])) {
return 'Default (Variable)';
}

return $conf['frontend'];
}

Expand All @@ -29,6 +30,7 @@ public static function getCacheBackendType(string $cacheId): string
if (!isset($conf['backend'])) {
return 'Default (DbBackend)';
}

return $conf['backend'];
}

Expand Down
23 changes: 17 additions & 6 deletions Tests/Functional/Domain/Repository/CacheTableRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,26 @@
***************************************************************/

use Aoe\Cachemgm\Domain\Repository\CacheTableRepository;
use Nimut\TestingFramework\TestCase\FunctionalTestCase;
use TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

class CacheTableRepositoryTest extends FunctionalTestCase
{
/**
* @var array
*/
protected $testExtensionsToLoad = ['typo3conf/ext/cachemgm'];
protected array $configurationToUseInTestInstance = [
'SYS' => [
'caching' => [
'cacheConfigurations' => [
// Set pages cache database backend, testing-framework sets this to NullBackend by default.
'pages' => [
'backend' => Typo3DatabaseBackend::class,
],
],
],
],
];

protected array $testExtensionsToLoad = ['typo3conf/ext/cachemgm'];

/**
* @var CacheTableRepository
Expand All @@ -50,7 +61,7 @@ protected function setUp(): void
$this->subject = GeneralUtility::makeInstance(CacheTableRepository::class);
}

public function testCountRowsInTable()
public function testCountRowsInTable(): void
{
$this->importDataSet(__DIR__ . '/Fixtures/cache_pages.xml');
$this->assertSame(
Expand Down
16 changes: 8 additions & 8 deletions Tests/Unit/Utility/CacheUtilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
***************************************************************/

use Aoe\Cachemgm\Utility\CacheUtility;
use Nimut\TestingFramework\TestCase\UnitTestCase;
use TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend;
use TYPO3\CMS\Core\Cache\Frontend\PhpFrontend;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

class CacheUtilityTest extends UnitTestCase
{
Expand All @@ -55,49 +55,49 @@ protected function setUp(): void
];
}

public function testGetAvailableCachesReturnsArray()
public function testGetAvailableCachesReturnsArray(): void
{
$this->assertTrue(is_array(CacheUtility::getAvailableCaches()));
}

public function testGetCacheTypeReturnsString()
public function testGetCacheTypeReturnsString(): void
{
$this->assertSame(
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_core']['frontend'],
CacheUtility::getCacheType('cache_core')
);
}

public function testGetCacheTypeReturnsDefaultValue()
public function testGetCacheTypeReturnsDefaultValue(): void
{
$this->assertSame(
'Default (Variable)',
CacheUtility::getCacheType('no_caches_defined')
);
}

public function testGetCacheBackendReturnsString()
public function testGetCacheBackendReturnsString(): void
{
$this->assertSame(
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_core']['backend'],
CacheUtility::getCacheBackendType('cache_core')
);
}

public function testGetCacheBackendReturnsDefaultValue()
public function testGetCacheBackendReturnsDefaultValue(): void
{
$this->assertSame(
'Default (DbBackend)',
CacheUtility::getCacheBackendType('no_caches_defined')
);
}

public function testGetCacheOptionsReturnsEmptyString()
public function testGetCacheOptionsReturnsEmptyString(): void
{
$this->assertEmpty(CacheUtility::getCacheOptions('cache_core'));
}

public function testGetCacheOptionsReturnsOptionString()
public function testGetCacheOptionsReturnsOptionString(): void
{
$cacheOptions = CacheUtility::getCacheOptions('cache_hash');
$this->assertStringContainsString('first', $cacheOptions);
Expand Down
67 changes: 30 additions & 37 deletions code-quality/ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,43 @@

declare(strict_types=1);

use PhpCsFixer\Fixer\FunctionNotation\FunctionTypehintSpaceFixer;
use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer;
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
use PhpCsFixer\Fixer\Strict\StrictParamFixer;
use Symplify\CodingStandard\Fixer\LineLength\DocBlockLineLengthFixer;
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(
Option::PATHS,
return ECSConfig::configure()
->withPaths([
__DIR__ . '/../Classes',
__DIR__ . '/../Tests',
__DIR__ . '/ecs.php',
])
->withSets([
SetList::COMMON,
SetList::CLEAN_CODE,
SetList::PSR_12,
SetList::SYMPLIFY,
])
->withConfiguredRule(
LineLengthFixer::class,
[
__DIR__ . '/../Classes',
__DIR__ . '/../Tests',
__DIR__ . '/ecs.php',
]
);

$containerConfigurator->import(SetList::COMMON);
$containerConfigurator->import(SetList::CLEAN_CODE);
$containerConfigurator->import(SetList::PSR_12);
$containerConfigurator->import(SetList::SYMPLIFY);

$containerConfigurator->services()
->set(LineLengthFixer::class)
->call('configure', [[
LineLengthFixer::LINE_LENGTH => 140,
LineLengthFixer::INLINE_SHORT_LINES => false,
]]);

// Skip Rules and Sniffer
$parameters->set(
Option::SKIP,
[
// Default Skips
NotOperatorWithSuccessorSpaceFixer::class => null,
DocBlockLineLengthFixer::class => null,

FunctionTypehintSpaceFixer::class,

// @todo strict php
DeclareStrictTypesFixer::class => null,
]
);
};
)
->withSkip([
// Default Skips
NotOperatorWithSuccessorSpaceFixer::class => null,
DocBlockLineLengthFixer::class => null,
ArrayListItemNewlineFixer::class => null,
ArrayOpenerAndCloserNewlineFixer::class => null,

// @todo strict php
DeclareStrictTypesFixer::class => null,
StrictComparisonFixer::class => null,
StrictParamFixer::class => null,
]);
Loading

0 comments on commit a2f55b1

Please sign in to comment.