diff --git a/lib/functions.php b/lib/functions.php index c971b46..874ed08 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -19,13 +19,13 @@ function task() { function group($name, $lambda = null) { $thrown = null; - builder()->push_group($name); + $levels = builder()->push_group($name); try { if ($lambda instanceof Closure) $lambda(); } catch (\Exception $e) { $thrown = $e; } - builder()->pop_group(); + builder()->pop_group($levels); if ($thrown) { throw $e; } diff --git a/lib/phake/Builder.php b/lib/phake/Builder.php index ab37d50..e242b33 100644 --- a/lib/phake/Builder.php +++ b/lib/phake/Builder.php @@ -53,11 +53,15 @@ public function add_task($name, $work, $deps) { } public function push_group($name) { - $this->target_node = $this->target_node->child_with_name($name); + $levels = 0; + $this->target_node = $this->target_node->child_with_name($name, $levels); + return $levels; } - public function pop_group() { - $this->target_node = $this->target_node->get_parent(); + public function pop_group($levels = 1) { + for ($i = 0; $i < $levels; $i++) { + $this->target_node = $this->target_node->get_parent(); + } } public function before($name, $lambda) { diff --git a/lib/phake/Node.php b/lib/phake/Node.php index 6e97d29..3eab0ed 100644 --- a/lib/phake/Node.php +++ b/lib/phake/Node.php @@ -49,7 +49,7 @@ public function get_root() { return $root; } - public function child_with_name($task_name) { + public function child_with_name($task_name, &$levels = 0) { $parts = explode(':', $task_name); $task = $this; @@ -60,6 +60,8 @@ public function child_with_name($task_name) { $task = $task->children[$part]; } + $levels = sizeof($parts); + return $task; } @@ -132,7 +134,7 @@ public function has_body() { public function get_task($task_name) { if ($task_name[0] != ':') { - + $parts = explode(':', $task_name); $task = $this; diff --git a/tests/BuilderTest.php b/tests/BuilderTest.php index 57e378a..7cda966 100644 --- a/tests/BuilderTest.php +++ b/tests/BuilderTest.php @@ -76,6 +76,7 @@ public function testGroups() $this->expectOutputString(<<