‪TYPO3CMS  9.5
ClassSchemaTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪ClassSchemaTest extends UnitTestCase
28 {
32  protected ‪$resetSingletonInstances = true;
33 
35  {
36  $classSchema = new ‪ClassSchema(Fixture\DummyClassWithInjectProperty::class);
37  static::assertTrue($classSchema->hasInjectProperties());
38 
39  $propertyDefinition = $classSchema->getProperty('propertyWithInjectAnnotation');
40  static::assertTrue($propertyDefinition['annotations']['inject']);
41 
42  $injectProperties = $classSchema->getInjectProperties();
43  static::assertArrayHasKey('propertyWithInjectAnnotation', $injectProperties);
44  }
45 
47  {
48  $classSchema = new ‪ClassSchema(Fixture\DummyClassWithLazyProperty::class);
49  static::assertTrue($classSchema->getProperty('propertyWithLazyAnnotation')['annotations']['lazy']);
50  }
51 
53  {
54  $classSchema = new ‪ClassSchema(Fixture\DummyClassWithAllTypesOfProperties::class);
55 
56  $propertyDefinition = $classSchema->getProperty('propertyWithCascadeAnnotation');
57  static::assertSame('remove', $propertyDefinition['annotations']['cascade']);
58  }
59 
61  {
62  $classSchema = new ‪ClassSchema(Fixture\DummyClassWithAllTypesOfProperties::class);
63 
64  $propertyDefinition = $classSchema->getProperty('propertyWithCascadeAnnotationWithoutVarAnnotation');
65  static::assertNull($propertyDefinition['annotations']['cascade']);
66  }
67 
69  {
70  $classSchema = new ‪ClassSchema(Fixture\DummyControllerWithIgnorevalidationAnnotation::class);
71  static::assertTrue(isset($classSchema->getMethod('someAction')['tags']['ignorevalidation']));
72  }
73 
78  {
79  $classSchema = new ‪ClassSchema(Fixture\DummyModelWithValidateAnnotation::class);
80 
81  static::assertSame(
82  [
83  [
84  'name' => 'StringLength',
85  'options' => [
86  'minimum' => '1',
87  'maximum' => '10',
88  ],
89  'className' => StringLengthValidator::class
90  ],
91  [
92  'name' => 'NotEmpty',
93  'options' => [],
94  'className' => NotEmptyValidator::class
95  ],
96  [
97  'name' => 'TYPO3.CMS.Extbase:NotEmpty',
98  'options' => [],
99  'className' => NotEmptyValidator::class
100  ],
101  [
102  'name' => 'TYPO3.CMS.Extbase.Tests.UnitDeprecated.Reflection.Fixture:DummyValidator',
103  'options' => [],
104  'className' => Fixture\Validation\Validator\DummyValidator::class
105  ],
106  [
107  'name' => '\TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator',
108  'options' => [],
109  'className' => NotEmptyValidator::class
110  ],
111  [
112  'name' => NotEmptyValidator::class,
113  'options' => [],
114  'className' => NotEmptyValidator::class
115  ]
116  ],
117  $classSchema->getProperty('propertyWithValidateAnnotations')['validators']
118  );
119  }
120 
125  {
126  $classSchema = new ClassSchema(Fixture\DummyControllerWithValidateAnnotations::class);
127 
128  static::assertSame(
129  [
130  [
131  'name' => 'StringLength',
132  'options' => [
133  'minimum' => '1',
134  'maximum' => '10',
135  ],
136  'className' => StringLengthValidator::class
137  ],
138  [
139  'name' => 'NotEmpty',
140  'options' => [],
141  'className' => NotEmptyValidator::class
142  ],
143  [
144  'name' => 'TYPO3.CMS.Extbase:NotEmpty',
145  'options' => [],
146  'className' => NotEmptyValidator::class
147  ],
148  [
149  'name' => 'TYPO3.CMS.Extbase.Tests.UnitDeprecated.Reflection.Fixture:DummyValidator',
150  'options' => [],
151  'className' => Fixture\Validation\Validator\DummyValidator::class
152  ],
153  [
154  'name' => '\TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator',
155  'options' => [],
156  'className' => NotEmptyValidator::class
157  ],
158  [
159  'name' => NotEmptyValidator::class,
160  'options' => [],
161  'className' => NotEmptyValidator::class
162  ]
163  ],
164  $classSchema->getMethod('methodWithValidateAnnotationsAction')['params']['fooParam']['validators']
165  );
166  }
167 
172  {
173  $this->expectException(InvalidTypeHintException::class);
174  $this->expectExceptionMessage('Missing type information for parameter "$fooParam" in TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\Fixture\DummyControllerWithValidateAnnotationWithoutParamTypeHint->methodWithValidateAnnotationsAction(): Either use an @param annotation or use a type hint.');
175  $this->expectExceptionCode(1515075192);
176 
177  new ClassSchema(Fixture\DummyControllerWithValidateAnnotationWithoutParamTypeHint::class);
178  }
179 
184  {
185  $this->expectException(InvalidValidationConfigurationException::class);
186  $this->expectExceptionMessage('Invalid validate annotation in TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\Fixture\DummyControllerWithValidateAnnotationWithoutParam->methodWithValidateAnnotationsAction(): The following validators have been defined for missing param "$fooParam": NotEmpty, StringLength');
187  $this->expectExceptionCode(1515073585);
188 
189  new ClassSchema(Fixture\DummyControllerWithValidateAnnotationWithoutParam::class);
190  }
191 }
‪TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationConfigurationException
Definition: InvalidValidationConfigurationException.php:21
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ClassSchemaTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: ClassSchemaTest.php:31
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ClassSchemaTest\testClassSchemaDetectsCascadePropertyOnlyWithVarAnnotation
‪testClassSchemaDetectsCascadePropertyOnlyWithVarAnnotation()
Definition: ClassSchemaTest.php:59
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ClassSchemaTest\classSchemaDetectsValidateAnnotationsOfControllerActions
‪classSchemaDetectsValidateAnnotationsOfControllerActions()
Definition: ClassSchemaTest.php:123
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ClassSchemaTest\testClassSchemaDetectsIgnoreValidationAnnotation
‪testClassSchemaDetectsIgnoreValidationAnnotation()
Definition: ClassSchemaTest.php:67
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ClassSchemaTest
Definition: ClassSchemaTest.php:28
‪TYPO3\CMS\Extbase\Validation\Validator\StringLengthValidator
Definition: StringLengthValidator.php:21
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ClassSchemaTest\testClassSchemaDetectsInjectProperties
‪testClassSchemaDetectsInjectProperties()
Definition: ClassSchemaTest.php:33
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ClassSchemaTest\testClassSchemaDetectsCascadeProperty
‪testClassSchemaDetectsCascadeProperty()
Definition: ClassSchemaTest.php:51
‪TYPO3\CMS\Extbase\Validation\Exception\InvalidTypeHintException
Definition: InvalidTypeHintException.php:21
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator
Definition: NotEmptyValidator.php:21
‪TYPO3\CMS\Extbase\Reflection\ClassSchema
Definition: ClassSchema.php:41
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ClassSchemaTest\classSchemaDetectsValidateAnnotationsModelProperties
‪classSchemaDetectsValidateAnnotationsModelProperties()
Definition: ClassSchemaTest.php:76
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection
Definition: ClassSchemaTest.php:2
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ClassSchemaTest\testClassSchemaDetectsLazyProperties
‪testClassSchemaDetectsLazyProperties()
Definition: ClassSchemaTest.php:45
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ClassSchemaTest\classSchemaGenerationThrowsExceptionWithValidateAnnotationsForMissingParam
‪classSchemaGenerationThrowsExceptionWithValidateAnnotationsForMissingParam()
Definition: ClassSchemaTest.php:182
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ClassSchemaTest\classSchemaGenerationThrowsExceptionWithValidateAnnotationsForParamWithoutTypeHint
‪classSchemaGenerationThrowsExceptionWithValidateAnnotationsForParamWithoutTypeHint()
Definition: ClassSchemaTest.php:170