‪TYPO3CMS  11.5
MethodParameterTest.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 
30 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
31 
35 class ‪MethodParameterTest extends UnitTestCase
36 {
40  public function ‪classSchemaDetectsMandatoryParams(): void
41  {
42  self::assertFalse(
43  (new ‪ClassSchema(DummyClassWithAllTypesOfMethods::class))
44  ->‪getMethod('methodWithMandatoryParam')
45  ->getParameter('param')
46  ->isOptional()
47  );
48  }
49 
54  {
55  self::assertSame(
56  'foo',
57  (new ‪ClassSchema(DummyClassWithAllTypesOfMethods::class))
58  ->‪getMethod('methodWithDefaultValueParam')
59  ->getParameter('param')
60  ->getDefaultValue()
61  );
62  }
63 
68  {
69  self::assertSame(
70  'string',
71  (new ‪ClassSchema(DummyClassWithAllTypesOfMethods::class))
72  ->‪getMethod('methodWithTypeHintedParam')
73  ->getParameter('param')
74  ->getType()
75  );
76  }
77 
82  {
83  $classSchemaMethod = (new ‪ClassSchema(DummyControllerWithIgnoreValidationDoctrineAnnotation::class))
84  ->‪getMethod('someAction');
85  self::assertTrue($classSchemaMethod->getParameter('foo')->ignoreValidation());
86  self::assertTrue($classSchemaMethod->getParameter('bar')->ignoreValidation());
87 
88  $this->expectException(NoSuchMethodParameterException::class);
89  $classSchemaMethod->getParameter('baz')->ignoreValidation();
90  }
91 
96  {
97  $classSchema = new ‪ClassSchema(DummyClassWithConstructorAndConstructorArgumentsWithDependencies::class);
98  self::assertTrue($classSchema->hasConstructor());
99 
100  $method = $classSchema->getMethod('__construct');
101  self::assertSame(DummyClassWithGettersAndSetters::class, $method->getParameter('foo')->getDependency());
102  }
103 
108  {
109  $this->resetSingletonInstances = true;
110  $classSchema = new ‪ClassSchema(DummyController::class);
111  self::assertSame(
112  [
113  [
114  'name' => 'StringLength',
115  'options' => [
116  'minimum' => 1,
117  'maximum' => 10,
118  ],
119  'className' => StringLengthValidator::class,
120  ],
121  [
122  'name' => 'NotEmpty',
123  'options' => [],
124  'className' => NotEmptyValidator::class,
125  ],
126  [
127  'name' => 'TYPO3.CMS.Extbase:NotEmpty',
128  'options' => [],
129  'className' => NotEmptyValidator::class,
130  ],
131  [
132  'name' => 'TYPO3.CMS.Extbase.Tests.Unit.Reflection.Fixture:DummyValidator',
133  'options' => [],
134  'className' => DummyValidator::class,
135  ],
136  [
137  'name' => '\TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator',
138  'options' => [],
139  'className' => NotEmptyValidator::class,
140  ],
141  [
142  'name' => NotEmptyValidator::class,
143  'options' => [],
144  'className' => NotEmptyValidator::class,
145  ],
146  ],
147  $classSchema->getMethod('methodWithValidateAnnotationsAction')->getParameter('fooParam')->getValidators()
148  );
149  }
150 }
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\MethodParameterTest\classSchemaDetectsParamTypeFromTypeHint
‪classSchemaDetectsParamTypeFromTypeHint()
Definition: MethodParameterTest.php:67
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\getMethod
‪Method getMethod(string $methodName)
Definition: ClassSchema.php:579
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Exception\NoSuchMethodParameterException
Definition: NoSuchMethodParameterException.php:24
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyController
Definition: DummyController.php:28
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyClassWithConstructorAndConstructorArgumentsWithDependencies
Definition: DummyClassWithConstructorAndConstructorArgumentsWithDependencies.php:24
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\MethodParameterTest\classSchemaDetectsIgnoreValidationAnnotation
‪classSchemaDetectsIgnoreValidationAnnotation()
Definition: MethodParameterTest.php:81
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyClassWithGettersAndSetters
Definition: DummyClassWithGettersAndSetters.php:24
‪TYPO3\CMS\Extbase\Validation\Validator\StringLengthValidator
Definition: StringLengthValidator.php:24
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\Validation\Validator\DummyValidator
Definition: DummyValidator.php:27
‪TYPO3\CMS\Extbase\Reflection\ClassSchema
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyControllerWithIgnoreValidationDoctrineAnnotation
Definition: DummyControllerWithIgnoreValidationDoctrineAnnotation.php:27
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\MethodParameterTest\classSchemaDetectsValidateAnnotationsOfControllerActions
‪classSchemaDetectsValidateAnnotationsOfControllerActions()
Definition: MethodParameterTest.php:107
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\MethodParameterTest\classSchemaDetectsMandatoryParams
‪classSchemaDetectsMandatoryParams()
Definition: MethodParameterTest.php:40
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator
Definition: NotEmptyValidator.php:22
‪TYPO3\CMS\Extbase\Reflection\ClassSchema
Definition: ClassSchema.php:54
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\MethodParameterTest\classSchemaDetectsDefaultValueParams
‪classSchemaDetectsDefaultValueParams()
Definition: MethodParameterTest.php:53
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\MethodParameterTest
Definition: MethodParameterTest.php:36
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema
Definition: MethodParameterTest.php:18
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyClassWithAllTypesOfMethods
Definition: DummyClassWithAllTypesOfMethods.php:24
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\MethodParameterTest\classSchemaDetectsConstructorArgumentsWithDependencies
‪classSchemaDetectsConstructorArgumentsWithDependencies()
Definition: MethodParameterTest.php:95