‪TYPO3CMS  11.5
PropertyTest.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 
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
33 class ‪PropertyTest extends UnitTestCase
34 {
39  {
40  $classSchema = new ‪ClassSchema(DummyClassWithLazyDoctrineAnnotation::class);
41  self::assertTrue($classSchema->getProperty('propertyWithLazyAnnotation')->isLazy());
42  }
43 
48  {
49  $classSchema = new ‪ClassSchema(DummyClassWithAllTypesOfProperties::class);
50 
51  $property = $classSchema->getProperty('publicProperty');
52  self::assertTrue($property->isPublic());
53  self::assertFalse($property->isProtected());
54  self::assertFalse($property->isPrivate());
55 
56  $property = $classSchema->getProperty('protectedProperty');
57  self::assertFalse($property->isPublic());
58  self::assertTrue($property->isProtected());
59  self::assertFalse($property->isPrivate());
60 
61  $property = $classSchema->getProperty('privateProperty');
62  self::assertFalse($property->isPublic());
63  self::assertFalse($property->isProtected());
64  self::assertTrue($property->isPrivate());
65  }
66 
71  {
72  $property = (new ‪ClassSchema(DummyClassWithAllTypesOfProperties::class))
73  ->‪getProperty('propertyWithTransientAnnotation');
74 
75  self::assertTrue($property->isTransient());
76  }
77 
81  public function ‪classSchemaDetectsCascadeProperty(): void
82  {
83  $property = (new ‪ClassSchema(DummyClassWithAllTypesOfProperties::class))
84  ->‪getProperty('propertyWithCascadeAnnotation');
85 
86  self::assertSame('remove', $property->getCascadeValue());
87  }
88 
93  {
94  $property = (new ‪ClassSchema(DummyClassWithAllTypesOfProperties::class))
95  ->‪getProperty('propertyWithCascadeAnnotationWithoutVarAnnotation');
96 
97  self::assertNull($property->getCascadeValue());
98  }
99 
104  {
105  $property = (new ‪ClassSchema(DummyClassWithAllTypesOfProperties::class))
106  ->‪getProperty('propertyWithObjectStorageAnnotation');
107 
108  self::assertSame(ObjectStorage::class, $property->getType());
109  self::assertSame(DummyClassWithAllTypesOfProperties::class, $property->getElementType());
110  }
111 
116  {
117  $property = (new ‪ClassSchema(DummyClassWithAllTypesOfProperties::class))
118  ->‪getProperty('propertyWithObjectStorageAnnotationWithoutFQCN');
119 
120  self::assertSame(ObjectStorage::class, $property->getType());
121  self::assertSame(DummyClassWithAllTypesOfProperties::class, $property->getElementType());
122  }
123 
128  {
129  $this->resetSingletonInstances = true;
130  $property = (new ‪ClassSchema(DummyModel::class))
131  ->‪getProperty('propertyWithValidateAnnotations');
132 
133  self::assertSame(
134  [
135  [
136  'name' => 'StringLength',
137  'options' => [
138  'minimum' => 1,
139  'maximum' => 10,
140  ],
141  'className' => StringLengthValidator::class,
142  ],
143  [
144  'name' => 'NotEmpty',
145  'options' => [],
146  'className' => NotEmptyValidator::class,
147  ],
148  [
149  'name' => 'TYPO3.CMS.Extbase:NotEmpty',
150  'options' => [],
151  'className' => NotEmptyValidator::class,
152  ],
153  [
154  'name' => 'TYPO3.CMS.Extbase.Tests.Unit.Reflection.Fixture:DummyValidator',
155  'options' => [],
156  'className' => DummyValidator::class,
157  ],
158  [
159  'name' => '\TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator',
160  'options' => [],
161  'className' => NotEmptyValidator::class,
162  ],
163  [
164  'name' => NotEmptyValidator::class,
165  'options' => [],
166  'className' => NotEmptyValidator::class,
167  ],
168  ],
169  $property->getValidators()
170  );
171  }
172 
177  {
178  $property = (new ‪ClassSchema(DummyClassWithAllTypesOfProperties::class))
179  ->‪getProperty('stringTypedProperty');
180 
181  self::assertSame('string', $property->getType());
182  }
183 
188  {
189  $property = (new ‪ClassSchema(DummyClassWithAllTypesOfProperties::class))
190  ->‪getProperty('nullableStringTypedProperty');
191 
192  self::assertSame('string', $property->getType());
193  }
194 }
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\PropertyTest\classSchemaDetectsTypeAndElementTypeWithoutFQCN
‪classSchemaDetectsTypeAndElementTypeWithoutFQCN()
Definition: PropertyTest.php:115
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyClassWithLazyDoctrineAnnotation
Definition: DummyClassWithLazyDoctrineAnnotation.php:26
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\PropertyTest\classSchemaDetectsCascadeProperty
‪classSchemaDetectsCascadeProperty()
Definition: PropertyTest.php:81
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyClassWithAllTypesOfProperties
Definition: DummyClassWithAllTypesOfProperties.php:29
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\PropertyTest\classSchemaDetectsPropertyVisibility
‪classSchemaDetectsPropertyVisibility()
Definition: PropertyTest.php:47
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\PropertyTest\classSchemaDetectsPropertiesWithLazyAnnotation
‪classSchemaDetectsPropertiesWithLazyAnnotation()
Definition: PropertyTest.php:38
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\PropertyTest\classSchemaDetectsTransientProperty
‪classSchemaDetectsTransientProperty()
Definition: PropertyTest.php:70
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\PropertyTest\classSchemaDetectsValidateAnnotationsModelProperties
‪classSchemaDetectsValidateAnnotationsModelProperties()
Definition: PropertyTest.php:127
‪TYPO3\CMS\Extbase\Validation\Validator\StringLengthValidator
Definition: StringLengthValidator.php:24
‪TYPO3\CMS\Extbase\Persistence\ObjectStorage
Definition: ObjectStorage.php:32
‪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\DummyModel
Definition: DummyModel.php:27
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\PropertyTest\classSchemaDetectsTypeFromPropertyWithStringTypeHint
‪classSchemaDetectsTypeFromPropertyWithStringTypeHint()
Definition: PropertyTest.php:176
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\PropertyTest\classSchemaDetectsTypeFromPropertyWithNullableStringTypeHint
‪classSchemaDetectsTypeFromPropertyWithNullableStringTypeHint()
Definition: PropertyTest.php:187
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\PropertyTest\classSchemaDetectsTypeAndElementType
‪classSchemaDetectsTypeAndElementType()
Definition: PropertyTest.php:103
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\PropertyTest
Definition: PropertyTest.php:34
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\getProperty
‪Property getProperty(string $propertyName)
Definition: ClassSchema.php:510
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator
Definition: NotEmptyValidator.php:22
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\PropertyTest\classSchemaDetectsCascadePropertyOnlyWithVarAnnotation
‪classSchemaDetectsCascadePropertyOnlyWithVarAnnotation()
Definition: PropertyTest.php:92
‪TYPO3\CMS\Extbase\Reflection\ClassSchema
Definition: ClassSchema.php:54
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema
Definition: MethodParameterTest.php:18