diff --git a/src/CliMenuBuilder.php b/src/CliMenuBuilder.php index a5dac795..4f25fca6 100644 --- a/src/CliMenuBuilder.php +++ b/src/CliMenuBuilder.php @@ -468,7 +468,7 @@ public function end() /** * @param string $id - * @return CliMenuBuilder + * @return CliMenu * @throws RuntimeException */ public function getSubMenu($id) diff --git a/test/CliMenuBuilderTest.php b/test/CliMenuBuilderTest.php index 28f1f282..b49d1c2f 100644 --- a/test/CliMenuBuilderTest.php +++ b/test/CliMenuBuilderTest.php @@ -278,6 +278,34 @@ public function testAddSubMenu() $this->assertSame($builder, $subMenuBuilder->end()); } + public function testSubMenuInheritsParentsStyle() + { + $builder = new CliMenuBuilder; + $menu = $builder->setBackgroundColour('green') + ->addSubMenu('sub-menu') + ->addItem('Some Item', function () { + }) + ->end() + ->build(); + + $this->assertSame('green', $builder->getSubMenu('sub-menu')->getStyle()->getBg()); + } + + public function testSubMenuDoesNotInheritsParentsStyleWhenSubMenuStyleHasAlterations() + { + $builder = new CliMenuBuilder; + $menu = $builder->setBackgroundColour('green') + ->addSubMenu('sub-menu') + ->addItem('Some Item', function () { + }) + ->setBackgroundColour('red') + ->end() + ->build(); + + $this->assertSame('red', $builder->getSubMenu('sub-menu')->getStyle()->getBg()); + $this->assertSame('green', $menu->getStyle()->getBg()); + } + public function testGetSubMenuThrowsExceptionIfNotBuiltYet() { $builder = (new CliMenuBuilder)