Skip to content
Open
Prev Previous commit
Next Next commit
fix: remove intermediate variables not needed anymore
  • Loading branch information
shakaran committed Dec 9, 2025
commit b70d44a675af4882da322d476cdeb3f28a6307f1
88 changes: 32 additions & 56 deletions tests/Knp/Menu/Tests/MenuItemTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,20 @@ public function testIsFirst(): void

public function testActsLikeFirst(): void
{
$ch1 = $this->ch1;
$ch2 = $this->ch2;
$ch3 = $this->ch3;
$ch4 = $this->ch4;
$menu = $this->menu;
$ch1->setDisplay(false);
$this->assertFalse($menu->actsLikeFirst(), 'The root item is not considered as first');
$this->assertFalse($ch1->actsLikeFirst(), 'A hidden item does not acts like first');
$this->assertTrue($ch2->actsLikeFirst());
$this->assertFalse($ch3->actsLikeFirst());
$this->assertTrue($ch4->actsLikeFirst());
$this->ch1->setDisplay(false);
$this->assertFalse($this->menu->actsLikeFirst(), 'The root item is not considered as first');
$this->assertFalse($this->ch1->actsLikeFirst(), 'A hidden item does not acts like first');
$this->assertTrue($this->ch2->actsLikeFirst());
$this->assertFalse($this->ch3->actsLikeFirst());
$this->assertTrue($this->ch4->actsLikeFirst());
}

public function testActsLikeFirstWithNoDisplayedItem(): void
{
$pt1 = $this->pt1;
$pt2 = $this->pt2;
$pt1->setDisplay(false);
$pt2->setDisplay(false);
$this->assertFalse($pt1->actsLikeFirst());
$this->assertFalse($pt2->actsLikeFirst());
$this->pt1->setDisplay(false);
$this->pt2->setDisplay(false);
$this->assertFalse($this->pt1->actsLikeFirst());
$this->assertFalse($this->pt2->actsLikeFirst());
}

public function testIsLast(): void
Expand All @@ -139,27 +132,20 @@ public function testIsLast(): void

public function testActsLikeLast(): void
{
$ch3 = $this->ch3;
$menu = $this->menu;
$ch1 = $this->ch1;
$ch2 = $this->ch2;
$ch4 = $this->ch4;
$ch3->setDisplay(false);
$this->assertFalse($menu->actsLikeLast(), 'The root item is not considered as last');
$this->assertFalse($ch1->actsLikeLast());
$this->assertTrue($ch2->actsLikeLast());
$this->assertFalse($ch3->actsLikeLast(), 'A hidden item does not acts like last');
$this->assertTrue($ch4->actsLikeLast());
$this->ch3->setDisplay(false);
$this->assertFalse($this->menu->actsLikeLast(), 'The root item is not considered as last');
$this->assertFalse($this->ch1->actsLikeLast());
$this->assertTrue($this->ch2->actsLikeLast());
$this->assertFalse($this->ch3->actsLikeLast(), 'A hidden item does not acts like last');
$this->assertTrue($this->ch4->actsLikeLast());
}

public function testActsLikeLastWithNoDisplayedItem(): void
{
$pt1 = $this->pt1;
$pt2 = $this->pt2;
$pt1->setDisplay(false);
$pt2->setDisplay(false);
$this->assertFalse($pt1->actsLikeLast());
$this->assertFalse($pt2->actsLikeLast());
$this->pt1->setDisplay(false);
$this->pt2->setDisplay(false);
$this->assertFalse($this->pt1->actsLikeLast());
$this->assertFalse($this->pt2->actsLikeLast());
}

public function testArrayAccess(): void
Expand Down Expand Up @@ -196,11 +182,9 @@ public function testCountable(): void

public function testGetChildren(): void
{
$ch4 = $this->ch4;
$gc1 = $this->gc1;
$children = $ch4->getChildren();
$children = $this->ch4->getChildren();
$this->assertCount(1, $children);
$this->assertEquals($gc1->getName(), $children['Grandchild 1']->getName());
$this->assertEquals($this->gc1->getName(), $children['Grandchild 1']->getName());
}

public function testGetFirstChild(): void
Expand Down Expand Up @@ -249,23 +233,20 @@ public function testAddChildFailsIfInAnotherMenu(): void

public function testGetChild(): void
{
$gc1 = $this->gc1;
$ch4 = $this->ch4;
$this->assertSame($gc1, $ch4->getChild('Grandchild 1'));
$this->assertNull($ch4->getChild('nonexistentchild'));
$this->assertSame($this->gc1, $this->ch4->getChild('Grandchild 1'));
$this->assertNull($this->ch4->getChild('nonexistentchild'));
}

public function testRemoveChild(): void
{
$ch4 = $this->ch4;
$gc1 = $this->gc1;
$gc2 = $ch4->addChild('gc2');
$ch4->addChild('gc2');
$gc3 = $ch4->addChild('gc3');
$gc4 = $ch4->addChild('gc4');
$ch4->addChild('gc4');
$this->assertCount(4, $ch4);
$ch4->removeChild('gc4');
$this->assertCount(3, $ch4);
$this->assertTrue($gc1->isFirst());
$this->assertTrue($this->gc1->isFirst());
$this->assertTrue($gc3->isLast());
}

Expand All @@ -280,13 +261,12 @@ public function testReAddRemovedChild(): void
{
$ch4 = $this->ch4;
$menu = $this->menu;
$pt2 = $this->pt2;
$gc2 = $ch4->addChild('gc2');
$ch4->removeChild('gc2');
$menu->addChild($gc2);
$this->assertCount(3, $menu);
$this->assertTrue($gc2->isLast());
$this->assertFalse($pt2->isLast());
$this->assertFalse($this->pt2->isLast());
}

public function testUpdateChildAfterRename(): void
Expand All @@ -303,22 +283,18 @@ public function testRenameToExistingSiblingNameThrowAnException(): void
{
$this->expectException(\InvalidArgumentException::class);

$pt1 = $this->pt1;
$pt1->setName('Parent 2');
$this->pt1->setName('Parent 2');
}

public function testGetUri(): void
{
$this->addChildWithExternalUrl();
$pt1 = $this->pt1;
$menu = $this->menu;
$this->assertNull($pt1->getUri());
$this->assertEquals('http://www.symfony-reloaded.org', $menu->getChildren()['child']->getUri());
$this->assertNull($this->pt1->getUri());
$this->assertEquals('http://www.symfony-reloaded.org', $this->menu->getChildren()['child']->getUri());
}

protected function addChildWithExternalUrl(): void
{
$menu = $this->menu;
$menu->addChild('child', ['uri' => 'http://www.symfony-reloaded.org']);
$this->menu->addChild('child', ['uri' => 'http://www.symfony-reloaded.org']);
}
}