Skip to content
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
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/.github/ export-ignore
/Build/ export-ignore
/Tests/ export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitlab-ci.yml export-ignore
/codeception.dist.yml export-ignore
/crowdin.yml export-ignore
/Makefile export-ignore
/rector.php export-ignore
/shell.nix export-ignore
/shell.nix export-ignore
39 changes: 39 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ jobs:
- name: Install xmllint
run: sudo apt-get update && sudo apt-get install -y libxml2-utils

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
tools: composer:v2

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: XML lint
run: Build/Scripts/lint-xml.sh

Expand Down Expand Up @@ -135,3 +144,33 @@ jobs:

- name: Code Quality (by PHPStan)
run: Build/Scripts/phpstan.sh

tests-unit-and-functional:
runs-on: ubuntu-latest
needs:
- coding-guideline
- code-quality
strategy:
matrix:
php-version:
- 8.2
- 8.3
- 8.4
- 8.5
steps:
- uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php-version }}"
tools: composer:v2

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run unit tests
run: Build/Scripts/phpunit.sh unit

- name: Run functional tests
run: Build/Scripts/phpunit.sh functional
1 change: 1 addition & 0 deletions Build/.php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => ['space' => 'none'],
'declare_parentheses' => true,
'declare_strict_types' => true,
'dir_constant' => true,
'function_to_constant' => ['functions' => ['get_called_class', 'get_class', 'get_class_this', 'php_sapi_name', 'phpversion', 'pi']],
'modernize_strpos' => true,
Expand Down
63 changes: 63 additions & 0 deletions Build/Scripts/coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash
#
# Runs all phpunit tests and measures the code coverage of Classes/.
#
# Usage:
# Build/Scripts/coverage.sh [additional phpunit arguments]
#
# Every testsuite defined in Build/phpunit.xml.dist runs in its own phpunit
# process, like in phpunit.sh, the functional bootstrap leaks global state
# into the unit tests. The coverage of all suites is merged with phpcov, the
# summary is printed and the html report is written to
# .Build/coverage/index.html.
#
# Requirements:
# - php with xdebug or pcov
#
# Environment variables used as overrides:
# typo3DatabaseDriver database driver to test against, defaults to "pdo_sqlite"

source "$(dirname "${BASH_SOURCE[0]}")/common.sh"

requireBinary phpunit
requireBinary phpcov

if ! runPhp -r 'exit(extension_loaded("xdebug") || extension_loaded("pcov") ? 0 : 1);'; then
echo "Missing coverage driver, please enable xdebug or pcov." >&2
exit 1
fi

export typo3DatabaseDriver="${typo3DatabaseDriver:-pdo_sqlite}"
export XDEBUG_MODE=coverage

COVERAGE_PATH="${PROJECT_ROOT}/.Build/coverage"
COVERAGE_DATA_PATH="${COVERAGE_PATH}/data"
rm -rf "${COVERAGE_PATH}"
mkdir -p "${COVERAGE_DATA_PATH}"

mapfile -t SUITES < <(runPhp "${BIN_DIR}/phpunit" -c Build/phpunit.xml.dist --list-suites \
| sed -n 's/^ - \(.*\) ([0-9]\{1,\} tests\{0,1\})$/\1/p')

