public function testGetTree()
 {
     $userRepo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     $buRepo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->any())->method('getRepository')->will($this->returnCallback(function ($repoName) use($userRepo, $buRepo) {
         if ($repoName == 'Oro\\Bundle\\UserBundle\\Entity\\User') {
             return $userRepo;
         }
         if ($repoName == 'Oro\\Bundle\\OrganizationBundle\\Entity\\BusinessUnit') {
             return $buRepo;
         }
     }));
     list($users, $bUnits) = $this->getTestData();
     $userRepo->expects($this->any())->method('findAll')->will($this->returnValue($users));
     $buRepo->expects($this->any())->method('findAll')->will($this->returnValue($bUnits));
     $metadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($metadata));
     $metadata->expects($this->any())->method('getTableName')->will($this->returnValue('test'));
     $connection = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
     $connection->expects($this->any())->method('isConnected')->will($this->returnValue(true));
     $schemaManager = $this->getMockBuilder('Doctrine\\DBAL\\Schema\\MySqlSchemaManager')->disableOriginalConstructor()->getMock();
     $connection->expects($this->any())->method('getSchemaManager')->will($this->returnValue($schemaManager));
     $schemaManager->expects($this->any())->method('listTableNames')->will($this->returnValue(array('test')));
     $this->treeProvider->warmUpCache();
     $tree = $this->treeProvider->getTree();
     $this->assertEquals(1, $tree->getBusinessUnitOrganizationId(1));
     $this->assertEquals([1], $tree->getUserOrganizationIds(1));
 }
Exemplo n.º 2
0
 public function testGetTree()
 {
     $userRepo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     $buRepo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->any())->method('getRepository')->will($this->returnValueMap([['Oro\\Bundle\\UserBundle\\Entity\\User', $userRepo], ['Oro\\Bundle\\OrganizationBundle\\Entity\\BusinessUnit', $buRepo]]));
     list($users, $bUnits) = $this->getTestData();
     $userRepo->expects($this->any())->method('findAll')->will($this->returnValue($users));
     $qb = $this->getMockBuilder('\\Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
     $query = $this->getMockBuilder('\\Doctrine\\ORM\\AbstractQuery')->setMethods(['setParameter', 'getArrayResult'])->disableOriginalConstructor()->getMockForAbstractClass();
     $buRepo->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($qb));
     $qb->expects($this->once())->method('select')->will($this->returnValue($qb));
     $qb->expects($this->once())->method('getQuery')->will($this->returnValue($query));
     $query->expects($this->once())->method('getArrayResult')->will($this->returnValue($bUnits));
     $metadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($metadata));
     $metadata->expects($this->any())->method('getTableName')->will($this->returnValue('test'));
     $connection = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
     $schemaManager = $this->getMockBuilder('Doctrine\\DBAL\\Schema\\MySqlSchemaManager')->disableOriginalConstructor()->getMock();
     $connection->expects($this->any())->method('getSchemaManager')->will($this->returnValue($schemaManager));
     $schemaManager->expects($this->any())->method('tablesExist')->with('test')->will($this->returnValue(true));
     $this->treeProvider->warmUpCache();
     /** @var OwnerTree $tree */
     $tree = $this->treeProvider->getTree();
     $this->assertEquals(1, $tree->getBusinessUnitOrganizationId(1));
     $this->assertEquals([1], $tree->getUserOrganizationIds(1));
 }
Exemplo n.º 3
0
 /**
  * {inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     $this->treeProvider->warmUpCache();
 }