Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ext conf func tests #11

Merged
merged 3 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout
- name: 'Checkout'
uses: actions/checkout@v4

- name: Composer
run: Build/Scripts/runTests.sh -p 8.1 -s composerUpdate
- name: 'Composer'
run: Build/Scripts/runTests.sh -p 8.2 -s composerUpdate

- name: Lint PHP
run: Build/Scripts/runTests.sh -p 8.1 -s lint
- name: 'Lint PHP'
run: Build/Scripts/runTests.sh -p 8.2 -s lint

- name: Validate code against CGL
run: Build/Scripts/runTests.sh -p 8.1 -s cgl -n
- name: 'Validate code against CGL'
run: Build/Scripts/runTests.sh -p 8.2 -s cgl -n

- name: 'Execute functional tests'
run: Build/Scripts/runTests.sh -p 8.2 -d sqlite -s functional
28 changes: 0 additions & 28 deletions Build/FunctionalTests.xml

This file was deleted.

29 changes: 0 additions & 29 deletions Build/UnitTests.xml

This file was deleted.

26 changes: 26 additions & 0 deletions Build/phpunit/FunctionalTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
backupGlobals="true"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="FunctionalTestsBootstrap.php"
cacheResult="false"
colors="true"
failOnRisky="true"
failOnWarning="true"
>
<testsuites>
<testsuite name="Functional tests">
<!--
This path either needs an adaption in extensions, or an extension's
test location path needs to be given to phpunit.
-->
<directory>../../Tests/Functional/</directory>
</testsuite>
</testsuites>
<php>
<ini name="display_errors" value="1"/>
<env name="TYPO3_CONTEXT" value="Testing"/>
</php>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

use TYPO3\TestingFramework\Core\Testbase;

call_user_func(function () {
(static function () {
$testbase = new Testbase();
$testbase->defineOriginalRootPath();
$testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/tests');
$testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/transient');
});
})();
31 changes: 31 additions & 0 deletions Build/phpunit/UnitTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0"?>
<!--
* This file is part of the package jweiland/glossary2.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
-->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
backupGlobals="true"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="UnitTestsBootstrap.php"
cacheResult="false"
colors="true"
failOnRisky="true"
failOnWarning="true"
>
<testsuites>
<testsuite name="Unit tests">
<!--
This path either needs an adaption in extensions, or an extension's
test location path needs to be given to phpunit.
-->
<directory>../../Tests/Unit/</directory>
</testsuite>
</testsuites>
<php>
<ini name="display_errors" value="1"/>
<env name="TYPO3_CONTEXT" value="Testing"/>
</php>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
* LICENSE file that was distributed with this source code.
*/

/**
* Boilerplate for a unit test phpunit boostrap file.
*
* This file is loosely maintained within TYPO3 testing-framework, extensions
* are encouraged to not use it directly, but to copy it to an own place,
* usually in parallel to a UnitTests.xml file.
*
* This file is defined in UnitTests.xml and called by phpunit
* before instantiating the test suites.
*
* The recommended way to execute the suite is "runTests.sh". See the
* according script within TYPO3 core's Build/Scripts directory and
* adapt to extensions needs.
*/

use TYPO3\CMS\Core\Cache\Backend\NullBackend;
use TYPO3\CMS\Core\Cache\Frontend\PhpFrontend;
use TYPO3\CMS\Core\Configuration\ConfigurationManager;
Expand Down Expand Up @@ -59,11 +74,11 @@

$cache = new PhpFrontend(
'core',
new NullBackend('production', [])
new NullBackend('production', []),
);
$packageManager = Bootstrap::createPackageManager(
UnitTestPackageManager::class,
Bootstrap::createPackageCache($cache)
Bootstrap::createPackageCache($cache),
);

GeneralUtility::setSingletonInstance(PackageManager::class, $packageManager);
Expand Down
25 changes: 4 additions & 21 deletions Classes/Configuration/ExtConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@

namespace StefanFroemken\PleskWidget\Configuration;

use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\SingletonInterface;

/*
* This class streamlines all settings from extension settings
*/
readonly class ExtConf implements SingletonInterface
readonly class ExtConf
{
private string $host;

Expand All @@ -33,22 +28,10 @@

private string $domain;

public function __construct(ExtensionConfiguration $extensionConfiguration)
public function __construct(array $extensionSettings)
{
try {
$extConf = (array)$extensionConfiguration->get('plesk_widget');

$this->host = trim((string)($extConf['host'] ?? ''));
$this->port = (int)($extConf['port'] ?? 8443);
$this->username = trim((string)($extConf['username'] ?? ''));
$this->password = trim((string)($extConf['password'] ?? ''));

$this->diskUsageType = trim((string)($extConf['diskUsageType'] ?? '%'));
$this->domain = trim((string)($extConf['domain'] ?? ''));
} catch (ExtensionConfigurationExtensionNotConfiguredException $extensionConfigurationExtensionNotConfiguredException) {
// Do nothing. The values will still be empty. We catch that as Exception just before the first API call
} catch (ExtensionConfigurationPathDoesNotExistException $extensionConfigurationPathDoesNotExistException) {
// Can never be called, as $path is not set
foreach ($extensionSettings as $property => $value) {
$this->{$property} = $value;
}
}

Expand Down
66 changes: 66 additions & 0 deletions Classes/Configuration/ExtConfFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package stefanfroemken/plesk-widget.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace StefanFroemken\PleskWidget\Configuration;

use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Utility\MathUtility;

readonly class ExtConfFactory
{
private const DEFAULT_SETTINGS = [
'host' => '',
'port' => 8443,
'username' => '',
'password' => '',
'diskUsageType' => '%',
'domain' => '',
];

public function __construct(private ExtensionConfiguration $extensionConfiguration) {}

public function create(): ExtConf
{
return new ExtConf($this->getExtensionSettings());
}

private function getExtensionSettings(): array
{
$extensionSettings = self::DEFAULT_SETTINGS;

try {
$extensionSettings = (array)$this->extensionConfiguration->get('plesk_widget');

// Remove whitespaces
$extensionSettings = array_map('trim', $extensionSettings);

// remove empty values
$extensionSettings = array_filter($extensionSettings);

$extensionSettings = array_merge(self::DEFAULT_SETTINGS, $extensionSettings);

// Special handling for integer value "port"
if (MathUtility::canBeInterpretedAsInteger($extensionSettings['port'])) {
$extensionSettings['port'] = (int)$extensionSettings['port'];
} else {
$extensionSettings['port'] = self::DEFAULT_SETTINGS['port'];
}
} catch (ExtensionConfigurationExtensionNotConfiguredException) {
// Do nothing. Keep the default values
} catch (ExtensionConfigurationPathDoesNotExistException) {
// Will never be thrown, as $path is not given
}

return $extensionSettings;
}
}
2 changes: 1 addition & 1 deletion Configuration/Icons.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* This file is part of the package jweiland/glossary2.
* This file is part of the package stefanfroemken/plesk-widget.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
Expand Down
3 changes: 3 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ services:
iconIdentifier: 'ext-plesk-widget-icon'
height: 'medium'

StefanFroemken\PleskWidget\Configuration\ExtConf:
factory: ['@StefanFroemken\PleskWidget\Configuration\ExtConfFactory', 'create']

StefanFroemken\PleskWidget\Service\PleskSiteService:
arguments:
$cache: '@cache.runtime'
Loading
Loading