24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
36 $this->resetSingletonInstances =
true;
37 $service = GeneralUtility::makeInstance(\
TYPO3\CMS\
Extbase\Reflection\ReflectionService::class);
38 $classSchema = $service->getClassSchema(Fixture\DummyModel::class);
39 $this->assertTrue($classSchema->isAggregateRoot());
47 $classSchema =
new ClassSchema(Fixture\DummyClassWithConstructorAndConstructorArguments::class);
48 static::assertTrue($classSchema->hasConstructor());
56 $classSchema =
new ClassSchema(Fixture\DummyClassWithConstructorAndConstructorArguments::class);
57 static::assertTrue($classSchema->hasConstructor());
59 $constructorArguments = $classSchema->getConstructorArguments();
60 static::assertArrayHasKey(
'foo', $constructorArguments);
61 static::assertArrayHasKey(
'bar', $constructorArguments);
63 $classSchema =
new ClassSchema(Fixture\DummyClassWithConstructorAndWithoutConstructorArguments::class);
64 static::assertTrue($classSchema->hasConstructor());
65 static::assertSame([], $classSchema->getConstructorArguments());
67 $classSchema =
new ClassSchema(Fixture\DummyClassWithoutConstructor::class);
68 static::assertFalse($classSchema->hasConstructor());
69 static::assertSame([], $classSchema->getConstructorArguments());
77 $classSchema =
new ClassSchema(Fixture\DummyClassWithConstructorAndConstructorArgumentsWithDependencies::class);
78 static::assertTrue($classSchema->hasConstructor());
80 $methodDefinition = $classSchema->getMethod(
'__construct');
81 static::assertArrayHasKey(
'foo', $methodDefinition[
'params']);
82 static::assertSame(Fixture\DummyClassWithGettersAndSetters::class, $methodDefinition[
'params'][
'foo'][
'dependency']);
95 'publicStaticProperty',
96 'protectedStaticProperty',
97 'privateStaticProperty',
98 'propertyWithIgnoredTags',
99 'propertyWithInjectAnnotation',
100 'propertyWithTransientAnnotation',
101 'propertyWithCascadeAnnotation',
102 'propertyWithCascadeAnnotationWithoutVarAnnotation',
103 'propertyWithObjectStorageAnnotation',
110 array_keys((
new ClassSchema(Fixture\DummyClassWithAllTypesOfProperties::class))->getProperties())
119 $classSchema =
new ClassSchema(Fixture\DummyClassWithAllTypesOfMethods::class);
120 static::assertTrue($classSchema->hasMethod(
'publicMethod'));
121 static::assertFalse($classSchema->hasMethod(
'nonExistentMethod'));
134 'methodWithIgnoredTags',
136 'injectMethodWithoutParam',
137 'injectMethodThatIsProtected',
140 'methodWithMandatoryParam',
141 'methodWithNullableParam',
142 'methodWithDefaultValueParam',
143 'methodWithTypeHintedParam'
145 array_keys((
new ClassSchema(Fixture\DummyClassWithAllTypesOfMethods::class))->getMethods())
154 $classSchema =
new ClassSchema(Fixture\DummyClassWithAllTypesOfMethods::class);
156 $methodDefinition = $classSchema->getMethod(
'publicMethod');
157 static::assertTrue($methodDefinition[
'public']);
158 static::assertFalse($methodDefinition[
'protected']);
159 static::assertFalse($methodDefinition[
'private']);
161 $methodDefinition = $classSchema->getMethod(
'protectedMethod');
162 static::assertFalse($methodDefinition[
'public']);
163 static::assertTrue($methodDefinition[
'protected']);
164 static::assertFalse($methodDefinition[
'private']);
166 $methodDefinition = $classSchema->getMethod(
'privateMethod');
167 static::assertFalse($methodDefinition[
'public']);
168 static::assertFalse($methodDefinition[
'protected']);
169 static::assertTrue($methodDefinition[
'private']);
177 $classSchema =
new ClassSchema(Fixture\DummyClassWithInjectDoctrineAnnotation::class);
178 static::assertTrue($classSchema->hasInjectProperties());
180 $injectProperties = $classSchema->getInjectProperties();
181 static::assertArrayHasKey(
'propertyWithFullQualifiedClassName', $injectProperties);
182 static::assertSame(Fixture\DummyClassWithInjectDoctrineAnnotation::class, $injectProperties[
'propertyWithFullQualifiedClassName']);
184 static::assertArrayHasKey(
'propertyWithRelativeClassName', $injectProperties);
185 static::assertSame(
'DummyClassWithInjectDoctrineAnnotation', $injectProperties[
'propertyWithRelativeClassName']);
187 static::assertArrayHasKey(
'propertyWithImportedClassName', $injectProperties);
188 static::assertSame(
'ClassSchemaTest', $injectProperties[
'propertyWithImportedClassName']);
190 static::assertArrayHasKey(
'propertyWithImportedAndAliasedClassName', $injectProperties);
191 static::assertSame(
'AliasedClassSchemaTest', $injectProperties[
'propertyWithImportedAndAliasedClassName']);
199 $classSchema =
new ClassSchema(Fixture\DummyClassWithAllTypesOfMethods::class);
200 static::assertTrue($classSchema->hasInjectMethods());
202 $methodDefinition = $classSchema->getMethod(
'injectSettings');
203 static::assertFalse($methodDefinition[
'injectMethod']);
205 $methodDefinition = $classSchema->getMethod(
'injectMethodWithoutParam');
206 static::assertFalse($methodDefinition[
'injectMethod']);
208 $methodDefinition = $classSchema->getMethod(
'injectMethodThatIsProtected');
209 static::assertFalse($methodDefinition[
'injectMethod']);
211 $methodDefinition = $classSchema->getMethod(
'injectFoo');
212 static::assertTrue($methodDefinition[
'injectMethod']);
214 $injectMethods = $classSchema->getInjectMethods();
215 static::assertArrayHasKey(
'injectFoo', $injectMethods);
223 $classSchema =
new ClassSchema(Fixture\DummyClassWithLazyDoctrineAnnotation::class);
224 static::assertTrue($classSchema->getProperty(
'propertyWithLazyAnnotation')[
'annotations'][
'lazy']);
232 $classSchema =
new ClassSchema(Fixture\DummyClassWithAllTypesOfMethods::class);
234 $methodDefinition = $classSchema->getMethod(
'staticMethod');
235 static::assertTrue($methodDefinition[
'static']);
243 $classSchema =
new ClassSchema(Fixture\DummyClassWithAllTypesOfMethods::class);
245 $methodDefinition = $classSchema->getMethod(
'methodWithMandatoryParam');
246 static::assertFalse($methodDefinition[
'params'][
'param'][
'optional']);
254 $classSchema =
new ClassSchema(Fixture\DummyClassWithAllTypesOfMethods::class);
256 $methodDefinition = $classSchema->getMethod(
'methodWithNullableParam');
257 static::assertTrue($methodDefinition[
'params'][
'param'][
'nullable']);
265 $classSchema =
new ClassSchema(Fixture\DummyClassWithAllTypesOfMethods::class);
267 $methodDefinition = $classSchema->getMethod(
'methodWithDefaultValueParam');
268 static::assertSame(
'foo', $methodDefinition[
'params'][
'param'][
'default']);
276 $classSchema =
new ClassSchema(Fixture\DummyClassWithAllTypesOfMethods::class);
278 $methodDefinition = $classSchema->getMethod(
'methodWithTypeHintedParam');
279 static::assertSame(
'string', $methodDefinition[
'params'][
'param'][
'type']);
287 $classSchema =
new ClassSchema(Fixture\DummyClassWithAllTypesOfProperties::class);
289 $propertyDefinition = $classSchema->getProperty(
'publicProperty');
290 static::assertTrue($propertyDefinition[
'public']);
291 static::assertFalse($propertyDefinition[
'protected']);
292 static::assertFalse($propertyDefinition[
'private']);
294 $propertyDefinition = $classSchema->getProperty(
'protectedProperty');
295 static::assertFalse($propertyDefinition[
'public']);
296 static::assertTrue($propertyDefinition[
'protected']);
297 static::assertFalse($propertyDefinition[
'private']);
299 $propertyDefinition = $classSchema->getProperty(
'privateProperty');
300 static::assertFalse($propertyDefinition[
'public']);
301 static::assertFalse($propertyDefinition[
'protected']);
302 static::assertTrue($propertyDefinition[
'private']);
310 $classSchema =
new ClassSchema(Fixture\DummyClassWithAllTypesOfProperties::class);
312 $propertyDefinition = $classSchema->getProperty(
'propertyWithInjectAnnotation');
313 static::assertTrue($propertyDefinition[
'annotations'][
'inject']);
321 $classSchema =
new ClassSchema(Fixture\DummyClassWithAllTypesOfProperties::class);
323 $propertyDefinition = $classSchema->getProperty(
'propertyWithTransientAnnotation');
324 static::assertTrue($propertyDefinition[
'annotations'][
'transient']);
332 $classSchema =
new ClassSchema(Fixture\DummyClassWithAllTypesOfProperties::class);
334 $propertyDefinition = $classSchema->getProperty(
'propertyWithCascadeAnnotation');
335 static::assertSame(
'remove', $propertyDefinition[
'annotations'][
'cascade']);
343 $classSchema =
new ClassSchema(Fixture\DummyClassWithAllTypesOfProperties::class);
345 $propertyDefinition = $classSchema->getProperty(
'propertyWithCascadeAnnotationWithoutVarAnnotation');
346 static::assertNull($propertyDefinition[
'annotations'][
'cascade']);
354 $classSchema =
new ClassSchema(Fixture\DummyControllerWithIgnoreValidationDoctrineAnnotation::class);
355 static::assertTrue(isset($classSchema->getMethod(
'someAction')[
'tags'][
'ignorevalidation']));
356 static::assertTrue(in_array(
'foo', $classSchema->getMethod(
'someAction')[
'tags'][
'ignorevalidation'],
true));
357 static::assertTrue(in_array(
'bar', $classSchema->getMethod(
'someAction')[
'tags'][
'ignorevalidation'],
true));
358 static::assertFalse(in_array(
'baz', $classSchema->getMethod(
'someAction')[
'tags'][
'ignorevalidation'],
true));
366 $classSchema =
new ClassSchema(Fixture\DummyClassWithAllTypesOfProperties::class);
368 $propertyDefinition = $classSchema->getProperty(
'propertyWithObjectStorageAnnotation');
369 static::assertSame(ObjectStorage::class, $propertyDefinition[
'type']);
370 static::assertSame(Fixture\DummyClassWithAllTypesOfProperties::class, $propertyDefinition[
'elementType']);
378 static::assertTrue((
new ClassSchema(Fixture\DummySingleton::class))->isSingleton());
386 static::assertTrue((
new ClassSchema(Fixture\DummyEntity::class))->isModel());
387 static::assertTrue((
new ClassSchema(Fixture\DummyValueObject::class))->isModel());
395 static::assertTrue((
new ClassSchema(Fixture\DummyEntity::class))->isEntity());
403 static::assertTrue((
new ClassSchema(Fixture\DummyValueObject::class))->isValueObject());
411 $this->resetSingletonInstances =
true;
412 static::assertSame(Fixture\DummyModel::class, (
new ClassSchema(Fixture\DummyModel::class))->getClassName());
420 static::assertTrue((
new ClassSchema(Fixture\DummyClassWithAllTypesOfProperties::class))->hasProperty(
'publicProperty'));
421 static::assertTrue((
new ClassSchema(Fixture\DummyClassWithAllTypesOfProperties::class))->hasProperty(
'protectedProperty'));
422 static::assertTrue((
new ClassSchema(Fixture\DummyClassWithAllTypesOfProperties::class))->hasProperty(
'privateProperty'));
430 static::assertTrue((
new ClassSchema(Fixture\DummyClassWithAllTypesOfProperties::class))->hasProperty(
'publicStaticProperty'));
431 static::assertTrue((
new ClassSchema(Fixture\DummyClassWithAllTypesOfProperties::class))->hasProperty(
'protectedStaticProperty'));
432 static::assertTrue((
new ClassSchema(Fixture\DummyClassWithAllTypesOfProperties::class))->hasProperty(
'privateStaticProperty'));
440 $tags = (
new ClassSchema(Fixture\DummyClassWithTags::class))->getTags();
441 static::assertArrayHasKey(
'see', $tags);
444 static::assertArrayNotHasKey(
'package', $tags);
445 static::assertArrayNotHasKey(
'subpackage', $tags);
446 static::assertArrayNotHasKey(
'license', $tags);
447 static::assertArrayNotHasKey(
'copyright', $tags);
448 static::assertArrayNotHasKey(
'author', $tags);
449 static::assertArrayNotHasKey(
'version', $tags);
457 $this->resetSingletonInstances =
true;
458 $classSchema =
new ClassSchema(Fixture\DummyModel::class);
462 'name' =>
'StringLength',
467 'className' => StringLengthValidator::class
470 'name' =>
'NotEmpty',
472 'className' => NotEmptyValidator::class
475 'name' =>
'TYPO3.CMS.Extbase:NotEmpty',
477 'className' => NotEmptyValidator::class
480 'name' =>
'TYPO3.CMS.Extbase.Tests.Unit.Reflection.Fixture:DummyValidator',
482 'className' => Fixture\Validation\Validator\DummyValidator::class
485 'name' =>
'\TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator',
487 'className' => NotEmptyValidator::class
490 'name' => NotEmptyValidator::class,
492 'className' => NotEmptyValidator::class
495 $classSchema->getProperty(
'propertyWithValidateAnnotations')[
'validators']
504 $this->resetSingletonInstances =
true;
505 $classSchema =
new ClassSchema(Fixture\DummyController::class);
509 'name' =>
'StringLength',
514 'className' => StringLengthValidator::class
517 'name' =>
'NotEmpty',
519 'className' => NotEmptyValidator::class
522 'name' =>
'TYPO3.CMS.Extbase:NotEmpty',
524 'className' => NotEmptyValidator::class
527 'name' =>
'TYPO3.CMS.Extbase.Tests.Unit.Reflection.Fixture:DummyValidator',
529 'className' => Fixture\Validation\Validator\DummyValidator::class
532 'name' =>
'\TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator',
534 'className' => NotEmptyValidator::class
537 'name' => NotEmptyValidator::class,
539 'className' => NotEmptyValidator::class
542 $classSchema->getMethod(
'methodWithValidateAnnotationsAction')[
'params'][
'fooParam'][
'validators']
551 $this->resetSingletonInstances =
true;
552 $this->expectException(InvalidTypeHintException::class);
553 $this->expectExceptionMessage(
'Missing type information for parameter "$fooParam" in TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyControllerWithValidateAnnotationWithoutParamTypeHint->methodWithValidateAnnotationsAction(): Either use an @param annotation or use a type hint.');
554 $this->expectExceptionCode(1515075192);
556 new ClassSchema(Fixture\DummyControllerWithValidateAnnotationWithoutParamTypeHint::class);
564 $this->resetSingletonInstances =
true;
565 $this->expectException(InvalidValidationConfigurationException::class);
566 $this->expectExceptionMessage(
'Invalid validate annotation in TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyControllerWithValidateAnnotationWithoutParam->methodWithValidateAnnotationsAction(): The following validators have been defined for missing param "$fooParam": NotEmpty, StringLength');
567 $this->expectExceptionCode(1515073585);
569 new ClassSchema(Fixture\DummyControllerWithValidateAnnotationWithoutParam::class);