if [ ${#SUITES[@]} -eq 0 ]; then
echo "No testsuites found in Build/phpunit.xml.dist." >&2
exit 1
fi

STATUS=0
for suite in "${SUITES[@]}"; do
echo "Running testsuite \"${suite}\" ..."
runPhp "${BIN_DIR}/phpunit" \
-c Build/phpunit.xml.dist \
--testsuite "${suite}" \
--coverage-php "${COVERAGE_DATA_PATH}/${suite}.cov" \
"$@" || STATUS=$?
done

runPhp "${BIN_DIR}/phpcov" merge \
--text php://stdout \
--html "${COVERAGE_PATH}" \
"${COVERAGE_DATA_PATH}"

echo "HTML report: ${COVERAGE_PATH}/index.html"

exit "${STATUS}"
2 changes: 1 addition & 1 deletion Build/Scripts/lint-php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

source "$(dirname "${BASH_SOURCE[0]}")/common.sh"

find ./*.php Classes Configuration -name '*.php' -print0 \
find ./*.php Classes Configuration Tests -name '*.php' -print0 \
| xargs -0 -n 1 -P 4 "${PHP_BIN}" -l
9 changes: 7 additions & 2 deletions Build/Scripts/lint-xml.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env bash
#
# Validates the XLIFF files in Resources/Private/Language against XLIFF 1.2
# strict (Build/xliff-core-1.2-strict.xsd, imports Build/xml.xsd).
# Validates the xml files of the extension against their schemas:
# - XLIFF files in Resources/Private/Language against XLIFF 1.2 strict
# (Build/xliff-core-1.2-strict.xsd, imports Build/xml.xsd)
# - Build/phpunit.xml.dist against the schema of the installed PHPUnit
#
# xmllint is not installed via composer. It is provided by shell.nix, in CI it
# is installed via apt (libxml2-utils).
Expand All @@ -15,8 +17,11 @@ if ! command -v xmllint > /dev/null; then
echo "Missing xmllint, please install it first, e.g. the package libxml2-utils." >&2
exit 1
fi
requireBinary phpunit

if [ -d Resources/Private/Language ]; then
find Resources/Private/Language -name '*.xlf' -print0 \
| xargs -0 -r xmllint --schema Build/xliff-core-1.2-strict.xsd --noout
fi

xmllint --schema .Build/vendor/phpunit/phpunit/phpunit.xsd --noout Build/phpunit.xml.dist
57 changes: 57 additions & 0 deletions Build/Scripts/phpunit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
#
# Runs the phpunit tests.
#
# Usage:
# Build/Scripts/phpunit.sh [testsuite] [additional phpunit arguments]
#
# Without a testsuite every suite defined in Build/phpunit.xml.dist is run,
# each one in its own phpunit process. They cannot share a process, the
# functional bootstrap leaks global state into the unit tests. The first
# argument is taken as the testsuite name unless it starts with a dash.
#
# Environment variables used as overrides:
# typo3DatabaseDriver database driver to test against, defaults to "pdo_sqlite"

source "$(dirname "${BASH_SOURCE[0]}")/common.sh"

requireBinary phpunit

export typo3DatabaseDriver="${typo3DatabaseDriver:-pdo_sqlite}"

runSuite() {
local suite="$1"
shift

runPhp "${BIN_DIR}/phpunit" \
-c Build/phpunit.xml.dist \
--testsuite "${suite}" \
--display-warnings \
--display-deprecations \
--display-errors \
--display-notices \
"$@"
}

if [ $# -gt 0 ] && [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then
TESTSUITE="$1"
shift
runSuite "${TESTSUITE}" "$@"
exit $?
fi

mapfile -t SUITES < <(runPhp "${BIN_DIR}/phpunit" -c Build/phpunit.xml.dist --list-suites \
| sed -n 's/^ - \(.*\) ([0-9]\{1,\} tests\{0,1\})$/\1/p')

if [ ${#SUITES[@]} -eq 0 ]; then
echo "No testsuites found in Build/phpunit.xml.dist." >&2
exit 1
fi

STATUS=0
for suite in "${SUITES[@]}"; do
echo "Running testsuite \"${suite}\" ..."
runSuite "${suite}" "$@" || STATUS=$?
done

exit "${STATUS}"
2 changes: 1 addition & 1 deletion Build/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ parameters:
paths:
- ../Classes
- ../Configuration
- ../ext_emconf.php
- ../Tests
- ../ext_localconf.php
33 changes: 33 additions & 0 deletions Build/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<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="../.Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php"
cacheResult="false"
colors="true"
failOnDeprecation="true"
failOnWarning="true"
failOnRisky="true"
processIsolation="false"
requireCoverageMetadata="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
>
<coverage/>
<testsuites>
<testsuite name="functional">
<directory>../Tests/Functional/</directory>
</testsuite>
<testsuite name="unit">
<directory>../Tests/Unit/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">../Classes/</directory>
</include>
</source>
</phpunit>
4 changes: 3 additions & 1 deletion Classes/Controller/Order/PaymentController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Extcode\CartGirosolution\Controller\Order;

/*
Expand Down Expand Up @@ -143,7 +145,7 @@ public function notifyAction(): ResponseInterface
}

$notify->sendOkStatus();
return $this->htmlResponse();
return $this->htmlResponse('');
}

private function updatePaymentAndTransaction($notify, Item $orderItem, string $status): bool
Expand Down
2 changes: 1 addition & 1 deletion Classes/EventListener/Order/Payment/ProviderRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __invoke(PaymentEvent $event): void

$payment = $this->orderItem->getPayment();
$provider = $payment->getProvider();
[$provider, $clearingType] = explode('_', (string)$provider);
[$provider, $clearingType] = array_pad(explode('_', (string)$provider), 2, '');

if ($provider !== 'GIROSOLUTION') {
return;
Expand Down
41 changes: 32 additions & 9 deletions Configuration/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,51 @@

namespace Extcode\CartGirosolution\Configuration;

use Extcode\Cart\Event\Order\PaymentEvent;
use Extcode\Cart\EventListener\Order\Finish\Email;
use Extcode\CartGirosolution\Event\Order\FinishEvent;
use Extcode\CartGirosolution\EventListener\Order\Payment\ClearCart;
use Extcode\CartGirosolution\EventListener\Order\Payment\ProviderRedirect;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

use function Symfony\Component\DependencyInjection\Loader\Configurator\tagged_iterator;

return static function (ContainerConfigurator $containerConfigurator, ContainerBuilder $container) {
return static function (ContainerConfigurator $containerConfigurator, ContainerBuilder $container): void {
$services = $containerConfigurator->services();
$services
->instanceof(CredentialLoaderInterface::class)
->tag('cartGirosolution.credentialLoader');

$services
->defaults()
->autowire()
->autoconfigure();
->autoconfigure()
->private();

$services
->instanceof(CredentialLoaderInterface::class)
->tag('cartGirosolution.credentialLoader');

$services
->load(
'Extcode\\CartGirosolution\\Configuration\\',
'../Classes/Configuration/'
);
->load('Extcode\\CartGirosolution\\', '../Classes/*');

$services->set(CredentialLoaderRegistry::class)
->arg('$credentialLoaders', tagged_iterator('cartGirosolution.credentialLoader'));

$services->set(ClearCart::class)
->tag('event.listener', [
'identifier' => 'cart-girosolution--order--payment--clear-cart',
'event' => PaymentEvent::class,
'before' => 'cart-girosolution--order--payment--provider-redirect',
]);

$services->set(ProviderRedirect::class)
->tag('event.listener', [
'identifier' => 'cart-girosolution--order--payment--provider-redirect',
'event' => PaymentEvent::class,
]);

$services->set('cart-girosolution--event-listener--order--finish--email', Email::class)
->tag('event.listener', [
'identifier' => 'cart-girosolution--order--finish--email',
'event' => FinishEvent::class,
]);
};
30 changes: 0 additions & 30 deletions Configuration/Services.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions Configuration/TCA/Overrides/sys_template.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

defined('TYPO3') or die();

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
Expand Down
Loading
Loading