Skip to content

Commit

Permalink
TASK: Make extension v12 compatible (#50)
Browse files Browse the repository at this point in the history
* TASK: Make extension v12 compatible

* TASK: Move properties to setup method

* TASK: Use LanguageServiceFactory

* TASK: Fix test for v12
  • Loading branch information
sabbelasichon authored Jun 12, 2023
1 parent fab74d9 commit a73e72d
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 81 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,34 @@ jobs:
strategy:
max-parallel: 2
matrix:
php-versions: [ 7.4, 8.0, 8.1 ]
typo3-versions:
- { typo3: 10, testing: 6 }
- { typo3: 11, testing: 6 }
- { typo3: 12, testing: 6 }
- { typo3: ^10.4, testing: ^6, php: 7.4 }
- { typo3: ^11.5, testing: ^7, php: 8.1 }
- { typo3: ^12.4, testing: ^7, php: 8.1 }

name: "Run tests with PHP ${{ matrix.php-versions }}
name: "Run tests with PHP ${{ matrix.typo3-versions.php }}
using TYPO3 ${{ matrix.typo3-versions.typo3 }}
with testing framework version ${{ matrix.typo3-versions.testing }}"
steps:
- uses: actions/checkout@v3

- uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php-versions }}"
php-version: "${{ matrix.typo3-versions.php }}"
extensions: intl, mbstring, pdo_sqlite, pdo_mysql
tools: composer:v2
coverage: none
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Start MySQL
run: sudo /etc/init.d/mysql start

- name: Run composer require
run: "composer require typo3/testing-framework:${{ matrix.typo3-versions.testing }} typo3/cms-core:${{ matrix.typo3-versions.typo3 }}"

# see https://github.com/ramsey/composer-install
- uses: "ramsey/composer-install@v2"
- uses: "ramsey/composer-install@v2"

- name: "Run Unit tests"
run: composer test-unit
Expand Down
10 changes: 5 additions & 5 deletions Classes/Middleware/LoggingMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
use Symfony\Component\Messenger\Middleware\StackInterface;
Expand All @@ -22,10 +22,10 @@ final class LoggingMiddleware implements MiddlewareInterface, LoggerAwareInterfa
{
use LoggerAwareTrait;

/**
* @var LoggerInterface
*/
protected $logger;
public function __construct()
{
$this->logger = new NullLogger();
}

public function handle(Envelope $envelope, StackInterface $stack): Envelope
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/Build/FunctionalTests.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="true" bootstrap="../../.Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php" colors="true" processIsolation="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="true" bootstrap="../../.Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>../../Classes/</directory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Ssch\T3Messenger\Tests\Functional\Fixtures\Extensions\t3_messenger_test\Classes\Controller;

use Psr\Http\Message\ResponseInterface;
use Ssch\T3Messenger\Tests\Functional\Fixtures\Extensions\t3_messenger_test\Classes\Command\MyCommand;
use Ssch\T3Messenger\Tests\Functional\Fixtures\Extensions\t3_messenger_test\Classes\Service\MyService;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
Expand All @@ -24,8 +25,15 @@ public function __construct(MyService $myService)
$this->myService = $myService;
}

