| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Alpixel\Bundle\MenuBundle\Tests\Entity; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Alpixel\Bundle\MenuBundle\Entity\Item; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Alpixel\Bundle\MenuBundle\Entity\Menu; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Doctrine\Common\Collections\ArrayCollection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | class ItemTest extends \PHPUnit_Framework_TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | { | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 11 |  | View Code Duplication |     public function testToString() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |         $item = $this->getItemInstance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         $this->assertNull($item->__toString()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         $test = 'Menu principal'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         $item->setName($test); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         $this->assertEquals($test, $item->__toString()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 21 |  | View Code Duplication |     public function testName() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         $item = $this->getItemInstance(); | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |         $this->assertNull($item->getName()); | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |         $test = 'Menu principal'; | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |         $item->setName($test); | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         $this->assertEquals($test, $item->getName()); | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     public function testUri() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $item = $this->getItemInstance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $this->assertNull($item->getUri()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $test = 'http://www.unicorn.fr'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $item->setUri($test); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $this->assertEquals($test, $item->getUri()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     public function testSetPosition() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $item = $this->getItemInstance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $this->assertNull($item->getPosition()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $test = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $item->setPosition($test); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->assertEquals($test, $item->getPosition()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     public function testMenu() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $item = $this->getItemInstance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $this->assertNull($item->getMenu()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $item->setMenu($this->getMenuInstance()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $this->assertInstanceOf(Menu::class, $item->getMenu()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     public function testParent() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $item = $this->getItemInstance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $this->assertNull($item->getParent()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $item->setParent($this->getItemInstance()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $this->assertInstanceOf(Item::class, $item->getParent()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 69 |  | View Code Duplication |     public function testChildren() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $item = $this->getItemInstance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $this->assertInstanceOf(ArrayCollection::class, $item->getChildren()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $this->assertCount(0, $item->getchildren()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $item->setChildren($this->getItemInstance()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $this->assertInstanceOf(ArrayCollection::class, $item->getChildren()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $this->assertCount(1, $item->getChildren()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $this->assertCount(1, $item->getChildren()->toArray()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $this->assertInstanceOf(Item::class, $item->getChildren()->first()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $item->removeChildren($item->getChildren()->first()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $this->assertCount(0, $item->getChildren()->toArray()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $collection = new ArrayCollection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $collection->add($this->getItemInstance()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $collection->add($this->getItemInstance()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $item->addChildren($collection); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $this->assertCount(2, $item->getChildren()->toArray()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     public function getItemInstance() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         return new Item(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     public function getMenuInstance() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         return new Menu(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 101 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 102 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.