public function extract($name = 'new', $result = null)
{
$from = 'app';
$to = $name;
if ($result) {
$from = $name;
$to = $result;
}
$to = $this->_toPath($to);
if ($from[0] !== '/') {
$from = Libraries::locate('command.create.template', $from, array('filter' => false, 'type' => 'file', 'suffix' => '.phar.gz'));
if (!$from || is_array($from)) {
return false;
}
}
if (file_exists($from)) {
try {
$archive = new Phar($from);
} catch (Exception $e) {
$this->error($e->getMessage());
return false;
}
if ($archive->extractTo($to)) {
$this->out(basename($to) . " created in " . dirname($to) . " from {$from}");
return true;
}
}
$this->error("Could not extract {$to} from {$from}");
return false;
}
public function testExtractWhenLibraryDoesNotExist() { $this->skipIf(!extension_loaded('zlib'), 'The zlib extension is not loaded.'); chdir($this->_testPath); $app = new Library(array('request' => new Request(), 'classes' => $this->classes)); $app->library = 'does_not_exist'; $result = $app->extract(); $this->assertTrue($result); $this->assertTrue(file_exists($this->_testPath . '/new')); $path = realpath($this->_testPath); $tplPath = realpath(LITHIUM_LIBRARY_PATH . '/lithium/console/command/create/template'); $expected = "new created in {$path} from {$tplPath}/app.phar.gz\n"; $result = $app->response->output; $this->assertEqual($expected, $result); $this->_cleanUp(); }