protected function setUp()
 {
     if (!class_exists('Doctrine\\DBAL\\DriverManager')) {
         $this->markTestSkipped('The Doctrine2 DBAL is required for this test');
     }
     $this->ownerTree = new OwnerTree();
     $this->metadataProvider = new OwnershipMetadataProviderStub($this);
     $objectIdAccessor = new ObjectIdAccessor();
     $treeProviderMock = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Owner\\OwnerTreeProvider')->disableOriginalConstructor()->getMock();
     $treeProviderMock->expects($this->any())->method('getTree')->will($this->returnValue($this->ownerTree));
     $decisionMaker = new EntityOwnershipDecisionMaker($treeProviderMock, $objectIdAccessor, new EntityOwnerAccessor($this->metadataProvider), $this->metadataProvider);
     $this->strategy = new PermissionGrantingStrategy($decisionMaker, $this->metadataProvider);
     $this->selector = TestHelper::get($this)->createAclExtensionSelector($this->metadataProvider);
     $this->context = new PermissionGrantingStrategyContext($this->selector);
     $contextLink = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\DependencyInjection\\Utils\\ServiceLink')->disableOriginalConstructor()->getMock();
     $contextLink->expects($this->any())->method('getService')->will($this->returnValue($this->context));
     $this->strategy->setContext($contextLink);
     $user = new User(1);
     $this->sid = new UserSecurityIdentity('TestUser', get_class($user));
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $token->expects($this->any())->method('getUser')->will($this->returnValue($user));
     $this->context->setSecurityToken($token);
     $this->context->setObject(new TestEntity('testId'));
     $this->map = new PermissionMap($this->selector);
 }
 protected function setUp()
 {
     if (!class_exists('Doctrine\\DBAL\\DriverManager')) {
         $this->markTestSkipped('The Doctrine2 DBAL is required for this test');
     }
     $this->ownerTree = new OwnerTree();
     $this->metadataProvider = new OwnershipMetadataProviderStub($this);
     $objectIdAccessor = new ObjectIdAccessor();
     /** @var \PHPUnit_Framework_MockObject_MockObject|OwnerTreeProvider $treeProviderMock */
     $treeProviderMock = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Owner\\OwnerTreeProvider')->disableOriginalConstructor()->getMock();
     $treeProviderMock->expects($this->any())->method('getTree')->will($this->returnValue($this->ownerTree));
     $configProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $configProvider->expects($this->any())->method('hasConfig')->willReturn(false);
     $this->container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $this->container->expects($this->any())->method('get')->will($this->returnValueMap([['oro_security.ownership_tree_provider.chain', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $treeProviderMock], ['oro_security.owner.metadata_provider.chain', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->metadataProvider], ['oro_security.acl.object_id_accessor', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $objectIdAccessor], ['oro_security.owner.entity_owner_accessor', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, new EntityOwnerAccessor($this->metadataProvider)], ['oro_entity_config.provider.security', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $configProvider]]));
     $decisionMaker = new EntityOwnershipDecisionMaker($treeProviderMock, $objectIdAccessor, new EntityOwnerAccessor($this->metadataProvider), $this->metadataProvider);
     $decisionMaker->setContainer($this->container);
     $this->strategy = new PermissionGrantingStrategy($decisionMaker, $this->metadataProvider);
     $this->selector = TestHelper::get($this)->createAclExtensionSelector($this->metadataProvider, $this->ownerTree, $decisionMaker);
     $this->context = new PermissionGrantingStrategyContext($this->selector);
     $contextLink = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\DependencyInjection\\Utils\\ServiceLink')->disableOriginalConstructor()->getMock();
     $contextLink->expects($this->any())->method('getService')->will($this->returnValue($this->context));
     $this->strategy->setContext($contextLink);
     $user = new User(1);
     $user->setUsername('TestUser');
     $this->sid = new UserSecurityIdentity('TestUser', get_class($user));
     $this->rsid = new RoleSecurityIdentity('TestRole');
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $token->expects($this->any())->method('getUser')->will($this->returnValue($user));
     $this->context->setSecurityToken($token);
     $this->context->setObject(new TestEntity('testId'));
     $this->map = new PermissionMap($this->selector);
 }