Skip to content

Commit

Permalink
[TASK] Adjust tests and add PHP 8.3 build
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Jan 15, 2024
1 parent a2444d5 commit 9bb2fbe
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ jobs:
- php: "8.1"
typo3: "^11.5"
- php: "8.1"
typo3: "^12.1"
typo3: "^12.4"
- php: "8.2"
typo3: "^12.1"
typo3: "^12.4"
- php: "8.3"
typo3: "^12.4"

runs-on: ubuntu-latest

Expand Down
37 changes: 37 additions & 0 deletions Tests/Unit/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use TYPO3\CMS\Core\Charset\CharsetConverter;
use TYPO3\CMS\Core\Core\ApplicationContext;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Localization\Locale;
use TYPO3\CMS\Core\Localization\Locales;
use TYPO3\CMS\Core\Localization\LocalizationFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3Fluid\Fluid\Core\Parser\Interceptor\Escape;
Expand Down Expand Up @@ -257,4 +260,38 @@ protected function createInstance()
$instanceClassName = $this->createInstanceClassName();
return new $instanceClassName();
}

protected function mockForLocalizationUtilityCalls(array $returnValeMap): void
{
$languageService = $this->getMockBuilder(LanguageService::class)->disableOriginalConstructor()->getMock();

$this->singletonInstances[LocalizationFactory::class] = $this->getMockBuilder(LocalizationFactory::class)
->setMethods(['getParsedData'])
->disableOriginalConstructor()
->getMock();
$this->singletonInstances[LocalizationFactory::class]->method('getParsedData')->willReturn([]);

if (class_exists(LanguageServiceFactory::class)) {
$languageServiceFactory = $this->getMockBuilder(LanguageServiceFactory::class)
->onlyMethods(['create'])
->disableOriginalConstructor()
->getMock();
$languageServiceFactory->method('create')->willReturn($languageService);

GeneralUtility::addInstance(LanguageServiceFactory::class, $languageServiceFactory);
}

if (class_exists(Locales::class)) {
$locale = new Locale();
$locales = $this->getMockBuilder(Locales::class)
->onlyMethods(['createLocaleFromRequest'])
->disableOriginalConstructor()
->getMock();
$locales->method('createLocaleFromRequest')->willReturn($locale);

$this->singletonInstances[Locales::class] = $locales;
}

$GLOBALS['LANG'] = $languageService;
}
}
13 changes: 3 additions & 10 deletions Tests/Unit/ViewHelpers/LViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Localization\LocalizationFactory;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
* Class LViewHelperTest
Expand All @@ -30,11 +28,7 @@ protected function setUp(): void
$cache->method('get')->willReturn($languageService);

$this->singletonInstances[ConfigurationManagerInterface::class] = $this->getMockBuilder(ConfigurationManagerInterface::class)->getMockForAbstractClass();
$this->singletonInstances[LocalizationFactory::class] = $this->getMockBuilder(LocalizationFactory::class)
->setMethods(['getParsedData'])
->disableOriginalConstructor()
->getMock();
$this->singletonInstances[LocalizationFactory::class]->method('getParsedData')->willReturn([]);

$this->singletonInstances[CacheManager::class] = $this->getMockBuilder(CacheManager::class)
->setMethods(['getCache'])
->disableOriginalConstructor()
Expand All @@ -51,10 +45,9 @@ protected function setUp(): void
);
}

parent::setUp();
$this->mockForLocalizationUtilityCalls([]);

$GLOBALS['TSFE'] = $this->getMockBuilder(TypoScriptFrontendController::class)->disableOriginalConstructor()->getMock();
$GLOBALS['LANG'] = $this->getMockBuilder(LanguageService::class)->disableOriginalConstructor()->getMock();
parent::setUp();
}

protected function tearDown(): void
Expand Down
11 changes: 2 additions & 9 deletions Tests/Unit/ViewHelpers/OrViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Localization\LocalizationFactory;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
Expand All @@ -29,10 +28,6 @@ protected function setUp(): void
$cache->method('has')->willReturn(true);
$cache->method('get')->willReturn($languageService);

$this->singletonInstances[LocalizationFactory::class] = $this->getMockBuilder(LocalizationFactory::class)
->disableOriginalConstructor()
->getMock();
$this->singletonInstances[LocalizationFactory::class]->method('getParsedData')->willReturn([]);
$this->singletonInstances[ConfigurationManagerInterface::class] = $this->getMockBuilder(ConfigurationManagerInterface::class)->getMockForAbstractClass();
$this->singletonInstances[CacheManager::class] = $this->getMockBuilder(CacheManager::class)
->setMethods(['getCache'])
Expand All @@ -49,13 +44,11 @@ protected function setUp(): void
);
}

$this->mockForLocalizationUtilityCalls([]);

parent::setUp();

$GLOBALS['TSFE'] = $this->getMockBuilder(TypoScriptFrontendController::class)->disableOriginalConstructor()->getMock();
$GLOBALS['LANG'] = $this->getMockBuilder(LanguageService::class)
->setMethods(['dummy'])
->disableOriginalConstructor()
->getMock();
$GLOBALS['TYPO3_REQUEST'] = null;
}

Expand Down

0 comments on commit 9bb2fbe

Please sign in to comment.