Skip to content

Commit

Permalink
Stash (starting help as object)
Browse files Browse the repository at this point in the history
  • Loading branch information
R11T committed Dec 30, 2014
1 parent 67521e5 commit 247867b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
17 changes: 17 additions & 0 deletions App/Library/Factory/Help.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* @licence GPL-v2
*/
namespace App\Library\Factory;

/**
* Help factory
*
* @since 0.3
* @author Romain L.
* @see \Test\Unit\App\Library\Factory\Help
*/
class Help
{

}
14 changes: 8 additions & 6 deletions App/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@ public function run()
$router = Singleton::router();
$action = $router->getAction();
$type = $router->getSoftwareType();
if ('help' !== $action) {
if (null !== $action && 'help' !== $action) {
if (is_callable([$this, $action])) {
if (null !== $type) {
return call_user_func_array([$this, $action], [$type]);
} else {
throw new \InvalidArgumentException('Query must not be empty');
}
} else {
throw new \InvalidArgumentException('Action isn\'t a REST method');
/*} else {
throw new \InvalidArgumentException('Action isn\'t a REST method');*/
}
} else {
return $this->help();
/*} else {
return $this->help();*/
}
return $this->help();
}

/**
Expand Down Expand Up @@ -102,6 +103,7 @@ private function update($softwareType = null)// rename to push
*/
private function help()
{
$factory = new \App\Library\Factory\Help();
return [
'---- Help ----',
'Usage : {script_name} action [parameters]',
Expand Down Expand Up @@ -143,7 +145,7 @@ private function create() // rename to post
$res = $db->query('CREATE UNIQUE INDEX software_name ON software(software_name)');
var_dump($res);
}

private function add() // refacto with above
{
// with software type and software name, create new software class
Expand Down
6 changes: 3 additions & 3 deletions Test/Unit/App/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public function testRunNonCallable()
Singleton::router()->getMockController()->getAction = 'test';
Singleton::router()->getMockController()->getSoftwareType = null;

$this->exception(function () {
$this->main->run();
})->isInstanceOf('\InvalidArgumentException');
$run = $this->main->run();
$this->array($run)->hasSize(7);
$this->string($run[0])->contains('Help');
}

/**
Expand Down

0 comments on commit 247867b

Please sign in to comment.