Переглянути джерело

[Closure Table] Fixed some typos and indentation

Gustavo Adrian 14 роки тому
батько
коміт
f2c322e323

+ 24 - 25
lib/Gedmo/Tree/Entity/Repository/ClosureTreeRepository.php

@@ -29,22 +29,21 @@ class ClosureTreeRepository extends AbstractTreeRepository
      * @param boolean $direct - true to count only direct children
      * @return integer
      */ 
-    public function childCount( $node, $direct = false )
+    public function childCount($node, $direct = false)
     {
-		$meta 	= $this->getClassMetadata();
-		$id		= $this->getIdFromEntity( $node );
-		$qb 	= $this->getQueryBuilder();
-		$qb->select( 'COUNT( c.id )' )
-			->from( $meta->rootEntityName, 'c' )
-			->where( 'c.ancestor = :node_id' )
-			->andWhere( 'c.ancestor != c.descendant' );
-		
-		if ( $direct === true )
-		{
-			$qb->andWhere( 'c.depth = 1' );
-		}
-		
-		$qb->setParameter( 'node_id', $id );
+        $meta = $this->getClassMetadata();
+        $id	= $this->getIdFromEntity($node);
+        $qb = $this->getQueryBuilder();
+        $qb->select('COUNT( c.id )')
+            ->from($meta->rootEntityName, 'c')
+            ->where('c.ancestor = :node_id')
+            ->andWhere('c.ancestor != c.descendant');
+        
+		if ($direct === true) {
+			$qb->andWhere('c.depth = 1');
+        }
+        
+        $qb->setParameter('node_id', $id);
 		
         return $qb->getQuery()->getSingleScalarResult();
     }
@@ -52,19 +51,19 @@ class ClosureTreeRepository extends AbstractTreeRepository
 	
 	protected function getQueryBuilder()
 	{
-		$qb = $this->_em->createQueryBuilder();
-		
-		return $qb;
+        $qb = $this->_em->createQueryBuilder();
+        
+        return $qb;
 	}
 	
 	protected function getIdFromEntity( $node )
 	{
-		$meta 		= $this->_em->getClassMetadata( get_class( $node ) );
-		$nodeID 	= $meta->getSingleIdentifierFieldName();
-		$refProp	= $meta->getReflectionProperty( $nodeID );
-		$id 		= $refProp->getValue( $node );
-		
-		return $id;
+        $meta = $this->_em->getClassMetadata(get_class($node));
+        $nodeID = $meta->getSingleIdentifierFieldName();
+        $refProp = $meta->getReflectionProperty($nodeID);
+        $id = $refProp->getValue($node);
+        
+        return $id;
 	}
 	
 	/**
@@ -73,6 +72,6 @@ class ClosureTreeRepository extends AbstractTreeRepository
     protected function validates()
     {
         // Temporarily solution to validation problem with this class
-		return true;
+        return true;
     }
 }

+ 72 - 75
lib/Gedmo/Tree/Strategy/ORM/Closure.php

@@ -73,18 +73,18 @@ class Closure implements Strategy
     /**
      * {@inheritdoc}
      */
