From 22c0357e228ff48b494faa7a06a4b4968e269c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 20 Dec 2013 12:02:42 +0100 Subject: [PATCH 1/3] Consistent naming for task bodies --- lib/phake/Builder.php | 2 +- lib/phake/Node.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/phake/Builder.php b/lib/phake/Builder.php index 81e1c1f..be82939 100644 --- a/lib/phake/Builder.php +++ b/lib/phake/Builder.php @@ -37,7 +37,7 @@ public function add_task($name, $work, $deps) { /* @var $node phake\Node */ if ($work !== null) { - $node->add_lambda($work); + $node->add_body($work); } foreach ($deps as $dep) { $node->add_dependency($dep); diff --git a/lib/phake/Node.php b/lib/phake/Node.php index 38064d1..7456a87 100644 --- a/lib/phake/Node.php +++ b/lib/phake/Node.php @@ -13,7 +13,7 @@ class Node private $has_run = false; private $before = array(); - private $lambdas = array(); + private $bodies = array(); private $after = array(); private $children = array(); @@ -56,9 +56,9 @@ public function child_with_name($name) { return $this->children[$name]; } - public function add_before($closure) { $this->before[] = $closure; } - public function add_lambda($closure) { $this->lambdas[] = $closure; } - public function add_after($closure) { $this->after[] = $closure; } + public function add_before($closure) { $this->before[] = $closure; } + public function add_body($closure) { $this->bodies[] = $closure; } + public function add_after($closure) { $this->after[] = $closure; } public function get_description() { return $this->desc; @@ -85,9 +85,9 @@ public function invoke(Application $application) { return; } - foreach ($this->before as $t) $t($application); - foreach ($this->lambdas as $t) $t($application); - foreach ($this->after as $t) $t($application); + foreach ($this->before as $t) $t($application); + foreach ($this->bodies as $t) $t($application); + foreach ($this->after as $t) $t($application); $this->has_run = true; } @@ -108,7 +108,7 @@ public function has_dependencies() { } public function has_body() { - return !!$this->tasks; + return !!$this->bodies; } public function get_task($task_name) { From 6c5ae2c681ba868260e43b475535362f441c49d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sat, 21 Dec 2013 00:58:38 +0100 Subject: [PATCH 2/3] Fix checking for dependencies --- lib/phake/Node.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/phake/Node.php b/lib/phake/Node.php index 7456a87..0b9915d 100644 --- a/lib/phake/Node.php +++ b/lib/phake/Node.php @@ -104,7 +104,7 @@ public function get_dependencies() { } public function has_dependencies() { - return !!$this->dependencies(); + return !!$this->deps; } public function has_body() { From f44552f772ce275849a9987eacd6ea69d32d10de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sat, 21 Dec 2013 00:59:24 +0100 Subject: [PATCH 3/3] Test node visibility --- tests/NodeTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/NodeTest.php b/tests/NodeTest.php index b3ee4d7..24f6482 100644 --- a/tests/NodeTest.php +++ b/tests/NodeTest.php @@ -14,6 +14,9 @@ public function testRootNode() $this->assertEquals(null, $root->get_parent()); $this->assertEquals($root, $root->get_root()); $this->assertEquals(array(), $root->get_dependencies()); + $this->assertFalse($root->has_body()); + $this->assertFalse($root->is_visible()); + return $root; } @@ -72,4 +75,26 @@ public function testSecondLevelNode(Node $root, Node $first) $this->assertSame($second, $root->get_task('first:second')); $this->assertSame($second, $first->get_task(':first:second')); } + + public function testNodeBecomesVisibleWhenItGetsBody() + { + $node = new Node(); + $this->assertFalse($node->has_body()); + $this->assertFalse($node->is_visible()); + + $node->add_body(function() { }); + $this->assertTrue($node->has_body()); + $this->assertTrue($node->is_visible()); + } + + public function testNodeBecomesVisibleWhenItGetsDependencies() + { + $node = new Node(); + $this->assertFalse($node->has_dependencies()); + $this->assertFalse($node->is_visible()); + + $node->add_dependency('does not matter'); + $this->assertTrue($node->has_dependencies()); + $this->assertTrue($node->is_visible()); + } }