/**
* @return void|ResponseInterface
*/
public function dispatchAction()
{
$this->myService->dispatch(new MyCommand('[email protected]'));

if (method_exists($this, 'htmlResponse')) {
return $this->htmlResponse();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ final class MyMessengerHandler implements MessageSubscriberInterface, LoggerAwar
{
use LoggerAwareTrait;

public function __invoke(MyOtherCommand $command): void
{
$this->logger->info(sprintf('Hi %s', $command->getNote()));
}

public function firstMessageMethod(MyCommand $command): void
{
$this->logger->info(sprintf('Hi %s', $command->getEmail()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* LICENSE.txt file that was distributed with this source code.
*/

use Ssch\T3Messenger\Tests\Functional\Fixtures\Extensions\t3_messenger_test\Classes\Controller\MessengerController;
use Ssch\T3Messenger\Tests\Functional\Fixtures\Extensions\t3_messenger_test\Classes\EventListener\BeforeMailerSentMessageEventListener;
use Ssch\T3Messenger\Tests\Functional\Fixtures\Extensions\t3_messenger_test\Classes\Handlers\MyMessengerHandler;
use Ssch\T3Messenger\Tests\Functional\Fixtures\Extensions\t3_messenger_test\Classes\Service\MyService;
Expand All @@ -26,4 +27,5 @@
$services->set(BeforeMailerSentMessageEventListener::class)->tag('event.listener', [
'event' => BeforeMailerSentMessageEvent::class,
]);
$services->set(MessengerController::class);
};
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
<?php

declare(strict_types=1);

/*
* This file is part of the "t3_messenger" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

defined('TYPO3_MODE') || die('Access denied.');

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'T3MessengerTest',
'Messenger',
Expand Down
34 changes: 16 additions & 18 deletions Tests/Functional/Mailer/MessengerMailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,26 @@ final class MessengerMailerTest extends FunctionalTestCase
{
use MailerAssertionsTrait;

protected bool $initializeDatabase = false;

protected array $testExtensionsToLoad = [
'typo3conf/ext/typo3_psr_cache_adapter',
'typo3conf/ext/t3_messenger',
'typo3conf/ext/t3_messenger/Tests/Functional/Fixtures/Extensions/t3_messenger_test',
];

protected array $configurationToUseInTestInstance = [
'MAIL' => [
'transport' => 'null',
'defaultMailFromAddress' => '[email protected]',
'defaultMailFromName' => 'Mustermann AG',
'defaultMailReplyToAddress' => '[email protected]',
'defaultMailReplyToName' => 'Mustermann AG',
],
];

private MailerInterface $subject;

protected function setUp(): void
{
$this->initializeDatabase = false;
$this->configurationToUseInTestInstance = [
'MAIL' => [
'transport' => 'null',
'defaultMailFromAddress' => '[email protected]',
'defaultMailFromName' => 'Mustermann AG',
'defaultMailReplyToAddress' => '[email protected]',
'defaultMailReplyToName' => 'Mustermann AG',
],
];
$this->testExtensionsToLoad = [
'typo3conf/ext/typo3_psr_cache_adapter',
'typo3conf/ext/t3_messenger',
'typo3conf/ext/t3_messenger/Tests/Functional/Fixtures/Extensions/t3_messenger_test',
];

parent::setUp();
$this->subject = $this->get(MailerInterface::class);
}
Expand Down
23 changes: 11 additions & 12 deletions Tests/Functional/MessengerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Symfony\Component\Messenger\Transport\TransportInterface;
use Symfony\Component\Messenger\Worker;
use TYPO3\CMS\Core\Http\Uri;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -33,20 +33,19 @@ final class MessengerTest extends FunctionalTestCase
{
private const ROOT_PAGE_UID = 1;

protected array $testExtensionsToLoad = [
'typo3conf/ext/typo3_psr_cache_adapter',
'typo3conf/ext/t3_messenger',
'typo3conf/ext/t3_messenger/Tests/Functional/Fixtures/Extensions/t3_messenger_test',
];

protected array $pathsToLinkInTestInstance = [
'typo3conf/ext/t3_messenger/Tests/Functional/Fixtures/sites' => 'typo3conf/sites',
];

private Site $site;

protected function setUp(): void
{
$this->pathsToLinkInTestInstance = [
'typo3conf/ext/t3_messenger/Tests/Functional/Fixtures/sites' => 'typo3conf/sites',
];
$this->testExtensionsToLoad = [
'typo3conf/ext/typo3_psr_cache_adapter',
'typo3conf/ext/t3_messenger',
'typo3conf/ext/t3_messenger/Tests/Functional/Fixtures/Extensions/t3_messenger_test',
];

parent::setUp();
$this->importDataSet(__DIR__ . '/Fixtures/Database/pages.xml');
$this->setUpFrontendRootPage(
Expand All @@ -55,7 +54,7 @@ protected function setUp(): void
);

$this->site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByRootPageId(self::ROOT_PAGE_UID);
$GLOBALS['LANG'] = $this->get(LanguageService::class);
$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->create('en');
}

public function testThatCommandIsRoutedToAsyncTransportSuccessfully(): void
Expand Down
34 changes: 16 additions & 18 deletions Tests/Functional/Mime/BodyRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,28 @@ final class BodyRendererTest extends FunctionalTestCase
{
use MailerAssertionsTrait;

protected bool $initializeDatabase = false;

protected array $testExtensionsToLoad = [
'typo3conf/ext/typo3_psr_cache_adapter',
'typo3conf/ext/t3_messenger',
'typo3conf/ext/t3_messenger/Tests/Functional/Fixtures/Extensions/t3_messenger_test',
];

protected array $configurationToUseInTestInstance = [
'MAIL' => [
'transport' => 'null',
'defaultMailFromAddress' => '[email protected]',
'defaultMailFromName' => 'Mustermann AG',
'defaultMailReplyToAddress' => '[email protected]',
'defaultMailReplyToName' => 'Mustermann AG',
],
];

private BodyRendererInterface $subject;

private MailerInterface $mailer;

protected function setUp(): void
{
$this->initializeDatabase = false;
$this->configurationToUseInTestInstance = [
'MAIL' => [
'transport' => 'null',
'defaultMailFromAddress' => '[email protected]',
'defaultMailFromName' => 'Mustermann AG',
'defaultMailReplyToAddress' => '[email protected]',
'defaultMailReplyToName' => 'Mustermann AG',
],
];
$this->testExtensionsToLoad = [
'typo3conf/ext/typo3_psr_cache_adapter',
'typo3conf/ext/t3_messenger',
'typo3conf/ext/t3_messenger/Tests/Functional/Fixtures/Extensions/t3_messenger_test',
];

parent::setUp();
$this->subject = $this->get(BodyRendererInterface::class);
$this->mailer = $this->get(MailerInterface::class);
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
],
"require": {
"php": "^7.4 || ^8.0",
"typo3/cms-core": "^10.4 || ^11.5 || ^12.1",
"typo3/cms-extbase": "^10.4 || ^11.5 || ^12.1",
"typo3/cms-core": "^10.4 || ^11.5 || ^12.4",
"typo3/cms-extbase": "^10.4 || ^11.5 || ^12.4",
"symfony/messenger": "^5.0 || ^6.2",
"symfony/options-resolver": "^5.0 || ^6.2",
"symfony/doctrine-messenger": "^5.0 || ^6.2",
"psr/cache": "^1.0",
"ssch/typo3-psr-cache-adapter": "^1.1"
"psr/cache": "^1.0 || ^2.0",
"ssch/typo3-psr-cache-adapter": "^1.2"
},
"require-dev": {
"symplify/easy-coding-standard": "^11.1",
Expand All @@ -33,10 +33,10 @@
"phpstan/phpstan-strict-rules": "^1.4",
"saschaegerer/phpstan-typo3": "^1.8",
"phpstan/extension-installer": "^1.2",
"typo3/testing-framework": "^7.0.2",
"helhum/typo3-console": "^7.1",
"typo3/minimal": "^10.4 || ^11.5 || ^12.0",
"typo3/cms-lowlevel": "^10.4 || ^11.5 || ^12.0",
"typo3/testing-framework": "^6.0 || ^7.0.2",
"helhum/typo3-console": "^6.0 || ^7.1 || ^8.0",
"typo3/minimal": "^10.4 || ^11.5 || ^12.4",
"typo3/cms-lowlevel": "^10.4 || ^11.5 || ^12.4",
"symfony/serializer": "^5.0 || ^6.2"
},
"replace": {
Expand Down
6 changes: 6 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
__DIR__ . '/Tests',
__DIR__ . '/Configuration',
__DIR__ . '/ecs.php',
__DIR__ . '/ext_localconf.php',
]);

$ecsConfig->ruleWithConfiguration(ArraySyntaxFixer::class, [
Expand Down Expand Up @@ -62,4 +63,9 @@
],);

$ecsConfig->sets([SetList::PSR_12, SetList::SYMPLIFY, SetList::COMMON, SetList::CLEAN_CODE]);

$ecsConfig->skip([
DeclareStrictTypesFixer::class => [__DIR__ . '/ext_localconf.php', __DIR__ . '/**/ext_localconf.php'],
HeaderCommentFixer::class => [__DIR__ . '/ext_localconf.php', __DIR__ . '/**/ext_localconf.php'],
]);
};
4 changes: 3 additions & 1 deletion ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

defined('TYPO3_MODE') || defined('TYPO3') || die('Access denied.');

if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['t3_messenger']) || !is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['t3_messenger'])) {
if (! isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['t3_messenger']) || ! is_array(
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['t3_messenger']
)) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['t3_messenger'] = [
'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
'backend' => \TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend::class,
Expand Down

0 comments on commit a73e72d

Please sign in to comment.