-    public function processPostPersist( $em, $entity )
+    public function processPostPersist($em, $entity)
     {        
-        if ( count( $this->pendingChildNodeInserts ) ) 
+        if (count($this->pendingChildNodeInserts)) 
 		{
-            while ( $entity = array_shift( $this->pendingChildNodeInserts ) ) 
-			{
-                $this->insertNode( $em, $entity );
+            while ($entity = array_shift($this->pendingChildNodeInserts)) 
+            {
+                $this->insertNode($em, $entity);
             }
         }
     }
     
-    public function insertNode(EntityManager $em, $entity, $addNodeChildrenToAncestors = false )
+    public function insertNode(EntityManager $em, $entity, $addNodeChildrenToAncestors = false)
     {
         $meta = $em->getClassMetadata(get_class($entity));
         $config = $this->listener->getConfiguration($em, $meta->name);
@@ -94,19 +94,17 @@ class Closure implements Strategy
         $entries = array();
 		
 		// If node has children it means it already has a self referencing row, so we skip its insertion
-		if ( $addNodeChildrenToAncestors === false )
-		{
-			$entries[] = array(
-				'ancestor'		=> $id,
-				'descendant' 	=> $id,
-				'depth' 		=> 0
-			);
-		}
+		if ($addNodeChildrenToAncestors === false) {
+            $entries[] = array(
+                'ancestor'		=> $id,
+                'descendant' 	=> $id,
+                'depth' 		=> 0
+            );
+        }
 		
-        $parent = $meta->getReflectionProperty( $config[ 'parent' ] )->getValue( $entity );
+        $parent = $meta->getReflectionProperty($config['parent'])->getValue($entity);
 		
-        if ( $parent ) 
-		{
+        if ( $parent ) {
             $parentId = $meta->getReflectionProperty($identifier)->getValue($parent);
             $dql = "SELECT c.ancestor, c.depth FROM {$closureMeta->name} c";
             $dql .= " WHERE c.descendant = {$parentId}";
@@ -114,27 +112,26 @@ class Closure implements Strategy
             //echo count($ancestors);
             foreach ($ancestors as $ancestor) {
                 $entries[] = array(
-                	'ancestor' => $ancestor['ancestor'],
+                    'ancestor' => $ancestor['ancestor'],
                     'descendant' => $id,
                     'depth' => $ancestor['depth'] + 1
                 );
 				
-				if ( $addNodeChildrenToAncestors === true )
-				{
-					$dql 		= "SELECT c.descendant, c.depth FROM {$closureMeta->name} c";
-					$dql 		.= " WHERE c.ancestor = {$id} AND c.ancestor != c.descendant";
-					$children 	= $em->createQuery( $dql )
-						->getArrayResult();
-					
-					foreach ( $children as $child )
-					{
-						$entries[] = array(
-							'ancestor'		=> $ancestor[ 'ancestor' ],
-							'descendant'	=> $child[ 'descendant' ],
-							'depth'			=> $child[ 'depth' ] + 1
-						);
-					}
-				}
+                if ($addNodeChildrenToAncestors === true) {
+                    $dql 		= "SELECT c.descendant, c.depth FROM {$closureMeta->name} c";
+                    $dql 		.= " WHERE c.ancestor = {$id} AND c.ancestor != c.descendant";
+                    $children 	= $em->createQuery($dql)
+                        ->getArrayResult();
+                    
+                    foreach ($children as $child)
+                    {
+                        $entries[] = array(
+                            'ancestor'		=> $ancestor['ancestor'],
+                            'descendant'	=> $child['descendant'],
+                            'depth'			=> $child['depth'] + 1
+                        );
+                    }
+                }
             }	
         }
         
@@ -163,18 +160,18 @@ class Closure implements Strategy
     
     public function updateNode(EntityManager $em, $entity, array $change)
     {
-        $meta 			= $em->getClassMetadata(get_class($entity));
-        $config 		= $this->listener->getConfiguration($em, $meta->name);
-        $closureMeta 	= $em->getClassMetadata($config['closure']);
-        $oldParent 		= $change[ 0 ];
-        $nodeId 		= $this->extractIdentifier($em, $entity);
-        $table 			= $closureMeta->getTableName();
+        $meta = $em->getClassMetadata(get_class($entity));
+        $config = $this->listener->getConfiguration($em, $meta->name);
+        $closureMeta = $em->getClassMetadata($config['closure']);
+        $oldParent = $change[0];
+        $nodeId = $this->extractIdentifier($em, $entity);
+        $table = $closureMeta->getTableName();
 		
-        if ( $oldParent ) 
+        if ($oldParent) 
 		{
-            $this->removeClosurePathsOfNodeID( $em, $table, $nodeId );
-			
-			$this->insertNode( $em, $entity, true );
+            $this->removeClosurePathsOfNodeID($em, $table, $nodeId);
+            
+            $this->insertNode($em, $entity, true);
         }
         
         //\Doctrine\Common\Util\Debug::dump($oldParent);
@@ -184,44 +181,44 @@ class Closure implements Strategy
 	/**
      * {@inheritdoc}
      */
-    public function processScheduledDelete( $em, $entity )
+    public function processScheduledDelete($em, $entity)
     {
-		$this->removeNode( $em, $entity );
-	}
+        $this->removeNode($em, $entity);
+    }
 	
-	public function removeNode( EntityManager $em, $entity, $maintainSelfReferencingRow = false, $maintainSelfReferencingRowOfChildren = false )
+    public function removeNode(EntityManager $em, $entity, $maintainSelfReferencingRow = false, $maintainSelfReferencingRowOfChildren = false)
 	{
-		$meta 			= $em->getClassMetadata( get_class( $entity ) );
-        $config 		= $this->listener->getConfiguration( $em, $meta->name );
-        $closureMeta 	= $em->getClassMetadata( $config[ 'closure' ] );
-		
-		$this->removeClosurePathsOfNodeID( $em, $closureMeta->getTableName(), $entity->getId(), $maintainSelfReferencingRow, $maintainSelfReferencingRowOfChildren );
+        $meta = $em->getClassMetadata(get_class($entity));
+        $config = $this->listener->getConfiguration($em, $meta->name);
+        $closureMeta = $em->getClassMetadata($config['closure']);
+        
+        $this->removeClosurePathsOfNodeID($em, $closureMeta->getTableName(), $entity->getId(), $maintainSelfReferencingRow, $maintainSelfReferencingRowOfChildren);
 	}
-	
-	public function removeClosurePathsOfNodeID( EntityManager $em, $table, $nodeId, $maintainSelfReferencingRow = true, $maintainSelfReferencingRowOfChildren = true )
+    
+	public function removeClosurePathsOfNodeID(EntityManager $em, $table, $nodeId, $maintainSelfReferencingRow = true, $maintainSelfReferencingRowOfChildren = true)
 	{
-		$subquery = "SELECT c1.id FROM {$table} c1 ";
-		$subquery .= "WHERE c1.descendant IN ( SELECT c2.descendant FROM {$table} c2 WHERE c2.ancestor = :id ) ";
-		$subquery .= "AND ( c1.ancestor IN ( SELECT c3.ancestor FROM {$table} c3 WHERE c3.descendant = :id ";
-
-		if ( $maintainSelfReferencingRow === true )
-		{
-			$subquery .= "AND c3.descendant != c3.ancestor ";
-		}
-		
-		if ( $maintainSelfReferencingRowOfChildren === false )
-		{
-			$subquery .= " OR c1.descendant = c1.ancestor ";
-		}
-		
-		$subquery .= " ) ) ";
+        $subquery = "SELECT c1.id FROM {$table} c1 ";
+        $subquery .= "WHERE c1.descendant IN ( SELECT c2.descendant FROM {$table} c2 WHERE c2.ancestor = :id ) ";
+        $subquery .= "AND ( c1.ancestor IN ( SELECT c3.ancestor FROM {$table} c3 WHERE c3.descendant = :id ";
+        
+		if ($maintainSelfReferencingRow === true)
+        {
+            $subquery .= "AND c3.descendant != c3.ancestor ";
+        }
+        
+        if ( $maintainSelfReferencingRowOfChildren === false )
+        {
+            $subquery .= " OR c1.descendant = c1.ancestor ";
+        }
+        
+        $subquery .= " ) ) ";
 		
-		$subquery = "DELETE FROM {$table} WHERE {$table}.id IN ( SELECT temp_table.id FROM ( {$subquery} ) temp_table )";
+        $subquery = "DELETE FROM {$table} WHERE {$table}.id IN ( SELECT temp_table.id FROM ( {$subquery} ) temp_table )";
 		
-		if (!$em->getConnection()->executeQuery($subquery, array('id' => $nodeId))) {
-			throw new \Gedmo\Exception\RuntimeException('Failed to delete old Closure records');
-		}
-	}
+        if (!$em->getConnection()->executeQuery($subquery, array('id' => $nodeId))) {
+            throw new \Gedmo\Exception\RuntimeException('Failed to delete old Closure records');
+        }
+    }
     
     private function extractIdentifier($em, $entity, $single = true)
     {

+ 22 - 22
tests/Gedmo/Tree/ClosureTreeRepositoryTest.php

@@ -49,7 +49,7 @@ class ClosureTreeRepositoryTest extends \PHPUnit_Framework_TestCase
         $evm->addEventSubscriber($treeListener);
         $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
         
-		$schema	= array(
+        $schema	= array(
             $this->em->getClassMetadata(self::TEST_BASE_CLOSURE_CLASS),
             $this->em->getClassMetadata(self::TEST_CLOSURE_CLASS),
             $this->em->getClassMetadata(self::TEST_ENTITY_CLASS),
@@ -62,28 +62,28 @@ class ClosureTreeRepositoryTest extends \PHPUnit_Framework_TestCase
             $this->em->getConnection()->getDatabasePlatform()
         );
         $config->setSQLLogger($this->analyzer);
-		
-		$this->populate();
+        
+        $this->populate();
     }
     
     public function test_childCount_returnsNumberOfChilds()
     {        
-        $repo 			= $this->em->getRepository( self::TEST_ENTITY_CLASS );
-        $food 			= $repo->findOneByTitle( 'Food' );
-		$closureRepo	= $this->em->getRepository( self::TEST_CLOSURE_CLASS );
-        $childCount 	= $closureRepo->childCount( $food );
-		
-		$this->assertEquals( $childCount, 4 );
+        $repo = $this->em->getRepository( self::TEST_ENTITY_CLASS );
+        $food = $repo->findOneByTitle( 'Food' );
+		$closureRepo = $this->em->getRepository( self::TEST_CLOSURE_CLASS );
+        $childCount = $closureRepo->childCount( $food );
+        
+        $this->assertEquals( $childCount, 4 );
     }
 	
-	public function test_childCount_returnsNumberOfDirectChilds()
+    public function test_childCount_returnsNumberOfDirectChilds()
     {        
-        $repo 			= $this->em->getRepository( self::TEST_ENTITY_CLASS );
-        $food 			= $repo->findOneByTitle( 'Food' );
-		$closureRepo	= $this->em->getRepository( self::TEST_CLOSURE_CLASS );
-        $childCount 	= $closureRepo->childCount( $food, true );
+        $repo = $this->em->getRepository(self::TEST_ENTITY_CLASS);
+        $food = $repo->findOneByTitle('Food');
+		$closureRepo = $this->em->getRepository(self::TEST_CLOSURE_CLASS);
+        $childCount = $closureRepo->childCount($food, true);
 		
-		$this->assertEquals( $childCount, 2 );
+		$this->assertEquals($childCount, 2);
     }
     
     
@@ -92,31 +92,31 @@ class ClosureTreeRepositoryTest extends \PHPUnit_Framework_TestCase
     {
         $root = new Category();
         $root->setTitle("Food");
-		$this->food = $root;
+        $this->food = $root;
         
         $root2 = new Category();
         $root2->setTitle("Sports");
-		$this->sports = $root2;
+        $this->sports = $root2;
         
         $child = new Category();
         $child->setTitle("Fruits");
         $child->setParent($root);
-		$this->fruits = $child;
+        $this->fruits = $child;
         
         $child2 = new Category();
         $child2->setTitle("Vegitables");
         $child2->setParent($root);
-		$this->vegitables = $child2;
+        $this->vegitables = $child2;
         
         $childsChild = new Category();
         $childsChild->setTitle("Carrots");
         $childsChild->setParent($child2);
-		$this->carrots = $childsChild;
+        $this->carrots = $childsChild;
         
         $potatoes = new Category();
         $potatoes->setTitle("Potatoes");
         $potatoes->setParent($child2);
-		$this->potatoes = $potatoes;
+        $this->potatoes = $potatoes;
         
         $this->em->persist($this->food);
         $this->em->persist($this->sports);
@@ -126,6 +126,6 @@ class ClosureTreeRepositoryTest extends \PHPUnit_Framework_TestCase
         $this->em->persist($this->potatoes);
 		
         $this->em->flush();
-		$this->em->clear();
+        $this->em->clear();
     }
 }

+ 174 - 174
tests/Gedmo/Tree/ClosureTreeTest.php

@@ -31,12 +31,12 @@ class ClosureTreeTest extends \PHPUnit_Framework_TestCase
      */
     private $analyzer;
 	
-	private $food;
-	private $sports;
-	private $fruits;
-	private $vegitables;
-	private $carrots;
-	private $potatoes;
+    private $food;
+    private $sports;
+    private $fruits;
+    private $vegitables;
+    private $carrots;
+    private $potatoes;
 
     public function setUp()
     {        
@@ -65,7 +65,7 @@ class ClosureTreeTest extends \PHPUnit_Framework_TestCase
         $evm->addEventSubscriber($treeListener);
         $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
         
-		$schema	= array(
+        $schema	= array(
             $this->em->getClassMetadata(self::TEST_BASE_CLOSURE_CLASS),
             $this->em->getClassMetadata(self::TEST_CLOSURE_CLASS),
             $this->em->getClassMetadata(self::TEST_ENTITY_CLASS),
@@ -79,211 +79,211 @@ class ClosureTreeTest extends \PHPUnit_Framework_TestCase
         );
         $config->setSQLLogger($this->analyzer);
 		
-		$this->populate();
+        $this->populate();
     }
     
     public function tearDown()
     {
         $this->analyzer->dumpResult();
-		$this->em->clear();
+        $this->em->clear();
     }
     
     public function test_insertNodes_verifyClosurePaths()
     {        
-		// We check the inserted nodes fields from the closure table
-		$repo 	= $this->em->getRepository(self::TEST_CLOSURE_CLASS);
+        // We check the inserted nodes fields from the closure table
+        $repo 	= $this->em->getRepository(self::TEST_CLOSURE_CLASS);
         $rows	= $this->em->createQuery( sprintf( 'SELECT c FROM %s c ORDER BY c.ancestor ASC, c.descendant ASC, c.depth ASC', self::TEST_CLOSURE_CLASS ) )
-			->getArrayResult();
+            ->getArrayResult();
 		
-		// Root self referencing row and descendants
-		$this->assertEquals( $rows[ 0 ][ 'ancestor' ], $this->food->getId() );
-		$this->assertEquals( $rows[ 0 ][ 'descendant' ], $this->food->getId() );
-		$this->assertEquals( $rows[ 0 ][ 'depth' ], 0 );
-		
-		$this->assertEquals( $rows[ 1 ][ 'ancestor' ], $this->food->getId() );
-		$this->assertEquals( $rows[ 1 ][ 'descendant' ], $this->fruits->getId() );
-		$this->assertEquals( $rows[ 1 ][ 'depth' ], 1 );
-		
-		$this->assertEquals( $rows[ 2 ][ 'ancestor' ], $this->food->getId() );
-		$this->assertEquals( $rows[ 2 ][ 'descendant' ], $this->vegitables->getId() );
-		$this->assertEquals( $rows[ 2 ][ 'depth' ], 1 );
-		
-		$this->assertEquals( $rows[ 3 ][ 'ancestor' ], $this->food->getId() );
-		$this->assertEquals( $rows[ 3 ][ 'descendant' ], $this->carrots->getId() );
-		$this->assertEquals( $rows[ 3 ][ 'depth' ], 2 );
-		
-		$this->assertEquals( $rows[ 4 ][ 'ancestor' ], $this->food->getId() );
-		$this->assertEquals( $rows[ 4 ][ 'descendant' ], $this->potatoes->getId() );
-		$this->assertEquals( $rows[ 4 ][ 'depth' ], 2 );
-		
-		// Sports self referencing row
-		$this->assertEquals( $rows[ 5 ][ 'ancestor' ], $this->sports->getId() );
-		$this->assertEquals( $rows[ 5 ][ 'descendant' ], $this->sports->getId() );
-		$this->assertEquals( $rows[ 5 ][ 'depth' ], 0 );
-		
-		// Fruits self referencing row
-		$this->assertEquals( $rows[ 6 ][ 'ancestor' ], $this->fruits->getId() );
-		$this->assertEquals( $rows[ 6 ][ 'descendant' ], $this->fruits->getId() );
-		$this->assertEquals( $rows[ 6 ][ 'depth' ], 0 );
-		
-		// Vegitables self referencing row and descendants
-		$this->assertEquals( $rows[ 7 ][ 'ancestor' ], $this->vegitables->getId() );
-		$this->assertEquals( $rows[ 7 ][ 'descendant' ], $this->vegitables->getId() );
-		$this->assertEquals( $rows[ 7 ][ 'depth' ], 0 );
-		
-		$this->assertEquals( $rows[ 8 ][ 'ancestor' ], $this->vegitables->getId() );
-		$this->assertEquals( $rows[ 8 ][ 'descendant' ], $this->carrots->getId() );
-		$this->assertEquals( $rows[ 8 ][ 'depth' ], 1 );
-		
-		$this->assertEquals( $rows[ 9 ][ 'ancestor' ], $this->vegitables->getId() );
-		$this->assertEquals( $rows[ 9 ][ 'descendant' ], $this->potatoes->getId() );
-		$this->assertEquals( $rows[ 9 ][ 'depth' ], 1 );
-		
-		// Carrots self referencing row
-		$this->assertEquals( $rows[ 10 ][ 'ancestor' ], $this->carrots->getId() );
-		$this->assertEquals( $rows[ 10 ][ 'descendant' ], $this->carrots->getId() );
-		$this->assertEquals( $rows[ 10 ][ 'depth' ], 0 );
+        // Root self referencing row and descendants
+        $this->assertEquals( $rows[ 0 ][ 'ancestor' ], $this->food->getId() );
+        $this->assertEquals( $rows[ 0 ][ 'descendant' ], $this->food->getId() );
+        $this->assertEquals( $rows[ 0 ][ 'depth' ], 0 );
+        
+        $this->assertEquals( $rows[ 1 ][ 'ancestor' ], $this->food->getId() );
+        $this->assertEquals( $rows[ 1 ][ 'descendant' ], $this->fruits->getId() );
+        $this->assertEquals( $rows[ 1 ][ 'depth' ], 1 );
+        
+        $this->assertEquals( $rows[ 2 ][ 'ancestor' ], $this->food->getId() );
+        $this->assertEquals( $rows[ 2 ][ 'descendant' ], $this->vegitables->getId() );
+        $this->assertEquals( $rows[ 2 ][ 'depth' ], 1 );
+        
+        $this->assertEquals( $rows[ 3 ][ 'ancestor' ], $this->food->getId() );
+        $this->assertEquals( $rows[ 3 ][ 'descendant' ], $this->carrots->getId() );
+        $this->assertEquals( $rows[ 3 ][ 'depth' ], 2 );
 		
-		// Potatoes self referencing row
-		$this->assertEquals( $rows[ 11 ][ 'ancestor' ], $this->potatoes->getId() );
-		$this->assertEquals( $rows[ 11 ][ 'descendant' ], $this->potatoes->getId() );
-		$this->assertEquals( $rows[ 11 ][ 'depth' ], 0 );
+        $this->assertEquals( $rows[ 4 ][ 'ancestor' ], $this->food->getId() );
+        $this->assertEquals( $rows[ 4 ][ 'descendant' ], $this->potatoes->getId() );
+        $this->assertEquals( $rows[ 4 ][ 'depth' ], 2 );
+        
+        // Sports self referencing row
+        $this->assertEquals( $rows[ 5 ][ 'ancestor' ], $this->sports->getId() );
+        $this->assertEquals( $rows[ 5 ][ 'descendant' ], $this->sports->getId() );
+        $this->assertEquals( $rows[ 5 ][ 'depth' ], 0 );
+        
+        // Fruits self referencing row
+        $this->assertEquals( $rows[ 6 ][ 'ancestor' ], $this->fruits->getId() );
+        $this->assertEquals( $rows[ 6 ][ 'descendant' ], $this->fruits->getId() );
+        $this->assertEquals( $rows[ 6 ][ 'depth' ], 0 );
+        
+        // Vegitables self referencing row and descendants
+        $this->assertEquals( $rows[ 7 ][ 'ancestor' ], $this->vegitables->getId() );
+        $this->assertEquals( $rows[ 7 ][ 'descendant' ], $this->vegitables->getId() );
+        $this->assertEquals( $rows[ 7 ][ 'depth' ], 0 );
+        
+        $this->assertEquals( $rows[ 8 ][ 'ancestor' ], $this->vegitables->getId() );
+        $this->assertEquals( $rows[ 8 ][ 'descendant' ], $this->carrots->getId() );
+        $this->assertEquals( $rows[ 8 ][ 'depth' ], 1 );
+        
+        $this->assertEquals( $rows[ 9 ][ 'ancestor' ], $this->vegitables->getId() );
+        $this->assertEquals( $rows[ 9 ][ 'descendant' ], $this->potatoes->getId() );
+        $this->assertEquals( $rows[ 9 ][ 'depth' ], 1 );
+        
+        // Carrots self referencing row
+        $this->assertEquals( $rows[ 10 ][ 'ancestor' ], $this->carrots->getId() );
+        $this->assertEquals( $rows[ 10 ][ 'descendant' ], $this->carrots->getId() );
+        $this->assertEquals( $rows[ 10 ][ 'depth' ], 0 );
+        
+        // Potatoes self referencing row
+        $this->assertEquals( $rows[ 11 ][ 'ancestor' ], $this->potatoes->getId() );
+        $this->assertEquals( $rows[ 11 ][ 'descendant' ], $this->potatoes->getId() );
+        $this->assertEquals( $rows[ 11 ][ 'depth' ], 0 );
     }
 	
-	public function test_updateNodes_moveASubtreeAndVerifyTreeClosurePaths()
+    public function test_updateNodes_moveASubtreeAndVerifyTreeClosurePaths()
     {
-		// We change a subtree's location
-		$vegitables = $this->em->getRepository( self::TEST_ENTITY_CLASS )
-			->findOneByTitle( 'Vegitables' );
-		$sports = $this->em->getRepository( self::TEST_ENTITY_CLASS )
-			->findOneByTitle( 'Sports' );
-		$vegitables->setParent( $sports );
-		
-		$this->em->persist( $vegitables );
-		$this->em->flush();
-		
-		// We then verify the closure paths
-		$repo 	= $this->em->getRepository(self::TEST_CLOSURE_CLASS);
-        $rows	= $this->em->createQuery( sprintf( 'SELECT c FROM %s c ORDER BY c.ancestor ASC, c.descendant ASC, c.depth ASC', self::TEST_CLOSURE_CLASS ) )
-			->getArrayResult();
-		
-		// Food self referencing row and descendants
-		$this->assertEquals( $rows[ 0 ][ 'ancestor' ], $this->food->getId() );
-		$this->assertEquals( $rows[ 0 ][ 'descendant' ], $this->food->getId() );
-		$this->assertEquals( $rows[ 0 ][ 'depth' ], 0 );
-		
-		$this->assertEquals( $rows[ 1 ][ 'ancestor' ], $this->food->getId() );
-		$this->assertEquals( $rows[ 1 ][ 'descendant' ], $this->fruits->getId() );
-		$this->assertEquals( $rows[ 1 ][ 'depth' ], 1 );
-		
-		// Sports self referencing row and descendants
-		$this->assertEquals( $rows[ 2 ][ 'ancestor' ], $this->sports->getId() );
-		$this->assertEquals( $rows[ 2 ][ 'descendant' ], $this->sports->getId() );
-		$this->assertEquals( $rows[ 2 ][ 'depth' ], 0 );
-		
-		$this->assertEquals( $rows[ 3 ][ 'ancestor' ], $this->sports->getId() );
-		$this->assertEquals( $rows[ 3 ][ 'descendant' ], $this->vegitables->getId() );
-		$this->assertEquals( $rows[ 3 ][ 'depth' ], 1 );
-		
-		$this->assertEquals( $rows[ 4 ][ 'ancestor' ], $this->sports->getId() );
-		$this->assertEquals( $rows[ 4 ][ 'descendant' ], $this->carrots->getId() );
-		$this->assertEquals( $rows[ 4 ][ 'depth' ], 2 );
-		
-		$this->assertEquals( $rows[ 5 ][ 'ancestor' ], $this->sports->getId() );
-		$this->assertEquals( $rows[ 5 ][ 'descendant' ], $this->potatoes->getId() );
-		$this->assertEquals( $rows[ 5 ][ 'depth' ], 2 );
-		
-		// Fruits self referencing row
-		$this->assertEquals( $rows[ 6 ][ 'ancestor' ], $this->fruits->getId() );
-		$this->assertEquals( $rows[ 6 ][ 'descendant' ], $this->fruits->getId() );
-		$this->assertEquals( $rows[ 6 ][ 'depth' ], 0 );
-		
-		// Vegitables self referencing row and descendants
-		$this->assertEquals( $rows[ 7 ][ 'ancestor' ], $this->vegitables->getId() );
-		$this->assertEquals( $rows[ 7 ][ 'descendant' ], $this->vegitables->getId() );
-		$this->assertEquals( $rows[ 7 ][ 'depth' ], 0 );
-		
-		$this->assertEquals( $rows[ 8 ][ 'ancestor' ], $this->vegitables->getId() );
-		$this->assertEquals( $rows[ 8 ][ 'descendant' ], $this->carrots->getId() );
-		$this->assertEquals( $rows[ 8 ][ 'depth' ], 1 );
-		
-		$this->assertEquals( $rows[ 9 ][ 'ancestor' ], $this->vegitables->getId() );
-		$this->assertEquals( $rows[ 9 ][ 'descendant' ], $this->potatoes->getId() );
-		$this->assertEquals( $rows[ 9 ][ 'depth' ], 1 );
-		
-		// Carrots self referencing row
-		$this->assertEquals( $rows[ 10 ][ 'ancestor' ], $this->carrots->getId() );
-		$this->assertEquals( $rows[ 10 ][ 'descendant' ], $this->carrots->getId() );
-		$this->assertEquals( $rows[ 10 ][ 'depth' ], 0 );
-		
-		// Potatoes self referencing row
-		$this->assertEquals( $rows[ 11 ][ 'ancestor' ], $this->potatoes->getId() );
-		$this->assertEquals( $rows[ 11 ][ 'descendant' ], $this->potatoes->getId() );
-		$this->assertEquals( $rows[ 11 ][ 'depth' ], 0 );
-	}
-	
-	public function test_removeNode_removesClosurePathsOfNodeAndVerifyTree()
-	{
-		// We remove a subtree
-		$vegitables = $this->em->getRepository( self::TEST_ENTITY_CLASS )
-			->findOneByTitle( 'Vegitables' );
-		$this->em->remove( $vegitables );
-		$this->em->flush();
-		
-		// We then verify the closure paths
-		$repo 	= $this->em->getRepository(self::TEST_CLOSURE_CLASS);
+        // We change a subtree's location
+        $vegitables = $this->em->getRepository( self::TEST_ENTITY_CLASS )
+            ->findOneByTitle( 'Vegitables' );
+        $sports = $this->em->getRepository( self::TEST_ENTITY_CLASS )
+            ->findOneByTitle( 'Sports' );
+        $vegitables->setParent( $sports );
+        
+        $this->em->persist( $vegitables );
+        $this->em->flush();
+        
+        // We then verify the closure paths
+        $repo = $this->em->getRepository(self::TEST_CLOSURE_CLASS);
+        $rows = $this->em->createQuery( sprintf( 'SELECT c FROM %s c ORDER BY c.ancestor ASC, c.descendant ASC, c.depth ASC', self::TEST_CLOSURE_CLASS ) )
+            ->getArrayResult();
+        
+        // Food self referencing row and descendants
+        $this->assertEquals( $rows[ 0 ][ 'ancestor' ], $this->food->getId() );
+        $this->assertEquals( $rows[ 0 ][ 'descendant' ], $this->food->getId() );
+        $this->assertEquals( $rows[ 0 ][ 'depth' ], 0 );
+        
+        $this->assertEquals( $rows[ 1 ][ 'ancestor' ], $this->food->getId() );
+        $this->assertEquals( $rows[ 1 ][ 'descendant' ], $this->fruits->getId() );
+        $this->assertEquals( $rows[ 1 ][ 'depth' ], 1 );
+        
+        // Sports self referencing row and descendants
+        $this->assertEquals( $rows[ 2 ][ 'ancestor' ], $this->sports->getId() );
+        $this->assertEquals( $rows[ 2 ][ 'descendant' ], $this->sports->getId() );
+        $this->assertEquals( $rows[ 2 ][ 'depth' ], 0 );
+        
+        $this->assertEquals( $rows[ 3 ][ 'ancestor' ], $this->sports->getId() );
+        $this->assertEquals( $rows[ 3 ][ 'descendant' ], $this->vegitables->getId() );
+        $this->assertEquals( $rows[ 3 ][ 'depth' ], 1 );
+        
+        $this->assertEquals( $rows[ 4 ][ 'ancestor' ], $this->sports->getId() );
+        $this->assertEquals( $rows[ 4 ][ 'descendant' ], $this->carrots->getId() );
+        $this->assertEquals( $rows[ 4 ][ 'depth' ], 2 );
+        
+        $this->assertEquals( $rows[ 5 ][ 'ancestor' ], $this->sports->getId() );
+        $this->assertEquals( $rows[ 5 ][ 'descendant' ], $this->potatoes->getId() );
+        $this->assertEquals( $rows[ 5 ][ 'depth' ], 2 );
+        
+        // Fruits self referencing row
+        $this->assertEquals( $rows[ 6 ][ 'ancestor' ], $this->fruits->getId() );
+        $this->assertEquals( $rows[ 6 ][ 'descendant' ], $this->fruits->getId() );
+        $this->assertEquals( $rows[ 6 ][ 'depth' ], 0 );
+        
+        // Vegitables self referencing row and descendants
+        $this->assertEquals( $rows[ 7 ][ 'ancestor' ], $this->vegitables->getId() );
+        $this->assertEquals( $rows[ 7 ][ 'descendant' ], $this->vegitables->getId() );
+        $this->assertEquals( $rows[ 7 ][ 'depth' ], 0 );
+        
+        $this->assertEquals( $rows[ 8 ][ 'ancestor' ], $this->vegitables->getId() );
+        $this->assertEquals( $rows[ 8 ][ 'descendant' ], $this->carrots->getId() );
+        $this->assertEquals( $rows[ 8 ][ 'depth' ], 1 );
+        
+        $this->assertEquals( $rows[ 9 ][ 'ancestor' ], $this->vegitables->getId() );
+        $this->assertEquals( $rows[ 9 ][ 'descendant' ], $this->potatoes->getId() );
+        $this->assertEquals( $rows[ 9 ][ 'depth' ], 1 );
+        
+        // Carrots self referencing row
+        $this->assertEquals( $rows[ 10 ][ 'ancestor' ], $this->carrots->getId() );
+        $this->assertEquals( $rows[ 10 ][ 'descendant' ], $this->carrots->getId() );
+        $this->assertEquals( $rows[ 10 ][ 'depth' ], 0 );
+        
+        // Potatoes self referencing row
+        $this->assertEquals( $rows[ 11 ][ 'ancestor' ], $this->potatoes->getId() );
+        $this->assertEquals( $rows[ 11 ][ 'descendant' ], $this->potatoes->getId() );
+        $this->assertEquals( $rows[ 11 ][ 'depth' ], 0 );
+    }
+    
+    public function test_removeNode_removesClosurePathsOfNodeAndVerifyTree()
+    {
+        // We remove a subtree
+        $vegitables = $this->em->getRepository( self::TEST_ENTITY_CLASS )
+            ->findOneByTitle( 'Vegitables' );
+        $this->em->remove( $vegitables );
+        $this->em->flush();
+        
+        // We then verify the closure paths
+        $repo = $this->em->getRepository(self::TEST_CLOSURE_CLASS);
         $rows	= $this->em->createQuery( sprintf( 'SELECT c FROM %s c ORDER BY c.ancestor ASC, c.descendant ASC, c.depth ASC', self::TEST_CLOSURE_CLASS ) )
-			->getArrayResult();
-		
-		// Food self referencing row and descendants
-		$this->assertEquals( $rows[ 0 ][ 'ancestor' ], $this->food->getId() );
-		$this->assertEquals( $rows[ 0 ][ 'descendant' ], $this->food->getId() );
-		$this->assertEquals( $rows[ 0 ][ 'depth' ], 0 );
-		
-		$this->assertEquals( $rows[ 1 ][ 'ancestor' ], $this->food->getId() );
-		$this->assertEquals( $rows[ 1 ][ 'descendant' ], $this->fruits->getId() );
-		$this->assertEquals( $rows[ 1 ][ 'depth' ], 1 );
-		
-		// Sports self referencing row
-		$this->assertEquals( $rows[ 2 ][ 'ancestor' ], $this->sports->getId() );
-		$this->assertEquals( $rows[ 2 ][ 'descendant' ], $this->sports->getId() );
-		$this->assertEquals( $rows[ 2 ][ 'depth' ], 0 );
-		
-		// Fruits self referencing row
-		$this->assertEquals( $rows[ 3 ][ 'ancestor' ], $this->fruits->getId() );
-		$this->assertEquals( $rows[ 3 ][ 'descendant' ], $this->fruits->getId() );
-		$this->assertEquals( $rows[ 3 ][ 'depth' ], 0 );
-	}
+            ->getArrayResult();
+        
+        // Food self referencing row and descendants
+        $this->assertEquals( $rows[ 0 ][ 'ancestor' ], $this->food->getId() );
+        $this->assertEquals( $rows[ 0 ][ 'descendant' ], $this->food->getId() );
+        $this->assertEquals( $rows[ 0 ][ 'depth' ], 0 );
+        
+        $this->assertEquals( $rows[ 1 ][ 'ancestor' ], $this->food->getId() );
+        $this->assertEquals( $rows[ 1 ][ 'descendant' ], $this->fruits->getId() );
+        $this->assertEquals( $rows[ 1 ][ 'depth' ], 1 );
+        
+        // Sports self referencing row
+        $this->assertEquals( $rows[ 2 ][ 'ancestor' ], $this->sports->getId() );
+        $this->assertEquals( $rows[ 2 ][ 'descendant' ], $this->sports->getId() );
+        $this->assertEquals( $rows[ 2 ][ 'depth' ], 0 );
+        
+        // Fruits self referencing row
+        $this->assertEquals( $rows[ 3 ][ 'ancestor' ], $this->fruits->getId() );
+        $this->assertEquals( $rows[ 3 ][ 'descendant' ], $this->fruits->getId() );
+        $this->assertEquals( $rows[ 3 ][ 'depth' ], 0 );
+    }
     
     private function populate()
     {
         $root = new Category();
         $root->setTitle("Food");
-		$this->food = $root;
+        $this->food = $root;
         
         $root2 = new Category();
         $root2->setTitle("Sports");
-		$this->sports = $root2;
+        $this->sports = $root2;
         
         $child = new Category();
         $child->setTitle("Fruits");
         $child->setParent($root);
-		$this->fruits = $child;
+        $this->fruits = $child;
         
         $child2 = new Category();
         $child2->setTitle("Vegitables");
         $child2->setParent($root);
-		$this->vegitables = $child2;
+        $this->vegitables = $child2;
         
         $childsChild = new Category();
         $childsChild->setTitle("Carrots");
         $childsChild->setParent($child2);
-		$this->carrots = $childsChild;
+        $this->carrots = $childsChild;
         
         $potatoes = new Category();
         $potatoes->setTitle("Potatoes");
         $potatoes->setParent($child2);
-		$this->potatoes = $potatoes;
+        $this->potatoes = $potatoes;
         
         $this->em->persist($this->food);
         $this->em->persist($this->sports);
@@ -291,8 +291,8 @@ class ClosureTreeTest extends \PHPUnit_Framework_TestCase
         $this->em->persist($this->vegitables);
         $this->em->persist($this->carrots);
         $this->em->persist($this->potatoes);
-		
+        
         $this->em->flush();
-		$this->em->clear();
+        $this->em->clear();
     }
 }