‪TYPO3CMS  ‪main
YamlSourceTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
26 final class ‪YamlSourceTest extends UnitTestCase
27 {
28  protected bool ‪$resetSingletonInstances = true;
29 
30  #[Test]
32  {
33  $this->expectException(ParseErrorException::class);
34  $this->expectExceptionCode(1480195405);
35 
36  $mockYamlSource = $this->getAccessibleMock(YamlSource::class, null, [], '', false);
37 
38  $input = [
39  'EXT:form/Resources/Forms/_example.yaml',
40  ];
41 
42  $mockYamlSource->_call('load', $input);
43  }
44 
45  #[Test]
47  {
48  $this->expectException(ParseErrorException::class);
49  $this->expectExceptionCode(1480195405);
50 
51  $mockYamlSource = $this->getAccessibleMock(YamlSource::class, null, [], '', false);
52 
53  $input = [
54  'EXT:form/Tests/Unit/Mvc/Configuration/Fixtures/Invalid.yaml',
55  ];
56 
57  $mockYamlSource->_call('load', $input);
58  }
59 
60  #[Test]
61  public function ‪getHeaderFromFileReturnsHeaderPart(): void
62  {
63  $mockYamlSource = $this->getAccessibleMock(YamlSource::class, null, [], '', false);
64 
65  $input = GeneralUtility::getFileAbsFileName('EXT:form/Tests/Unit/Mvc/Configuration/Fixtures/Header.yaml');
66  $expected =
67 '# Header 1
68 # Header 2
69 ';
70 
71  self::assertSame($expected, $mockYamlSource->_call('getHeaderFromFile', $input));
72  }
73 
74  #[Test]
76  {
77  $mockYamlSource = $this->getAccessibleMock(YamlSource::class, null, [], '', false);
78 
79  $input = [
80  'EXT:form/Tests/Unit/Mvc/Configuration/Fixtures/OverruleNonArrayValuesOverArrayValues1.yaml',
81  'EXT:form/Tests/Unit/Mvc/Configuration/Fixtures/OverruleNonArrayValuesOverArrayValues2.yaml',
82  ];
83 
84  $expected = [
85  'Form' => [
86  'klaus01' => null,
87  'key03' => 'value2',
88  ],
89  ];
90 
91  self::assertSame($expected, $mockYamlSource->_call('load', $input));
92  }
93 
94  #[Test]
96  {
97  $mockYamlSource = $this->getAccessibleMock(YamlSource::class, null, [], '', false);
98 
99  $input = [
100  'EXT:form/Tests/Unit/Mvc/Configuration/Fixtures/ConfigurationWithVendorNamespacePrefix1.yaml',
101  'EXT:form/Tests/Unit/Mvc/Configuration/Fixtures/ConfigurationWithoutVendorNamespacePrefix1.yaml',
102  'EXT:form/Tests/Unit/Mvc/Configuration/Fixtures/ConfigurationWithVendorNamespacePrefix2.yaml',
103  ];
104 
105  $expected = [
106  'klaus01' => [
107  'key01' => 'key01_value',
108  'key02' => 'key02_value_override',
109  'key06' => 'key06_value_override',
110  'key07' => 'key07_value_override',
111  ],
112  'key03' => 'key03_value',
113  'key04' => 'key04_value',
114  'key05' => 'key05_value_override',
115  'key08' => 'key08_value_override',
116  ];
117 
118  self::assertSame($expected, $mockYamlSource->_call('load', $input));
119  }
120 }
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration
Definition: ConfigurationManagerTest.php:18
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\YamlSourceTest\loadOverruleNonArrayValuesOverArrayValues
‪loadOverruleNonArrayValuesOverArrayValues()
Definition: YamlSourceTest.php:75
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\YamlSourceTest\loadThrowsExceptionIfFileToLoadIsNotValidYamlUseSymfonyParser
‪loadThrowsExceptionIfFileToLoadIsNotValidYamlUseSymfonyParser()
Definition: YamlSourceTest.php:46
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\YamlSourceTest
Definition: YamlSourceTest.php:27
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\YamlSourceTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: YamlSourceTest.php:28
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\YamlSourceTest\loadRemovesVendorNamespacePrefixFromConfiguration
‪loadRemovesVendorNamespacePrefixFromConfiguration()
Definition: YamlSourceTest.php:95
‪TYPO3\CMS\Form\Mvc\Configuration\YamlSource
Definition: YamlSource.php:44
‪TYPO3\CMS\Form\Mvc\Configuration\Exception\ParseErrorException
Definition: ParseErrorException.php:24
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\YamlSourceTest\getHeaderFromFileReturnsHeaderPart
‪getHeaderFromFileReturnsHeaderPart()
Definition: YamlSourceTest.php:61
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\YamlSourceTest\loadThrowsExceptionIfFileToLoadNotExists
‪loadThrowsExceptionIfFileToLoadNotExists()
Definition: YamlSourceTest.php:31