Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent naming for task bodies #34

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/phake/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions lib/phake/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -63,9 +63,9 @@ public function child_with_name($task_name) {
return $task;
}

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;
Expand All @@ -92,9 +92,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;
}
Expand All @@ -111,11 +111,11 @@ public function get_dependencies() {
}

public function has_dependencies() {
return !!$this->dependencies();
return !!$this->deps;
}

public function has_body() {
return !!$this->tasks;
return !!$this->bodies;
}

public function get_task($task_name) {
Expand Down
25 changes: 25 additions & 0 deletions tests/NodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -73,6 +76,28 @@ public function testSecondLevelNode(Node $root, Node $first)
$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());
}

public function testGroupedNodes()
{
$root = new Node();
Expand Down