Skip to content
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
13 changes: 7 additions & 6 deletions lib/phake/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,21 @@ private function assign_description($thing) {
}

public function resolve_runfile($directory) {
$directory = rtrim($directory, '/') . '/';
$directory = rtrim($directory, '/');
$runfiles = array('Phakefile', 'Phakefile.php');

do {
foreach ($runfiles as $r) {
$candidate = $directory . $r;
$candidate = $directory . '/' . $r;
if (file_exists($candidate)) {
return $candidate;
}
}
if ($directory == '/') {
throw new \Exception("No Phakefile found");
}
$previous = $directory;
$directory = dirname($directory);
} while (true);
} while ($directory !== $previous);

throw new \Exception("No Phakefile found");
}

public function load_runfile($file) {
Expand Down
57 changes: 57 additions & 0 deletions tests/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,63 @@ public function testInvalidPath()
$builder->load_runfile('does not exist');
}

/**
* @dataProvider provideResolveRunfile
*/
public function testResolveRunfile($search, $expected)
{
$builder = new Builder();

$this->assertEquals($expected, $builder->resolve_runfile($search));
}

public function provideResolveRunfile()
{
$root = __DIR__ . '/..';

return array(
array(
$root,
$root . '/Phakefile'
),
array(
$root . '/bin',
$root . '/Phakefile'
),
array(
$root . '/example',
$root . '/example/Phakefile'
),
array(
$root . '/lib/phake',
$root . '/Phakefile'
)
);
}

/**
* @expectedException Exception
* @dataProvider provideResolveRunfileNonExistant
*/
public function testResolveRunfileNonExistant($path)
{
$builder = new Builder();

$builder->resolve_runfile($path);
}

public function provideResolveRunfileNonExistant()
{
return array(
array(
realpath('../../')
),
array(
realpath(__DIR__ . '/../..')
),
);
}

public function testEmpty()
{
$builder = new Builder();
Expand Down