From 9872a5e027a9e8f4adda04766b0d1dd4b44106ea Mon Sep 17 00:00:00 2001 From: Susanne Moog <look@susi.dev> Date: Tue, 8 Nov 2022 18:42:50 +0100 Subject: [PATCH] [TASK] Rewrite YamlLoaderTests as functional tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The YamlLoaderTests are better suited as functional tests as they access the file system and require accessible mocks otherwise. Resolves: #99025 Releases: main Change-Id: I2d355c5d19494408da2d1512f5f8c742087dd9a2 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/76490 Tested-by: Stefan Bürk <stefan@buerk.tech> Tested-by: core-ci <typo3@b13.com> Tested-by: Oliver Hader <oliver.hader@typo3.org> Reviewed-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Oliver Hader <oliver.hader@typo3.org> --- .../Configuration/Loader/Fixtures/Berta.yaml | 4 + .../Loader/Fixtures/Env/Berta.yaml} | 2 +- .../Loader/Fixtures/Env/Env_barbaz.yaml} | 0 .../Loader/Fixtures/Env/Secondfile.yaml | 5 + .../Loader/Fixtures/LoadWithAnImport.yaml | 7 + .../LoadWithImportAndRelativeFiles.yaml} | 0 .../Fixtures/LoadWithMultipleImports.yaml | 8 + .../Fixtures/LoadWithNestedPlaceholders.yaml | 6 + .../Loader/Fixtures/LoadWithPlaceholders.yaml | 7 + .../Loader/Fixtures/Placeholder/Berta.yaml | 5 + .../Loader/Fixtures/Placeholder/Foo.yaml} | 0 .../Loader/Fixtures/SecondImportedFile.yaml | 3 + .../Fixtures/Subfolder/BaseTestInclusion.yaml | 0 .../Loader/Fixtures/ThirdImportedFile.yaml | 2 + .../Loader/YamlFileLoaderTest.php | 208 +++++++++++++ .../Loader/Fixtures/Env/Secondfile.yml | 5 - .../Loader/Fixtures/Placeholder/Berta.yml | 5 - .../Loader/YamlFileLoaderTest.php | 284 +----------------- 18 files changed, 257 insertions(+), 294 deletions(-) create mode 100644 typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Berta.yaml rename typo3/sysext/core/Tests/{Unit/Configuration/Loader/Fixtures/Env/Berta.yml => Functional/Configuration/Loader/Fixtures/Env/Berta.yaml} (56%) rename typo3/sysext/core/Tests/{Unit/Configuration/Loader/Fixtures/Env/Env_barbaz.yml => Functional/Configuration/Loader/Fixtures/Env/Env_barbaz.yaml} (100%) create mode 100644 typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Env/Secondfile.yaml create mode 100644 typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithAnImport.yaml rename typo3/sysext/core/Tests/{Unit/Configuration/Loader/Fixtures/Berta.yaml => Functional/Configuration/Loader/Fixtures/LoadWithImportAndRelativeFiles.yaml} (100%) create mode 100644 typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithMultipleImports.yaml create mode 100644 typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithNestedPlaceholders.yaml create mode 100644 typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithPlaceholders.yaml create mode 100644 typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Placeholder/Berta.yaml rename typo3/sysext/core/Tests/{Unit/Configuration/Loader/Fixtures/Placeholder/Foo.yml => Functional/Configuration/Loader/Fixtures/Placeholder/Foo.yaml} (100%) create mode 100644 typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/SecondImportedFile.yaml rename typo3/sysext/core/Tests/{Unit => Functional}/Configuration/Loader/Fixtures/Subfolder/BaseTestInclusion.yaml (100%) create mode 100644 typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/ThirdImportedFile.yaml create mode 100644 typo3/sysext/core/Tests/Functional/Configuration/Loader/YamlFileLoaderTest.php delete mode 100644 typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Env/Secondfile.yml delete mode 100644 typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Placeholder/Berta.yml diff --git a/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Berta.yaml b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Berta.yaml new file mode 100644 index 000000000000..39e2c0f3e56f --- /dev/null +++ b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Berta.yaml @@ -0,0 +1,4 @@ +options: + - option1 + - option2 +betterthanbefore: 1 diff --git a/typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Env/Berta.yml b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Env/Berta.yaml similarity index 56% rename from typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Env/Berta.yml rename to typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Env/Berta.yaml index 5f8748c16779..ee056e650e2c 100644 --- a/typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Env/Berta.yml +++ b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Env/Berta.yaml @@ -1,5 +1,5 @@ imports: - - { resource: Secondfile.yml } + - { resource: Secondfile.yaml } options: - option1 diff --git a/typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Env/Env_barbaz.yml b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Env/Env_barbaz.yaml similarity index 100% rename from typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Env/Env_barbaz.yml rename to typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Env/Env_barbaz.yaml diff --git a/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Env/Secondfile.yaml b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Env/Secondfile.yaml new file mode 100644 index 000000000000..2c8c6017bf96 --- /dev/null +++ b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Env/Secondfile.yaml @@ -0,0 +1,5 @@ +imports: + - { resource: Env_%env("foo")%.yaml } + +options: + - optionBefore diff --git a/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithAnImport.yaml b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithAnImport.yaml new file mode 100644 index 000000000000..422b9d25c804 --- /dev/null +++ b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithAnImport.yaml @@ -0,0 +1,7 @@ +imports: + - { resource: SecondImportedFile.yaml } + +options: + - option1 + - option2 +betterthanbefore: 1 diff --git a/typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Berta.yaml b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithImportAndRelativeFiles.yaml similarity index 100% rename from typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Berta.yaml rename to typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithImportAndRelativeFiles.yaml diff --git a/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithMultipleImports.yaml b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithMultipleImports.yaml new file mode 100644 index 000000000000..5dc7aadd004b --- /dev/null +++ b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithMultipleImports.yaml @@ -0,0 +1,8 @@ +imports: + - { resource: SecondImportedFile.yaml } + - { resource: ThirdImportedFile.yaml } + +options: + - option1 + - option2 +betterthanbefore: 1 diff --git a/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithNestedPlaceholders.yaml b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithNestedPlaceholders.yaml new file mode 100644 index 000000000000..fa901f7a5099 --- /dev/null +++ b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithNestedPlaceholders.yaml @@ -0,0 +1,6 @@ +firstset: + myinitialversion: 13 +options: + - option1 + - option2 +betterthanbefore: '%env(foo)%' diff --git a/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithPlaceholders.yaml b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithPlaceholders.yaml new file mode 100644 index 000000000000..ad2f3a36e47d --- /dev/null +++ b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithPlaceholders.yaml @@ -0,0 +1,7 @@ +firstset: + myinitialversion: 13 +options: + - option1 + - option2 +betterthanbefore: '%firstset.myinitialversion%' +muchbetterthanbefore: 'some::%options.0%::option' diff --git a/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Placeholder/Berta.yaml b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Placeholder/Berta.yaml new file mode 100644 index 000000000000..2fd5dd4d36a7 --- /dev/null +++ b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Placeholder/Berta.yaml @@ -0,0 +1,5 @@ +imports: + - { resource: '%settings.dynamicOption%.yaml' } + +settings: + dynamicOption: 'Foo' diff --git a/typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Placeholder/Foo.yml b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Placeholder/Foo.yaml similarity index 100% rename from typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Placeholder/Foo.yml rename to typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Placeholder/Foo.yaml diff --git a/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/SecondImportedFile.yaml b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/SecondImportedFile.yaml new file mode 100644 index 000000000000..cf023b8e1093 --- /dev/null +++ b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/SecondImportedFile.yaml @@ -0,0 +1,3 @@ +options: + - optionBefore +betterthanbefore: 2 diff --git a/typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Subfolder/BaseTestInclusion.yaml b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Subfolder/BaseTestInclusion.yaml similarity index 100% rename from typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Subfolder/BaseTestInclusion.yaml rename to typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/Subfolder/BaseTestInclusion.yaml diff --git a/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/ThirdImportedFile.yaml b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/ThirdImportedFile.yaml new file mode 100644 index 000000000000..45589ab459e9 --- /dev/null +++ b/typo3/sysext/core/Tests/Functional/Configuration/Loader/Fixtures/ThirdImportedFile.yaml @@ -0,0 +1,2 @@ +options: + - optionAfterBefore diff --git a/typo3/sysext/core/Tests/Functional/Configuration/Loader/YamlFileLoaderTest.php b/typo3/sysext/core/Tests/Functional/Configuration/Loader/YamlFileLoaderTest.php new file mode 100644 index 000000000000..1a389d263fbf --- /dev/null +++ b/typo3/sysext/core/Tests/Functional/Configuration/Loader/YamlFileLoaderTest.php @@ -0,0 +1,208 @@ +<?php + +declare(strict_types=1); + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +namespace TYPO3\CMS\Core\Tests\Functional\Configuration\Loader; + +use TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; + +class YamlFileLoaderTest extends FunctionalTestCase +{ + protected bool $resetSingletonInstances = true; + + /** + * Generic method to check if the load method returns an array from a YAML file + * + * @test + */ + public function load(): void + { + $fileName = 'EXT:core/Tests/Functional/Configuration/Loader/Fixtures/Berta.yaml'; + + $expected = [ + 'options' => [ + 'option1', + 'option2', + ], + 'betterthanbefore' => 1, + ]; + $output = (new YamlFileLoader())->load($fileName); + self::assertSame($expected, $output); + } + + /** + * Method checking for imports that they have been processed properly + * + * @test + */ + public function loadWithAnImport(): void + { + $fileName = 'EXT:core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithAnImport.yaml'; + + $expected = [ + 'options' => [ + 'optionBefore', + 'option1', + 'option2', + ], + 'betterthanbefore' => 1, + ]; + + $output = (new YamlFileLoader())->load($fileName); + self::assertSame($expected, $output); + } + + /** + * Method checking for multiple imports that they have been loaded in the right order + * + * @test + */ + public function loadWithMultipleImports(): void + { + $fileName = 'EXT:core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithMultipleImports.yaml'; + + $expected = [ + 'options' => [ + 'optionBefore', + 'optionAfterBefore', + 'option1', + 'option2', + ], + 'betterthanbefore' => 1, + ]; + + $output = (new YamlFileLoader())->load($fileName); + self::assertSame($expected, $output); + } + + /** + * Method checking for imports that they have been processed properly + * + * @test + */ + public function loadWithImportAndRelativePaths(): void + { + $fileName = 'EXT:core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithImportAndRelativeFiles.yaml'; + $output = (new YamlFileLoader())->load($fileName); + self::assertSame( + [ + 'enable' => [ + 'frontend' => false, + 'json.api' => true, + 'backend' => true, + 'rest.api' => true, + ], + ], + $output + ); + } + + /** + * Method checking for placeholders + * + * @test + */ + public function loadWithPlaceholders(): void + { + $fileName = 'EXT:core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithPlaceholders.yaml'; + $output = (new YamlFileLoader())->load($fileName); + + $expected = [ + 'firstset' => [ + 'myinitialversion' => 13, + ], + 'options' => [ + 'option1', + 'option2', + ], + 'betterthanbefore' => 13, + 'muchbetterthanbefore' => 'some::option1::option', + ]; + + self::assertSame($expected, $output); + } + + /** + * Method checking for nested placeholders + * + * @test + */ + public function loadWithNestedPlaceholders(): void + { + $fileName = 'EXT:core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithNestedPlaceholders.yaml'; + + $expected = [ + 'firstset' => [ + 'myinitialversion' => 13, + ], + 'options' => [ + 'option1', + 'option2', + ], + 'betterthanbefore' => 13, + ]; + + putenv('foo=%firstset.myinitialversion%'); + $output = (new YamlFileLoader())->load($fileName); + putenv('foo='); + self::assertSame($expected, $output); + } + + /** + * Method checking for imports with env vars that they have been processed properly + * + * @test + */ + public function loadWithImportAndEnvVars(): void + { + $loader = new YamlFileLoader(); + + putenv('foo=barbaz'); + $output = $loader->load('EXT:core/Tests/Functional/Configuration/Loader/Fixtures/Env/Berta.yaml'); + putenv('foo='); + + $expected = [ + 'loadedWithEnvVars' => 1, + 'options' => [ + 'optionBefore', + 'option1', + 'option2', + ], + ]; + + self::assertSame($expected, $output); + } + + /** + * Method checking for imports with placeholder values in the file name + * + * @test + */ + public function loadWithImportAndPlaceholderInFileName(): void + { + $output = (new YamlFileLoader())->load('EXT:core/Tests/Functional/Configuration/Loader/Fixtures/Placeholder/Berta.yaml'); + + $expected = [ + 'loadedWithPlaceholder' => 1, + 'settings' => [ + 'dynamicOption' => 'Foo', + ], + ]; + + self::assertSame($expected, $output); + } +} diff --git a/typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Env/Secondfile.yml b/typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Env/Secondfile.yml deleted file mode 100644 index 8f9b401d260f..000000000000 --- a/typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Env/Secondfile.yml +++ /dev/null @@ -1,5 +0,0 @@ -imports: - - { resource: Env_%env("foo")%.yml } - -options: - - optionBefore diff --git a/typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Placeholder/Berta.yml b/typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Placeholder/Berta.yml deleted file mode 100644 index b49c6ae58ce5..000000000000 --- a/typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Placeholder/Berta.yml +++ /dev/null @@ -1,5 +0,0 @@ -imports: - - { resource: '%settings.dynamicOption%.yml' } - -settings: - dynamicOption: 'Foo' diff --git a/typo3/sysext/core/Tests/Unit/Configuration/Loader/YamlFileLoaderTest.php b/typo3/sysext/core/Tests/Unit/Configuration/Loader/YamlFileLoaderTest.php index 3122e75dcdc0..f3c79f9fd3c1 100644 --- a/typo3/sysext/core/Tests/Unit/Configuration/Loader/YamlFileLoaderTest.php +++ b/typo3/sysext/core/Tests/Unit/Configuration/Loader/YamlFileLoaderTest.php @@ -22,287 +22,6 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase; class YamlFileLoaderTest extends UnitTestCase { - /** - * Generic method to check if the load method returns an array from a YAML file - * @test - */ - public function load(): void - { - $fileName = 'Berta.yml'; - $fileContents = ' -options: - - option1 - - option2 -betterthanbefore: 1 -'; - - $expected = [ - 'options' => [ - 'option1', - 'option2', - ], - 'betterthanbefore' => 1, - ]; - - // Accessible mock to $subject since getFileContents calls GeneralUtility methods - $subject = $this->getAccessibleMock(YamlFileLoader::class, ['getFileContents', 'getStreamlinedFileName']); - $subject->expects(self::once())->method('getStreamlinedFileName')->with($fileName)->willReturn($fileName); - $subject->expects(self::once())->method('getFileContents')->with($fileName)->willReturn($fileContents); - $output = $subject->load($fileName); - self::assertSame($expected, $output); - } - - /** - * Method checking for imports that they have been processed properly - * @test - */ - public function loadWithAnImport(): void - { - $fileName = 'Berta.yml'; - $fileContents = ' -imports: - - { resource: Secondfile.yml } - -options: - - option1 - - option2 -betterthanbefore: 1 -'; - - $importFileName = 'Secondfile.yml'; - $importFileContents = ' -options: - - optionBefore -betterthanbefore: 2 -'; - - $expected = [ - 'options' => [ - 'optionBefore', - 'option1', - 'option2', - ], - 'betterthanbefore' => 1, - ]; - - // Accessible mock to $subject since getFileContents calls GeneralUtility methods - $subject = $this->getAccessibleMock(YamlFileLoader::class, ['getFileContents', 'getStreamlinedFileName']); - $subject->expects(self::exactly(2))->method('getStreamlinedFileName') - ->withConsecutive([$fileName], [$importFileName, $fileName]) - ->willReturn($fileName, $importFileName); - $subject->expects(self::exactly(2))->method('getFileContents') - ->withConsecutive([$fileName], [$importFileName]) - ->willReturn($fileContents, $importFileContents); - $output = $subject->load($fileName); - self::assertSame($expected, $output); - } - - /** - * Method checking for mulitple imports that they have been loaded in the right order - * @test - */ - public function loadWithMultipleImports(): void - { - $fileName = 'Berta.yml'; - $fileContents = ' -imports: - - { resource: Secondfile.yml } - - { resource: Thirdfile.yml } - -options: - - option1 - - option2 -betterthanbefore: 1 -'; - - $importFileName = 'Secondfile.yml'; - $importFileContents = ' -options: - - optionBefore -betterthanbefore: 2 -'; - - $importFileName2 = 'Thirdfile.yml'; - $importFileContents2 = ' -options: - - optionAfterBefore -'; - - $expected = [ - 'options' => [ - 'optionBefore', - 'optionAfterBefore', - 'option1', - 'option2', - ], - 'betterthanbefore' => 1, - ]; - - // Accessible mock to $subject since getFileContents calls GeneralUtility methods - $subject = $this->getAccessibleMock(YamlFileLoader::class, ['getFileContents', 'getStreamlinedFileName']); - - $subject - ->expects(self::exactly(3)) - ->method('getStreamlinedFileName') - ->withConsecutive([$fileName, null], [$importFileName2, $fileName], [$importFileName, $fileName]) - ->willReturnOnConsecutiveCalls( - $fileName, - $importFileName2, - $importFileName - ); - - $subject - ->expects(self::exactly(3)) - ->method('getFileContents') - ->withConsecutive([$fileName], [$importFileName2], [$importFileName]) - ->willReturnOnConsecutiveCalls( - $fileContents, - $importFileContents2, - $importFileContents - ); - - $output = $subject->load($fileName); - self::assertSame($expected, $output); - } - - /** - * Method checking for imports that they have been processed properly - * @test - */ - public function loadWithImportAndRelativePaths(): void - { - $subject = new YamlFileLoader(); - $result = $subject->load(__DIR__ . '/Fixtures/Berta.yaml'); - self::assertSame([ - 'enable' => [ - 'frontend' => false, - 'json.api' => true, - 'backend' => true, - 'rest.api' => true, - ], - ], $result); - } - - /** - * Method checking for placeholders - * @test - */ - public function loadWithPlaceholders(): void - { - $fileName = 'Berta.yml'; - $fileContents = ' - -firstset: - myinitialversion: 13 -options: - - option1 - - option2 -betterthanbefore: \'%firstset.myinitialversion%\' -muchbetterthanbefore: \'some::%options.0%::option\' -'; - - $expected = [ - 'firstset' => [ - 'myinitialversion' => 13, - ], - 'options' => [ - 'option1', - 'option2', - ], - 'betterthanbefore' => 13, - 'muchbetterthanbefore' => 'some::option1::option', - ]; - - // Accessible mock to $subject since getFileContents calls GeneralUtility methods - $subject = $this->getAccessibleMock(YamlFileLoader::class, ['getFileContents', 'getStreamlinedFileName']); - $subject->expects(self::once())->method('getStreamlinedFileName')->with($fileName)->willReturn($fileName); - $subject->expects(self::once())->method('getFileContents')->with($fileName)->willReturn($fileContents); - $output = $subject->load($fileName); - self::assertSame($expected, $output); - } - - /** - * Method checking for nested placeholders - * @test - */ - public function loadWithNestedPlaceholders(): void - { - $fileName = 'Berta.yml'; - $fileContents = ' - -firstset: - myinitialversion: 13 -options: - - option1 - - option2 -betterthanbefore: \'%env(foo)%\' -'; - - $expected = [ - 'firstset' => [ - 'myinitialversion' => 13, - ], - 'options' => [ - 'option1', - 'option2', - ], - 'betterthanbefore' => 13, - ]; - - // Accessible mock to $subject since getFileContents calls GeneralUtility methods - $subject = $this->getAccessibleMock(YamlFileLoader::class, ['getFileContents', 'getStreamlinedFileName']); - $subject->expects(self::once())->method('getStreamlinedFileName')->with($fileName)->willReturn($fileName); - $subject->expects(self::once())->method('getFileContents')->with($fileName)->willReturn($fileContents); - - putenv('foo=%firstset.myinitialversion%'); - $output = $subject->load($fileName); - putenv('foo='); - self::assertSame($expected, $output); - } - - /** - * Method checking for imports with env vars that they have been processed properly - * @test - */ - public function loadWithImportAndEnvVars(): void - { - $loader = new YamlFileLoader(); - - putenv('foo=barbaz'); - $output = $loader->load(__DIR__ . '/Fixtures/Env/Berta.yml'); - putenv('foo='); - - $expected = [ - 'loadedWithEnvVars' => 1, - 'options' => [ - 'optionBefore', - 'option1', - 'option2', - ], - ]; - - self::assertSame($expected, $output); - } - - /** - * Method checking for imports with placeholder values in the file name - * @test - */ - public function loadWithImportAndPlaceholderInFileName(): void - { - $loader = new YamlFileLoader(); - $output = $loader->load(__DIR__ . '/Fixtures/Placeholder/Berta.yml'); - - $expected = [ - 'loadedWithPlaceholder' => 1, - 'settings' => [ - 'dynamicOption' => 'Foo', - ], - ]; - - self::assertSame($expected, $output); - } - public function loadWithEnvVarDataProvider(): array { return [ @@ -484,9 +203,8 @@ betterthanbefore: \'%env(mynonexistingenv)%\' * @test * @param mixed $placeholderValue * @param bool $expected - * @skip */ - public function containsPlaceholderTest($placeholderValue, bool $expected): void + public function containsPlaceholderTest(mixed $placeholderValue, bool $expected): void { $subject = $this->getAccessibleMock(YamlFileLoader::class, ['dummy']); $output = $subject->_call('containsPlaceholder', $placeholderValue); -- GitLab