Skip to content

Commit

Permalink
Merge pull request #439 from consolidation-org/gendoc-test
Browse files Browse the repository at this point in the history
Add GenerateMarkdownDocCest test.
  • Loading branch information
greg-1-anderson authored Sep 3, 2016
2 parents c2fc756 + aed52c0 commit 14df06a
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 4 deletions.
39 changes: 39 additions & 0 deletions data/Task/Development/GeneratedWrapper.tmpl
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}
}
4 changes: 2 additions & 2 deletions src/Task/Development/GenerateMarkdownDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* ``` php
* <?php
* $this->taskGenerateMarkdownDoc('models.md')
* $this->taskGenDoc('models.md')
* ->docClass('Model\User') // take class Model\User
* ->docClass('Model\Post') // take class Model\Post
* ->filterMethods(function(\ReflectionMethod $r) {
Expand All @@ -30,7 +30,7 @@
*
* ``` php
* <?php
* $this->taskGenerateMarkdownDoc('models.md')
* $this->taskGenDoc('models.md')
* ->docClass('Model\User')
* ->processClassSignature(false) // false can be passed to not include class signature
* ->processClassDocBlock(function(\ReflectionClass $r, $text) {
Expand Down
2 changes: 1 addition & 1 deletion src/Task/Development/loadTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function taskGenDoc($filename)

/**
* @param $filename
* @return GenerateMarkdownDoc
* @return GenerateTask
*/
protected function taskGenTask($className, $wrapperClassName = '')
{
Expand Down
61 changes: 61 additions & 0 deletions tests/_data/TestedRoboTask.php
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);
}
}
2 changes: 1 addition & 1 deletion tests/cli/GenTaskCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class GenTaskCest
{
// tests
public function toExecLsCommand(CliGuy $I)
public function toTestTaskGeneration(CliGuy $I)
{
$result = $I->taskGenTask('Symfony\Component\Filesystem\Filesystem', 'FilesystemStack')->run();
verify($result->getMessage())->contains('protected function _chgrp($files, $group, $recursive = false)');
Expand Down
86 changes: 86 additions & 0 deletions tests/cli/GenerateMarkdownDocCest.php
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);
}
}

0 comments on commit 14df06a

Please sign in to comment.