‪TYPO3CMS  10.4
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 
53  public function ‪classSchemaDetectsNullableParams(): void
54  {
55  self::markTestSkipped('Skip until MethodParameter::allowsNull() is needed and properly implemented');
56 
57  self::assertTrue(
58  (new ‪ClassSchema(DummyClassWithAllTypesOfMethods::class))
59  ->‪getMethod('methodWithNullableParam')
60  ->getParameter('param')
61  ->allowsNull()
62  );
63  }
64 
69  {
70  self::assertSame(
71  'foo',
72  (new ‪ClassSchema(DummyClassWithAllTypesOfMethods::class))
73  ->‪getMethod('methodWithDefaultValueParam')
74  ->getParameter('param')
75  ->getDefaultValue()
76  );
77  }
78 
83  {
84  self::assertSame(
85  'string',
86  (new ‪ClassSchema(DummyClassWithAllTypesOfMethods::class))
87  ->‪getMethod('methodWithTypeHintedParam')
88  ->getParameter('param')
89  ->getType()
90  );
91  }
92 
97  {
98  $classSchemaMethod = (new ‪ClassSchema(DummyControllerWithIgnoreValidationDoctrineAnnotation::class))
99  ->‪getMethod('someAction');
100  self::assertTrue($classSchemaMethod->getParameter('foo')->ignoreValidation());
101  self::assertTrue($classSchemaMethod->getParameter('bar')->ignoreValidation());
102 
103  static::expectException(NoSuchMethodParameterException::class);
104  $classSchemaMethod->getParameter('baz')->ignoreValidation();
105  }
106 
111  {
112  $classSchema = new ‪ClassSchema(DummyClassWithConstructorAndConstructorArgumentsWithDependencies::class);
113  self::assertTrue($classSchema->hasConstructor());
114 
115  $method = $classSchema->getMethod('__construct');
116  self::assertSame(DummyClassWithGettersAndSetters::class, $method->getParameter('foo')->getDependency());
117  }
118 
123  {
124  $this->resetSingletonInstances = true;
125  $classSchema = new ‪ClassSchema(DummyController::class);
126  self::assertSame(
127  [
128  [
129  'name' => 'StringLength',
130  'options' => [
131  'minimum' => 1,
132  'maximum' => 10,
133  ],
134  'className' => StringLengthValidator::class
135  ],
136  [
137  'name' => 'NotEmpty',
138  'options' => [],
139  'className' => NotEmptyValidator::class
140  ],
141  [
142  'name' => 'TYPO3.CMS.Extbase:NotEmpty',
143  'options' => [],
144  'className' => NotEmptyValidator::class
145  ],
146  [
147  'name' => 'TYPO3.CMS.Extbase.Tests.Unit.Reflection.Fixture:DummyValidator',
148  'options' => [],
149  'className' => DummyValidator::class
150  ],
151  [
152  'name' => '\TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator',
153  'options' => [],
154  'className' => NotEmptyValidator::class
155  ],
156  [
157  'name' => NotEmptyValidator::class,
158  'options' => [],
159  'className' => NotEmptyValidator::class
160  ]
161  ],
162  $classSchema->getMethod('methodWithValidateAnnotationsAction')->getParameter('fooParam')->getValidators()
163  );
164  }
165 }
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\MethodParameterTest\classSchemaDetectsParamTypeFromTypeHint
‪classSchemaDetectsParamTypeFromTypeHint()
Definition: MethodParameterTest.php:82
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\getMethod
‪Method getMethod(string $methodName)
Definition: ClassSchema.php:541
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Exception\NoSuchMethodParameterException
Definition: NoSuchMethodParameterException.php:24
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyController
Definition: DummyController.php:27
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyClassWithConstructorAndConstructorArgumentsWithDependencies
Definition: DummyClassWithConstructorAndConstructorArgumentsWithDependencies.php:22
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\MethodParameterTest\classSchemaDetectsIgnoreValidationAnnotation
‪classSchemaDetectsIgnoreValidationAnnotation()
Definition: MethodParameterTest.php:96
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyClassWithGettersAndSetters
Definition: DummyClassWithGettersAndSetters.php:22
‪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:26
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\MethodParameterTest\classSchemaDetectsValidateAnnotationsOfControllerActions
‪classSchemaDetectsValidateAnnotationsOfControllerActions()
Definition: MethodParameterTest.php:122
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\MethodParameterTest\classSchemaDetectsMandatoryParams
‪classSchemaDetectsMandatoryParams()
Definition: MethodParameterTest.php:40
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\MethodParameterTest\classSchemaDetectsNullableParams
‪classSchemaDetectsNullableParams()
Definition: MethodParameterTest.php:53
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator
Definition: NotEmptyValidator.php:22
‪TYPO3\CMS\Extbase\Reflection\ClassSchema
Definition: ClassSchema.php:55
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\MethodParameterTest\classSchemaDetectsDefaultValueParams
‪classSchemaDetectsDefaultValueParams()
Definition: MethodParameterTest.php:68
‪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:22
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\MethodParameterTest\classSchemaDetectsConstructorArgumentsWithDependencies
‪classSchemaDetectsConstructorArgumentsWithDependencies()
Definition: MethodParameterTest.php:110