‪TYPO3CMS  11.5
PhpErrorCodeViewHelperTest.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 
22 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
23 
24 class ‪PhpErrorCodeViewHelperTest extends FunctionalTestCase
25 {
29  protected ‪$initializeDatabase = false;
30 
34  public function ‪errorCodesDataProvider(): array
35  {
36  return [
37  [
38  'errorCode' => E_ERROR,
39  'expectedString' => 'E_ERROR',
40  ],
41  [
42  'errorCode' => E_ALL,
43  'expectedString' => 'E_ALL',
44  ],
45  [
46  'errorCode' => E_ERROR ^ E_WARNING ^ E_PARSE,
47  'expectedString' => 'E_ERROR | E_WARNING | E_PARSE',
48  ],
49  [
50  'errorCode' => E_RECOVERABLE_ERROR ^ E_USER_DEPRECATED,
51  'expectedString' => 'E_RECOVERABLE_ERROR | E_USER_DEPRECATED',
52  ],
53  ];
54  }
55 
60  public function ‪renderPhpCodesCorrectly(int $errorCode, string $expected): void
61  {
62  // Happy little hack for VH tests in install tool: ViewHelperResolver
63  // createViewHelperInstanceFromClassName() has an early check for
64  // FailSafeContainer to makeInstance() VH's directly, but in functional test
65  // context, we don't have a FailSafeContainer, but we also don't have VH entries
66  // of ext:install VH's in container. To circumvent this conflict, we for now
67  // instantiate our VH SuT and container->set() it to force service resolving.
68  $viewHelperInstance = new ‪PhpErrorCodeViewHelper();
69  $this->getContainer()->set(PhpErrorCodeViewHelper::class, $viewHelperInstance);
70 
71  $view = new ‪StandaloneView();
72  $view->getRenderingContext()->getViewHelperResolver()->addNamespace('install', 'TYPO3\\CMS\\Install\\ViewHelpers');
73  $view->setTemplateSource('<install:format.phpErrorCode phpErrorCode="' . $errorCode . '" />');
74  self::assertSame($expected, $view->render());
75  }
76 }
‪TYPO3\CMS\Install\ViewHelpers\Format\PhpErrorCodeViewHelper
Definition: PhpErrorCodeViewHelper.php:28
‪TYPO3\CMS\Install\Tests\Functional\ViewHelpers\Format\PhpErrorCodeViewHelperTest\$initializeDatabase
‪bool $initializeDatabase
Definition: PhpErrorCodeViewHelperTest.php:28
‪TYPO3\CMS\Install\Tests\Functional\ViewHelpers\Format
Definition: PhpErrorCodeViewHelperTest.php:18
‪TYPO3\CMS\Install\Tests\Functional\ViewHelpers\Format\PhpErrorCodeViewHelperTest\renderPhpCodesCorrectly
‪renderPhpCodesCorrectly(int $errorCode, string $expected)
Definition: PhpErrorCodeViewHelperTest.php:59
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:31
‪TYPO3\CMS\Install\Tests\Functional\ViewHelpers\Format\PhpErrorCodeViewHelperTest\errorCodesDataProvider
‪array errorCodesDataProvider()
Definition: PhpErrorCodeViewHelperTest.php:33
‪TYPO3\CMS\Install\Tests\Functional\ViewHelpers\Format\PhpErrorCodeViewHelperTest
Definition: PhpErrorCodeViewHelperTest.php:25