/** * Sets up this test case * */ protected function setUp() { $this->mockObjectManager = $this->createMock(ObjectManagerInterface::class); $this->mockObjectManager->expects($this->any())->method('isRegistered')->will($this->returnCallback(array($this, 'objectManagerIsRegisteredCallback'))); $this->parser = $this->getAccessibleMock(Parser::class, array('dummy')); $this->parser->_set('objectManager', $this->mockObjectManager); }
/** * Prepare test objects */ protected function setUp() { $this->nodeFactory = $this->getMockBuilder(NodeFactory::class)->setMethods(array('filterNodeByContext'))->getMock(); $this->nodeFactory->expects(self::any())->method('filterNodeByContext')->willReturnArgument(0); $this->reflectionServiceMock = $this->createMock(ReflectionService::class); $this->reflectionServiceMock->expects(self::any())->method('getAllImplementationClassNamesForInterface')->with(NodeInterface::class)->willReturn(array(Node::class)); $this->objectManagerMock = $this->createMock(ObjectManagerInterface::class); $this->objectManagerMock->expects(self::any())->method('get')->with(ReflectionService::class)->willReturn($this->reflectionServiceMock); $this->objectManagerMock->expects(self::any())->method('getClassNameByObjectName')->with(NodeInterface::class)->willReturn(Node::class); $this->inject($this->nodeFactory, 'objectManager', $this->objectManagerMock); }
/** * Sets up this test case * */ public function setUp() { $this->mockObjectManager = $this->createMock(ObjectManagerInterface::class); $this->mockObjectManager->expects($this->any())->method('getObjectNameByClassName')->with('Acme\\Test\\Command\\DefaultCommandController')->will($this->returnValue('Acme\\Test\\Command\\DefaultCommandController')); $this->mockCommand = $this->getMockBuilder(Cli\Command::class)->disableOriginalConstructor()->getMock(); $this->mockCommand->expects($this->any())->method('getControllerClassName')->will($this->returnValue('Acme\\Test\\Command\\DefaultCommandController')); $this->mockCommand->expects($this->any())->method('getControllerCommandName')->will($this->returnValue('list')); $this->mockCommandManager = $this->createMock(Cli\CommandManager::class); $this->mockCommandManager->expects($this->any())->method('getCommandByIdentifier')->with('acme.test:default:list')->will($this->returnValue($this->mockCommand)); $this->mockReflectionService = $this->createMock(ReflectionService::class); $this->requestBuilder = new Cli\RequestBuilder(); $this->requestBuilder->injectObjectManager($this->mockObjectManager); $this->requestBuilder->injectCommandManager($this->mockCommandManager); }
/** * @return void */ public function setUp() { parent::setup(); vfsStream::setup('Foo'); $this->httpRequest = Http\Request::create(new Http\Uri('http://localhost')); $this->httpResponse = new Http\Response(); $mockRequestHandler = $this->createMock(Http\RequestHandler::class); $mockRequestHandler->expects($this->any())->method('getHttpRequest')->will($this->returnValue($this->httpRequest)); $mockRequestHandler->expects($this->any())->method('getHttpResponse')->will($this->returnValue($this->httpResponse)); $this->mockBootstrap = $this->createMock(Bootstrap::class); $this->mockBootstrap->expects($this->any())->method('getActiveRequestHandler')->will($this->returnValue($mockRequestHandler)); $this->mockSecurityContext = $this->createMock(Context::class); $this->mockObjectManager = $this->createMock(ObjectManagerInterface::class); $this->mockObjectManager->expects($this->any())->method('get')->with(Context::class)->will($this->returnValue($this->mockSecurityContext)); }
/** * Sets up this test case */ public function setUp() { $this->dispatcher = $this->getMockBuilder(Dispatcher::class)->disableOriginalConstructor()->setMethods(['resolveController'])->getMock(); $this->mockActionRequest = $this->getMockBuilder(ActionRequest::class)->disableOriginalConstructor()->getMock(); $this->mockActionRequest->expects($this->any())->method('isMainRequest')->will($this->returnValue(false)); $this->mockParentRequest = $this->getMockBuilder(ActionRequest::class)->disableOriginalConstructor()->getMock(); $this->mockActionRequest->expects($this->any())->method('getParentRequest')->will($this->returnValue($this->mockParentRequest)); $this->mockMainRequest = $this->getMockBuilder(ActionRequest::class)->disableOriginalConstructor()->getMock(); $this->mockActionRequest->expects($this->any())->method('getMainRequest')->will($this->returnValue($this->mockMainRequest)); $this->mockHttpRequest = $this->getMockBuilder(HttpRequest::class)->disableOriginalConstructor()->getMock(); $this->mockActionRequest->expects($this->any())->method('getHttpRequest')->will($this->returnValue($this->mockHttpRequest)); $this->mockHttpResponse = $this->getMockBuilder(HttpResponse::class)->disableOriginalConstructor()->getMock(); $this->mockController = $this->getMockBuilder(ControllerInterface::class)->setMethods(['processRequest'])->getMock(); $this->dispatcher->expects($this->any())->method('resolveController')->will($this->returnValue($this->mockController)); $this->mockSecurityContext = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); $this->mockFirewall = $this->getMockBuilder(FirewallInterface::class)->getMock(); $this->mockSecurityLogger = $this->getMockBuilder(SecurityLoggerInterface::class)->getMock(); $this->mockObjectManager = $this->getMockBuilder(ObjectManagerInterface::class)->getMock(); $this->mockObjectManager->expects($this->any())->method('get')->will($this->returnCallback(function ($className) { if ($className === Context::class) { return $this->mockSecurityContext; } elseif ($className === FirewallInterface::class) { return $this->mockFirewall; } elseif ($className === SecurityLoggerInterface::class) { return $this->mockSecurityLogger; } return null; })); $this->inject($this->dispatcher, 'objectManager', $this->mockObjectManager); }
/** * @test */ public function resolveValidatorObjectNameCanResolveShortNamesOfBuiltInValidators() { $this->mockObjectManager->expects($this->at(0))->method('get')->with(ReflectionService::class)->will($this->returnValue($this->mockReflectionService)); $this->mockObjectManager->expects($this->at(1))->method('isRegistered')->with('Foo')->will($this->returnValue(false)); $this->mockObjectManager->expects($this->at(2))->method('isRegistered')->with('Neos\\Flow\\Validation\\Validator\\FooValidator')->will($this->returnValue(true)); $this->mockReflectionService->expects($this->any())->method('getAllImplementationClassNamesForInterface')->with(ValidatorInterface::class)->will($this->returnValue(['Neos\\Flow\\Validation\\Validator\\FooValidator'])); $this->assertSame('Neos\\Flow\\Validation\\Validator\\FooValidator', $this->validatorResolver->_call('resolveValidatorObjectName', 'Foo')); }
/** * @test */ public function validatePasswordWillUseStrategyIdentifierFromHashedPassword() { $mockStrategy = $this->createMock(PasswordHashingStrategyInterface::class); $this->mockObjectManager->expects($this->any())->method('get')->will($this->returnValue($mockStrategy)); $mockStrategy->expects($this->atLeastOnce())->method('validatePassword')->with('myTestPassword', '---hashed-password---')->will($this->returnValue(true)); $result = $this->hashService->validatePassword('myTestPassword', 'TestStrategy=>---hashed-password---'); $this->assertEquals(true, $result); }
/** * @test */ public function convertFromReturnsNullIfResourcePropertyIsNotConverted() { $this->mockObjectManager->expects($this->any())->method('getClassNameByObjectName')->will($this->returnCallback(function ($objectType) { return $objectType; })); $configuration = new PropertyMappingConfiguration(); $configuration->setTypeConverterOption(ImageInterfaceConverter::class, PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED, true); $this->assertNull($this->converter->convertFrom(array(), Image::class, array(), $configuration)); }
/** * @test */ public function parseSetsDefaultValueOfRoutePartsRecursively() { $this->route->setUriPattern('{foo.bar}'); $this->route->setRoutePartsConfiguration(['foo.bar' => ['handler' => 'SomeRoutePartHandler']]); $this->route->setDefaults(['foo' => ['bar' => 'SomeDefaultValue']]); $mockRoutePartHandler = $this->createMock(Routing\DynamicRoutePartInterface::class); $mockRoutePartHandler->expects($this->once())->method('setDefaultValue')->with('SomeDefaultValue'); $this->mockObjectManager->expects($this->once())->method('get')->with('SomeRoutePartHandler')->will($this->returnValue($mockRoutePartHandler)); $this->route->parse(); }
/** * @test * @expectedException \Neos\Flow\Property\Exception\InvalidTargetException */ public function convertFromShouldThrowExceptionIfRequiredConstructorParameterWasNotFound() { $source = ['propertyX' => 'bar']; $object = new ClassWithSettersAndConstructor('param1'); $convertedChildProperties = ['property2' => 'bar']; $this->mockReflectionService->expects($this->once())->method('hasMethod')->with(ClassWithSettersAndConstructor::class, '__construct')->will($this->returnValue(true)); $this->mockReflectionService->expects($this->once())->method('getMethodParameters')->with(ClassWithSettersAndConstructor::class, '__construct')->will($this->returnValue(array('property1' => array('optional' => false, 'type' => null)))); $this->mockObjectManager->expects($this->once())->method('getClassNameByObjectName')->with(ClassWithSettersAndConstructor::class)->will($this->returnValue(ClassWithSettersAndConstructor::class)); $configuration = $this->buildConfiguration(array(PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED => true)); $result = $this->converter->convertFrom($source, ClassWithSettersAndConstructor::class, $convertedChildProperties, $configuration); $this->assertSame($object, $result); }
/** * @test */ public function convertFromUsesPropertyMapperToConvertNodePropertyOfArrayType() { $contextPath = '/foo/bar@user-demo'; $nodePath = '/foo/bar'; $nodeTypeProperties = array('assets' => array('type' => 'array<Neos\\Media\\Domain\\Model\\Asset>')); $decodedPropertyValue = array('8aaf4dd2-bd85-11e3-ae3d-14109fd7a2dd', '8febe94a-bd85-11e3-8401-14109fd7a2dd'); $source = array('__contextNodePath' => $contextPath, 'assets' => json_encode($decodedPropertyValue)); $convertedPropertyValue = array(new \stdClass(), new \stdClass()); $mockNode = $this->setUpNodeWithNodeType($nodePath, $nodeTypeProperties); $this->mockObjectManager->expects($this->any())->method('isRegistered')->with(Asset::class)->will($this->returnValue(true)); $this->mockPropertyMapper->expects($this->once())->method('convert')->with($decodedPropertyValue, $nodeTypeProperties['assets']['type'])->will($this->returnValue($convertedPropertyValue)); $mockNode->expects($this->once())->method('setProperty')->with('assets', $convertedPropertyValue); $this->nodeConverter->convertFrom($source, null, array(), $this->mockConverterConfiguration); }
/** * @test */ public function handleInjectsActionRequestToSecurityContext() { $mockWidgetId = 'SomeWidgetId'; $mockControllerObjectName = 'SomeControllerObjectName'; $this->mockHttpRequest->expects($this->at(0))->method('hasArgument')->with('__widgetId')->will($this->returnValue(true)); $this->mockHttpRequest->expects($this->atLeastOnce())->method('getArgument')->with('__widgetId')->will($this->returnValue($mockWidgetId)); $mockWidgetContext = $this->getMockBuilder(\Neos\FluidAdaptor\Core\Widget\WidgetContext::class)->getMock(); $mockWidgetContext->expects($this->atLeastOnce())->method('getControllerObjectName')->will($this->returnValue($mockControllerObjectName)); $this->mockAjaxWidgetContextHolder->expects($this->atLeastOnce())->method('get')->with($mockWidgetId)->will($this->returnValue($mockWidgetContext)); $mockActionRequest = $this->getMockBuilder(\Neos\Flow\Mvc\ActionRequest::class)->disableOriginalConstructor()->getMock(); $this->mockObjectManager->expects($this->atLeastOnce())->method('get')->with(\Neos\Flow\Mvc\ActionRequest::class)->will($this->returnValue($mockActionRequest)); $this->mockSecurityContext->expects($this->once())->method('setRequest')->with($mockActionRequest); $this->ajaxWidgetComponent->handle($this->mockComponentContext); }
/** * Sets up this test case */ public function setUp() { $this->routerCachingService = $this->getAccessibleMock(RouterCachingService::class, ['dummy']); $this->mockRouteCache = $this->getMockBuilder(VariableFrontend::class)->disableOriginalConstructor()->getMock(); $this->inject($this->routerCachingService, 'routeCache', $this->mockRouteCache); $this->mockResolveCache = $this->getMockBuilder(StringFrontend::class)->disableOriginalConstructor()->getMock(); $this->inject($this->routerCachingService, 'resolveCache', $this->mockResolveCache); $this->mockPersistenceManager = $this->getMockBuilder(PersistenceManagerInterface::class)->getMock(); $this->inject($this->routerCachingService, 'persistenceManager', $this->mockPersistenceManager); $this->mockSystemLogger = $this->getMockBuilder(SystemLoggerInterface::class)->getMock(); $this->inject($this->routerCachingService, 'systemLogger', $this->mockSystemLogger); $this->mockObjectManager = $this->createMock(ObjectManagerInterface::class); $this->mockApplicationContext = $this->getMockBuilder(ApplicationContext::class)->disableOriginalConstructor()->getMock(); $this->mockObjectManager->expects($this->any())->method('getContext')->will($this->returnValue($this->mockApplicationContext)); $this->inject($this->routerCachingService, 'objectManager', $this->mockObjectManager); $this->inject($this->routerCachingService, 'objectManager', $this->mockObjectManager); $this->mockHttpRequest = $this->getMockBuilder(\Neos\Flow\Http\Request::class)->disableOriginalConstructor()->getMock(); $this->mockHttpRequest->expects($this->any())->method('getMethod')->will($this->returnValue('GET')); $this->mockHttpRequest->expects($this->any())->method('getRelativePath')->will($this->returnValue('some/route/path')); $this->mockUri = $this->getMockBuilder(\Neos\Flow\Http\Uri::class)->disableOriginalConstructor()->getMock(); $this->mockUri->expects($this->any())->method('getHost')->will($this->returnValue('subdomain.domain.com')); $this->mockHttpRequest->expects($this->any())->method('getUri')->will($this->returnValue($this->mockUri)); }
/** * @test */ public function parseDesignatorMethodAnnotatedWithObservesAnnotationPropertyConstraints() { $this->mockObjectManager->expects($this->any())->method('get')->will($this->returnValue($this->createMock(SystemLoggerInterface::class))); $pointcutFilterComposite = new PointcutFilterComposite(); $parser = $this->getAccessibleMock(PointcutExpressionParser::class, ['dummy'], [], '', false); $parser->injectReflectionService($this->mockReflectionService); $parser->injectObjectManager($this->mockObjectManager); $parser->_call('parseDesignatorMethodAnnotatedWith', '&&', 'foo(bar == FALSE)', $pointcutFilterComposite); $expectedAnnotation = 'foo'; $expectedAnnotationValueConstraints = ['bar' => ['operator' => [0 => '=='], 'value' => [0 => 'FALSE']]]; $filters = ObjectAccess::getProperty($pointcutFilterComposite, 'filters', true); $filter = $filters[0][1]; $annotation = ObjectAccess::getProperty($filter, 'annotation', true); $annotationValueConstraints = ObjectAccess::getProperty($filter, 'annotationValueConstraints', true); $this->assertEquals($expectedAnnotation, $annotation); $this->assertEquals($expectedAnnotationValueConstraints, $annotationValueConstraints); }
/** * @return void */ public function setUp() { $this->dispatchComponent = new DispatchComponent(); $this->mockComponentContext = $this->getMockBuilder(ComponentContext::class)->disableOriginalConstructor()->getMock(); $this->mockHttpRequest = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->getMock(); $this->mockComponentContext->expects($this->any())->method('getHttpRequest')->will($this->returnValue($this->mockHttpRequest)); $this->mockHttpResponse = $this->getMockBuilder(Response::class)->disableOriginalConstructor()->getMock(); $this->mockComponentContext->expects($this->any())->method('getHttpResponse')->will($this->returnValue($this->mockHttpResponse)); $this->mockDispatcher = $this->getMockBuilder(Dispatcher::class)->getMock(); $this->inject($this->dispatchComponent, 'dispatcher', $this->mockDispatcher); $this->mockActionRequest = $this->getMockBuilder(ActionRequest::class)->disableOriginalConstructor()->getMock(); $mockMediaTypeConverter = $this->createMock(MediaTypeConverterInterface::class); $this->mockObjectManager = $this->createMock(ObjectManagerInterface::class); $this->mockObjectManager->expects($this->any())->method('get')->willReturnMap([[ActionRequest::class, $this->mockHttpRequest, $this->mockActionRequest], [MediaTypeConverterInterface::class, $mockMediaTypeConverter]]); $this->inject($this->dispatchComponent, 'objectManager', $this->mockObjectManager); $this->mockSecurityContext = $this->getMockBuilder(Security\Context::class)->getMock(); $this->inject($this->dispatchComponent, 'securityContext', $this->mockSecurityContext); $this->mockPropertyMapper = $this->getMockBuilder(PropertyMapper::class)->disableOriginalConstructor()->getMock(); $this->inject($this->dispatchComponent, 'propertyMapper', $this->mockPropertyMapper); }
/** * @test * @expectedException \Neos\Flow\Http\Component\Exception */ public function createThrowsExceptionIfComponentClassNameDoesNotImplementComponentInterface() { $chainConfiguration = ['foo' => ['component' => 'Foo\\Component\\ClassName']]; $this->mockObjectManager->expects($this->at(0))->method('get')->with('Foo\\Component\\ClassName')->will($this->returnValue(new \stdClass())); $this->componentChainFactory->create($chainConfiguration); }
/** * @test * @expectedException \Neos\Flow\Mvc\Exception\ViewNotFoundException */ public function resolveViewThrowsExceptionIfResolvedViewDoesNotImplementViewInterface() { $this->mockObjectManager->expects($this->any())->method('getCaseSensitiveObjectName')->will($this->returnValue(false)); $this->actionController->_set('defaultViewObjectName', 'ViewDefaultObjectName'); $this->actionController->_call('resolveView'); }
public function setUp() { $this->mockReflectionService = $this->getMockBuilder(\Neos\Flow\Reflection\ReflectionService::class)->disableOriginalConstructor()->getMock(); $this->mockObjectManager = $this->createMock(\Neos\Flow\ObjectManagement\ObjectManagerInterface::class); $this->mockObjectManager->expects($this->any())->method('get')->with(\Neos\Flow\Reflection\ReflectionService::class)->will($this->returnValue($this->mockReflectionService)); }