‪TYPO3CMS  10.4
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 
70  public function ‪classSchemaDetectsInjectProperty(): void
71  {
72  $property = (new ‪ClassSchema(DummyClassWithAllTypesOfProperties::class))
73  ->‪getProperty('propertyWithInjectAnnotation');
74 
75  self::assertTrue($property->isInjectProperty());
76  }
77 
82  {
83  $property = (new ‪ClassSchema(DummyClassWithAllTypesOfProperties::class))
84  ->‪getProperty('propertyWithTransientAnnotation');
85 
86  self::assertTrue($property->isTransient());
87  }
88 
92  public function ‪classSchemaDetectsCascadeProperty(): void
93  {
94  $property = (new ‪ClassSchema(DummyClassWithAllTypesOfProperties::class))
95  ->‪getProperty('propertyWithCascadeAnnotation');
96 
97  self::assertSame('remove', $property->getCascadeValue());
98  }
99 
104  {
105  $property = (new ‪ClassSchema(DummyClassWithAllTypesOfProperties::class))
106  ->‪getProperty('propertyWithCascadeAnnotationWithoutVarAnnotation');
107 
108  self::assertNull($property->getCascadeValue());
109  }
110 
115  {
116  $property = (new ‪ClassSchema(DummyClassWithAllTypesOfProperties::class))
117  ->‪getProperty('propertyWithObjectStorageAnnotation');
118 
119  self::assertSame(ObjectStorage::class, $property->getType());
120  self::assertSame(DummyClassWithAllTypesOfProperties::class, $property->getElementType());
121  }
122 
127  {
128  $property = (new ‪ClassSchema(DummyClassWithAllTypesOfProperties::class))
129  ->‪getProperty('propertyWithObjectStorageAnnotationWithoutFQCN');
130 
131  self::assertSame(ObjectStorage::class, $property->getType());
132  self::assertSame(DummyClassWithAllTypesOfProperties::class, $property->getElementType());
133  }
134 
139  {
140  $this->resetSingletonInstances = true;
141  $property = (new ‪ClassSchema(DummyModel::class))
142  ->‪getProperty('propertyWithValidateAnnotations');
143 
144  self::assertSame(
145  [
146  [
147  'name' => 'StringLength',
148  'options' => [
149  'minimum' => 1,
150  'maximum' => 10,
151  ],
152  'className' => StringLengthValidator::class
153  ],
154  [
155  'name' => 'NotEmpty',
156  'options' => [],
157  'className' => NotEmptyValidator::class
158  ],
159  [
160  'name' => 'TYPO3.CMS.Extbase:NotEmpty',
161  'options' => [],
162  'className' => NotEmptyValidator::class
163  ],
164  [
165  'name' => 'TYPO3.CMS.Extbase.Tests.Unit.Reflection.Fixture:DummyValidator',
166  'options' => [],
167  'className' => DummyValidator::class
168  ],
169  [
170  'name' => '\TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator',
171  'options' => [],
172  'className' => NotEmptyValidator::class
173  ],
174  [
175  'name' => NotEmptyValidator::class,
176  'options' => [],
177  'className' => NotEmptyValidator::class
178  ]
179  ],
180  $property->getValidators()
181  );
182  }
183 }
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\PropertyTest\classSchemaDetectsTypeAndElementTypeWithoutFQCN
‪classSchemaDetectsTypeAndElementTypeWithoutFQCN()
Definition: PropertyTest.php:126
‪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:92
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyClassWithAllTypesOfProperties
Definition: DummyClassWithAllTypesOfProperties.php:27
‪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:81
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\PropertyTest\classSchemaDetectsValidateAnnotationsModelProperties
‪classSchemaDetectsValidateAnnotationsModelProperties()
Definition: PropertyTest.php:138
‪TYPO3\CMS\Extbase\Validation\Validator\StringLengthValidator
Definition: StringLengthValidator.php:24
‪TYPO3\CMS\Extbase\Persistence\ObjectStorage
Definition: ObjectStorage.php:28
‪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\classSchemaDetectsTypeAndElementType
‪classSchemaDetectsTypeAndElementType()
Definition: PropertyTest.php:114
‪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:486
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator
Definition: NotEmptyValidator.php:22
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\PropertyTest\classSchemaDetectsCascadePropertyOnlyWithVarAnnotation
‪classSchemaDetectsCascadePropertyOnlyWithVarAnnotation()
Definition: PropertyTest.php:103
‪TYPO3\CMS\Extbase\Reflection\ClassSchema
Definition: ClassSchema.php:55
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema\PropertyTest\classSchemaDetectsInjectProperty
‪classSchemaDetectsInjectProperty()
Definition: PropertyTest.php:70
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ClassSchema
Definition: MethodParameterTest.php:18