-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #439 from consolidation-org/gendoc-test
Add GenerateMarkdownDocCest test.
- Loading branch information
Showing
6 changed files
with
190 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
namespace Robo\Task\{delegateNamespace}; | ||
|
||
use Robo\Result; | ||
use Robo\Task\StackBasedTask; | ||
use {delegateNamespace}\{delegate}; | ||
|
||
/** | ||
* Wrapper for {delegate} Component. | ||
* Comands are executed in stack and can be stopped on first fail with `stopOnFail` option. | ||
* | ||
* ``` php | ||
* <?php | ||
* $this->task{wrapperClassName}() | ||
* ... | ||
* ->run(); | ||
* | ||
* // one line | ||
* ... | ||
* | ||
* ?> | ||
* ``` | ||
* | ||
{methodList} | ||
*/ | ||
class {wrapperClassName} extends StackBasedTask | ||
{ | ||
protected $delegate; | ||
|
||
public function __construct() | ||
{ | ||
$this->delegate = new {delegate}(); | ||
} | ||
|
||
protected function getDelegate() | ||
{ | ||
return $this->delegate; | ||
}{immediateMethods}{methodImplementations} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
use Robo\Result; | ||
use Robo\Task\BaseTask; | ||
|
||
/** | ||
* A test task file. Used for testig documentation generation. | ||
* | ||
* ``` php | ||
* <?php | ||
* $this->taskTestedRoboTask([ | ||
* 'web/assets/screen.css', | ||
* 'web/assets/print.css', | ||
* 'web/assets/theme.css' | ||
* ]) | ||
* ->to('web/assets/style.css') | ||
* ->run() | ||
* ?> | ||
* ``` | ||
*/ | ||
class TestedRoboTask extends BaseTask | ||
{ | ||
/** | ||
* @var array|Iterator files | ||
*/ | ||
protected $files; | ||
|
||
/** | ||
* @var string dst | ||
*/ | ||
protected $dst; | ||
|
||
/** | ||
* Constructor. This should not be documented | ||
* | ||
* @param array|Iterator $files | ||
*/ | ||
public function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* Set the destination file | ||
* | ||
* @param string $dst | ||
* | ||
* @return Concat The current instance | ||
*/ | ||
public function to($dst) | ||
{ | ||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function run() | ||
{ | ||
return Result::success($this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
namespace Robo; | ||
|
||
use \CliGuy; | ||
|
||
use Robo\Contract\TaskInterface; | ||
use Robo\Collection\Temporary; | ||
use Robo\Result; | ||
|
||
class GenerateMarkdownDocCest | ||
{ | ||
public function _before(CliGuy $I) | ||
{ | ||
$I->amInPath(codecept_data_dir().'sandbox'); | ||
} | ||
|
||
public function toGenerateDocumentation(CliGuy $I) | ||
{ | ||
$sourceFile = codecept_data_dir() . 'TestedRoboTask.php'; | ||
$I->seeFileFound($sourceFile); | ||
include $sourceFile; | ||
$I->assertTrue(class_exists('TestedRoboTask')); | ||
|
||
$collection = $I->collectionBuilder(); | ||
$taskGenerator = $collection->taskGenDoc("TestedRoboTask.md"); | ||
$taskGenerator->filterClasses(function (\ReflectionClass $r) { | ||
return !($r->isAbstract() || $r->isTrait()) && $r->implementsInterface('Robo\Contract\TaskInterface'); | ||
})->prepend("# TestedRoboTask Tasks"); | ||
$taskGenerator->docClass('TestedRoboTask'); | ||
|
||
$taskGenerator->filterMethods( | ||
function (\ReflectionMethod $m) { | ||
if ($m->isConstructor() || $m->isDestructor() || $m->isStatic()) { | ||
return false; | ||
} | ||
$undocumentedMethods = | ||
[ | ||
'', | ||
'run', | ||
'__call', | ||
'inflect', | ||
'injectDependencies', | ||
'getCommand', | ||
'getPrinted', | ||
'getConfig', | ||
'setConfig', | ||
'logger', | ||
'setLogger', | ||
'setProgressIndicator', | ||
'progressIndicatorSteps', | ||
'setBuilder', | ||
'getBuilder', | ||
'collectionBuilder', | ||
]; | ||
return !in_array($m->name, $undocumentedMethods) && $m->isPublic(); // methods are not documented | ||
} | ||
)->processClassSignature( | ||
function ($c) { | ||
return "## " . preg_replace('~Task$~', '', $c->getShortName()) . "\n"; | ||
} | ||
)->processClassDocBlock( | ||
function (\ReflectionClass $c, $doc) { | ||
$doc = preg_replace('~@method .*?(.*?)\)~', '* `$1)` ', $doc); | ||
$doc = str_replace('\\'.$c->name, '', $doc); | ||
return $doc; | ||
} | ||
)->processMethodSignature( | ||
function (\ReflectionMethod $m, $text) { | ||
return str_replace('#### *public* ', '* `', $text) . '`'; | ||
} | ||
)->processMethodDocBlock( | ||
function (\ReflectionMethod $m, $text) { | ||
|
||
return $text ? ' ' . trim(strtok($text, "\n"), "\n") : ''; | ||
} | ||
); | ||
|
||
$collection->run(); | ||
$I->seeFileFound('TestedRoboTask.md'); | ||
|
||
$contents = file_get_contents('TestedRoboTask.md'); | ||
$I->assertContains('A test task file. Used for testig documentation generation.', $contents); | ||
$I->assertContains('taskTestedRoboTask', $contents); | ||
$I->assertContains('Set the destination file', $contents); | ||
} | ||
} |