Neos\Flow\Tests\Unit\Validation\ValidatorResolverTest::buildBaseValidatorConjunctionAddsValidatorsDefinedByAnnotationsInTheClassToTheReturnedConjunction PHP Метод

buildBaseValidatorConjunctionAddsValidatorsDefinedByAnnotationsInTheClassToTheReturnedConjunction() публичный Метод

    public function buildBaseValidatorConjunctionAddsValidatorsDefinedByAnnotationsInTheClassToTheReturnedConjunction()
    {
        $mockObject = $this->createMock(\stdClass::class);
        $className = get_class($mockObject);
        $propertyTagsValues = ['foo' => ['var' => ['string']], 'bar' => ['var' => ['integer']], 'baz' => ['var' => ['array<TYPO3\\TestPackage\\Quux>']]];
        $validateAnnotations = ['foo' => [new Annotations\Validate(['type' => 'Foo', 'options' => ['bar' => 'baz']]), new Annotations\Validate(['type' => 'Bar']), new Annotations\Validate(['type' => 'Baz'])], 'bar' => [new Annotations\Validate(['type' => 'TYPO3\\TestPackage\\Quux'])]];
        $mockReflectionService = $this->getMockBuilder(ReflectionService::class)->disableOriginalConstructor()->getMock();
        $mockReflectionService->expects($this->any())->method('getAllImplementationClassNamesForInterface')->with(PolyTypeObjectValidatorInterface::class)->will($this->returnValue([]));
        $mockReflectionService->expects($this->at(0))->method('getClassSchema')->will($this->returnValue(null));
        $mockReflectionService->expects($this->at(1))->method('getClassPropertyNames')->with($className)->will($this->returnValue(['foo', 'bar', 'baz']));
        $mockReflectionService->expects($this->at(2))->method('getPropertyTagsValues')->with($className, 'foo')->will($this->returnValue($propertyTagsValues['foo']));
        $mockReflectionService->expects($this->at(3))->method('isPropertyAnnotatedWith')->will($this->returnValue(false));
        $mockReflectionService->expects($this->at(4))->method('getPropertyAnnotations')->with(get_class($mockObject), 'foo', Annotations\Validate::class)->will($this->returnValue($validateAnnotations['foo']));
        $mockReflectionService->expects($this->at(5))->method('getPropertyTagsValues')->with($className, 'bar')->will($this->returnValue($propertyTagsValues['bar']));
        $mockReflectionService->expects($this->at(6))->method('isPropertyAnnotatedWith')->will($this->returnValue(false));
        $mockReflectionService->expects($this->at(7))->method('getPropertyAnnotations')->with(get_class($mockObject), 'bar', Annotations\Validate::class)->will($this->returnValue($validateAnnotations['bar']));
        $mockReflectionService->expects($this->at(8))->method('getPropertyTagsValues')->with($className, 'baz')->will($this->returnValue($propertyTagsValues['baz']));
        $mockReflectionService->expects($this->at(9))->method('isPropertyAnnotatedWith')->will($this->returnValue(false));
        $mockReflectionService->expects($this->at(10))->method('getPropertyAnnotations')->with(get_class($mockObject), 'baz', Annotations\Validate::class)->will($this->returnValue([]));
        $mockObjectManager = $this->createMock(ObjectManagerInterface::class);
        $mockObjectManager->expects($this->any())->method('get')->with(ReflectionService::class)->will($this->returnValue($mockReflectionService));
        $mockObjectValidator = $this->createMock(GenericObjectValidator::class);
        $validatorResolver = $this->getAccessibleMock(ValidatorResolver::class, ['resolveValidatorObjectName', 'createValidator']);
        $validatorResolver->_set('reflectionService', $mockReflectionService);
        $validatorResolver->_set('objectManager', $mockObjectManager);
        $validatorResolver->expects($this->at(0))->method('createValidator')->with('Foo', ['bar' => 'baz'])->will($this->returnValue($mockObjectValidator));
        $validatorResolver->expects($this->at(1))->method('createValidator')->with('Bar')->will($this->returnValue($mockObjectValidator));
        $validatorResolver->expects($this->at(2))->method('createValidator')->with('Baz')->will($this->returnValue($mockObjectValidator));
        $validatorResolver->expects($this->at(3))->method('createValidator')->with('TYPO3\\TestPackage\\Quux')->will($this->returnValue($mockObjectValidator));
        $validatorResolver->expects($this->at(4))->method('createValidator')->with(CollectionValidator::class, ['elementType' => 'TYPO3\\TestPackage\\Quux', 'validationGroups' => ['Default']])->will($this->returnValue($mockObjectValidator));
        $validatorResolver->_call('buildBaseValidatorConjunction', $className . 'Default', $className, ['Default']);
        $builtValidators = $validatorResolver->_get('baseValidatorConjunctions');
        $this->assertInstanceOf(ConjunctionValidator::class, $builtValidators[$className . 'Default']);
    }
ValidatorResolverTest