|
1
|
|
|
<?php |
|
2
|
|
|
namespace Robo; |
|
3
|
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
|
5
|
|
|
use Robo\Traits\TestTasksTrait; |
|
6
|
|
|
|
|
7
|
|
|
class GenerateMarkdownDocTest extends TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
use TestTasksTrait; |
|
10
|
|
|
use Collection\loadTasks; |
|
11
|
|
|
use Task\Development\loadTasks; |
|
12
|
|
|
use Task\File\loadTasks; |
|
13
|
|
|
|
|
14
|
|
|
protected $fixtures; |
|
15
|
|
|
|
|
16
|
|
|
public function setUp() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->fixtures = new Fixtures(); |
|
19
|
|
|
$this->initTestTasksTrait(); |
|
20
|
|
|
$this->fixtures->createAndCdToSandbox(); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function tearDown() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->fixtures->cleanup(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testGenerateDocumentation() |
|
29
|
|
|
{ |
|
30
|
|
|
$sourceFile = $this->fixtures->dataFile('TestedRoboTask.php'); |
|
31
|
|
|
$this->assertFileExists($sourceFile); |
|
32
|
|
|
include $sourceFile; |
|
33
|
|
|
$this->assertTrue(class_exists('TestedRoboTask')); |
|
34
|
|
|
|
|
35
|
|
|
$collection = $this->collectionBuilder(); |
|
36
|
|
|
$taskGenerator = $collection->taskGenDoc("TestedRoboTask.md"); |
|
|
|
|
|
|
37
|
|
|
$taskGenerator->filterClasses(function (\ReflectionClass $r) { |
|
38
|
|
|
return !($r->isAbstract() || $r->isTrait()) && $r->implementsInterface('Robo\Contract\TaskInterface'); |
|
39
|
|
|
})->prepend("# TestedRoboTask Tasks"); |
|
40
|
|
|
$taskGenerator->docClass('TestedRoboTask'); |
|
41
|
|
|
|
|
42
|
|
|
$taskGenerator->filterMethods( |
|
43
|
|
|
function (\ReflectionMethod $m) { |
|
44
|
|
|
if ($m->isConstructor() || $m->isDestructor() || $m->isStatic()) { |
|
45
|
|
|
return false; |
|
46
|
|
|
} |
|
47
|
|
|
$undocumentedMethods = |
|
48
|
|
|
[ |
|
49
|
|
|
'', |
|
50
|
|
|
'run', |
|
51
|
|
|
'__call', |
|
52
|
|
|
'inflect', |
|
53
|
|
|
'injectDependencies', |
|
54
|
|
|
'getCommand', |
|
55
|
|
|
'getPrinted', |
|
56
|
|
|
'getConfig', |
|
57
|
|
|
'setConfig', |
|
58
|
|
|
'logger', |
|
59
|
|
|
'setLogger', |
|
60
|
|
|
'setProgressIndicator', |
|
61
|
|
|
'progressIndicatorSteps', |
|
62
|
|
|
'setBuilder', |
|
63
|
|
|
'getBuilder', |
|
64
|
|
|
'collectionBuilder', |
|
65
|
|
|
]; |
|
66
|
|
|
return !in_array($m->name, $undocumentedMethods) && $m->isPublic(); // methods are not documented |
|
67
|
|
|
} |
|
68
|
|
|
)->processClassSignature( |
|
69
|
|
|
function ($c) { |
|
70
|
|
|
return "## " . preg_replace('~Task$~', '', $c->getShortName()) . "\n"; |
|
71
|
|
|
} |
|
72
|
|
|
)->processClassDocBlock( |
|
73
|
|
|
function (\ReflectionClass $c, $doc) { |
|
74
|
|
|
$doc = preg_replace('~@method .*?(.*?)\)~', '* `$1)` ', $doc); |
|
75
|
|
|
$doc = str_replace('\\'.$c->name, '', $doc); |
|
76
|
|
|
return $doc; |
|
77
|
|
|
} |
|
78
|
|
|
)->processMethodSignature( |
|
79
|
|
|
function (\ReflectionMethod $m, $text) { |
|
80
|
|
|
return str_replace('#### *public* ', '* `', $text) . '`'; |
|
81
|
|
|
} |
|
82
|
|
|
)->processMethodDocBlock( |
|
83
|
|
|
function (\ReflectionMethod $m, $text) { |
|
84
|
|
|
|
|
85
|
|
|
return $text ? ' ' . trim(strtok($text, "\n"), "\n") : ''; |
|
86
|
|
|
} |
|
87
|
|
|
); |
|
88
|
|
|
|
|
89
|
|
|
$result = $collection->run(); |
|
90
|
|
|
$this->assertTrue($result->wasSuccessful(), $result->getMessage()); |
|
91
|
|
|
|
|
92
|
|
|
$this->assertFileExists('TestedRoboTask.md'); |
|
93
|
|
|
|
|
94
|
|
|
$contents = file_get_contents('TestedRoboTask.md'); |
|
95
|
|
|
$this->assertContains('A test task file. Used for testig documentation generation.', $contents); |
|
96
|
|
|
$this->assertContains('taskTestedRoboTask', $contents); |
|
97
|
|
|
$this->assertContains('Set the destination file', $contents); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: