Skip to content

Commit 6931b79

Browse files
committed
Merge branch bc-andreadao/master
2 parents 1db5ae8 + 30ae7c5 commit 6931b79

18 files changed

Lines changed: 228 additions & 43 deletions

src/Example/functions.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace PhpDocumentorMarkdown\Functions;
4+
5+
/**
6+
* Mock function to demonstrate parameter handling.
7+
*
8+
* @param string $param1 Mock parameter 1
9+
* @param int $param2 Mock parameter 2
10+
* @return string
11+
*/
12+
function mockFunctionWithParameters(string $param1, int $param2): string
13+
{
14+
return "Parameter 1: $param1, Parameter 2: $param2";
15+
}
16+
17+
/**
18+
* Get database configuration.
19+
*
20+
* @return array Database configuration array
21+
* @see config.php
22+
*/
23+
function getDatabaseConfig(): array
24+
{
25+
return [
26+
'DB_NAME' => getenv('MYSQL_DATABASE') ?: 'pizza',
27+
'DB_USER' => getenv('MYSQL_USER'),
28+
'DB_PASSWORD' => getenv('MYSQL_PASSWORD'),
29+
'DB_HOST' => getenv('MYSQL_HOST'),
30+
];
31+
}

tests/Functional/FunctionalTestCase.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace PhpDocumentorMarkdown\Test\Functional;
44

5-
use League\CommonMark\CommonMarkConverter;
6-
use League\CommonMark\Exception\CommonMarkException;
75
use PhpDocumentorMarkdown\Test\Functional\Service\MarkdownGeneratorService;
86
use PHPUnit\Framework\TestCase;
97

tests/Functional/PhpdocOutputTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public static function dataProviderTestFiles(): iterable
3131
array(
3232
'path' => 'classes/PhpDocumentorMarkdown/Example/Pizza/Sauce.md',
3333
),
34+
array(
35+
'path' => 'functions/getDatabaseConfig.md',
36+
),
37+
array(
38+
'path' => 'functions/mockFunctionWithParameters.md',
39+
),
3440
);
3541
}
3642

tests/Functional/Service/MarkdownGeneratorService.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99

1010
class MarkdownGeneratorService
1111
{
12+
protected string $projectRootPath;
1213
protected string $workingDir;
1314
protected Filesystem $filesystem;
1415

1516
public function __construct(
16-
protected string $projectRootPath
17+
string $projectRootPath
1718
) {
19+
$this->projectRootPath = $projectRootPath;
1820
$this->filesystem = new Filesystem();
1921
$this->workingDir = tempnam(sys_get_temp_dir(), 'phpdoc');
2022
$this->filesystem->remove($this->workingDir);
@@ -34,11 +36,6 @@ protected function getProjectRootPath(): string
3436
return $this->projectRootPath;
3537
}
3638

37-
protected function getThemePath(): string
38-
{
39-
return "{$this->getProjectRootPath()}/themes/markdown";
40-
}
41-
4239
protected function getPhpDocBinaryPath(): string
4340
{
4441
return "{$this->getProjectRootPath()}/vendor/bin/phpdoc";
@@ -58,16 +55,13 @@ public function runPhpDocWithDir(string $path, array $arguments = []): Process
5855
PHP_BINARY,
5956
$this->getPhpDocBinaryPath(),
6057
'-vvv',
61-
'--config=none',
58+
"--config={$this->getProjectRootPath()}/phpdoc.dist.xml",
6259
'--force',
63-
"--template={$this->getThemePath()}",
64-
"--directory=$this->workingDir/test",
6560
"--target=$this->workingDir/output",
66-
'--title=Pizza Place (Example documentation)'
6761
],
6862
$arguments
6963
),
70-
$this->workingDir
64+
$this->getProjectRootPath()
7165
);
7266

7367
return $process->mustRun();

tests/Functional/expected/Home.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,12 @@ This is an automatically generated documentation for **Pizza Place (Example docu
3434
|-------------------------------------------------------------------|--------------------------|
3535
| [`Base`](./classes/PhpDocumentorMarkdown/Example/Pizza/Base.md) | Represents a pizza base. |
3636
| [`Sauce`](./classes/PhpDocumentorMarkdown/Example/Pizza/Sauce.md) | Pizza sauce class. |
37+
38+
### \PhpDocumentorMarkdown\Functions
39+
40+
#### Functions
41+
42+
| Function | Description |
43+
|-----------------------------------------------------------------------------|--------------------------------------------------|
44+
| [`mockFunctionWithParameters()`](./functions/mockFunctionWithParameters.md) | Mock function to demonstrate parameter handling. |
45+
| [`getDatabaseConfig()`](./functions/getDatabaseConfig.md) | Get database configuration. |
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# getDatabaseConfig()
2+
3+
Get database configuration.
4+
5+
* Full name: `getDatabaseConfig`
6+
* Defined in: `src/Example/functions.php`
7+
8+
## Parameters
9+
10+
This function has no parameters.
11+
12+
## Return Value
13+
14+
**array**
15+
16+
Database configuration array
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# mockFunctionWithParameters()
2+
3+
Mock function to demonstrate parameter handling.
4+
5+
* Full name: `mockFunctionWithParameters`
6+
* Defined in: `src/Example/functions.php`
7+
8+
## Parameters
9+
10+
| Parameter | Type | Description |
11+
|-----------|------------|------------------|
12+
| `$param1` | **string** | Mock parameter 1 |
13+
| `$param2` | **int** | Mock parameter 2 |
14+
15+
## Return Value
16+
17+
**string**

tests/Unit/Twig/Macro/MacroTest.php

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public static function dataProviderTestMdNodePath(): array
5050
{
5151
return [
5252
[
53-
'expected' => '/Fully/Qualified/Structural/Element/Name.md',
53+
'expected' => 'Fully/Qualified/Structural/Element/Name.md',
5454
'args' => ['\Fully\Qualified\Structural\Element\Name'],
5555
],
5656
[
57-
'expected' => '/Fully/Qualified/Structural/Element/Name.md',
57+
'expected' => 'Fully/Qualified/Structural/Element/Name.md',
5858
'args' => [(object)['FullyQualifiedStructuralElementName' => '\Fully\Qualified\Structural\Element\Name']],
5959
],
6060
];
@@ -92,26 +92,49 @@ public function testMdClassPath(string $expected, array $args): void
9292
self::assertEquals($expected, $result);
9393
}
9494

95-
public static function dataProviderTestMdClassLink(): array
95+
public static function dataProviderTestMdFunctionPath(): array
9696
{
9797
return [
9898
[
99-
'expected' => '[`Unknown`](./classes/Fully/Qualified/Structural/Element/Name.md)',
99+
'expected' => 'functions/Fully/Qualified/Structural/Element/Name.md',
100100
'args' => ['\Fully\Qualified\Structural\Element\Name'],
101101
],
102+
[
103+
'expected' => 'functions/Fully/Qualified/Structural/Element/Name.md',
104+
'args' => [(object)['FullyQualifiedStructuralElementName' => '\Fully\Qualified\Structural\Element\Name']],
105+
],
106+
];
107+
}
108+
109+
/**
110+
* @dataProvider dataProviderTestMdFunctionPath
111+
*/
112+
public function testMdFunctionPath(string $expected, array $args): void
113+
{
114+
$result = $this->renderTemplate('mdFunctionPath', $args);
115+
self::assertEquals($expected, $result);
116+
}
117+
118+
public static function dataProviderTestMdLink(): array
119+
{
120+
return [
121+
[
122+
'expected' => '[`Unknown`](./classes/Fully/Qualified/Structural/Element/Name.md)',
123+
'args' => ['\Fully\Qualified\Structural\Element\Name', null, null, 'class'],
124+
],
102125
[
103126
'expected' => '[`ClassName`](Structural/Element/Name.md)',
104-
'args' => ['\Fully\Qualified\Structural\Element\Name', 'classes/Fully/Qualified', 'ClassName'],
127+
'args' => ['\Fully\Qualified\Structural\Element\Name', 'classes/Fully/Qualified', 'ClassName', 'class'],
105128
],
106129
];
107130
}
108131

109132
/**
110-
* @dataProvider dataProviderTestMdClassLink
133+
* @dataProvider dataProviderTestMdLink
111134
*/
112-
public function testMdClassLink(string $expected, array $args): void
135+
public function testMdLink(string $expected, array $args): void
113136
{
114-
$result = $this->renderTemplate('mdClassLink', $args);
137+
$result = $this->renderTemplate('mdLink', $args);
115138
self::assertEquals($expected, $result);
116139
}
117140

tests/Unit/Twig/templates/macros.test.twig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
{% if key == 'mdClassPath' %}
1212
{{- macros.mdClassPath(args[0]) -}}
1313
{% endif %}
14-
{% if key == 'mdClassLink' %}
15-
{{- macros.mdClassLink(args[0], args[1], args[2]) -}}
14+
{% if key == 'mdFunctionPath' %}
15+
{{- macros.mdFunctionPath(args[0]) -}}
16+
{% endif %}
17+
{% if key == 'mdLink' %}
18+
{{- macros.mdLink(args[0], args[1], args[2], args[3]) -}}
1619
{% endif %}
1720
{% if key == 'mdRepeat' %}
1821
{{- macros.mdRepeat(args[0], args[1]) -}}

themes/markdown/class.md.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
} only %}
88

99
* Full name: `{{ node.FullyQualifiedStructuralElementName }}`
10-
{% if node.parent and node.parent is not empty %}* Parent class: {{ macros.mdClassLink(node.parent, macros.mdClassPath(node), node.parent.FullyQualifiedStructuralElementName) }}
10+
{% if node.parent and node.parent is not empty %}* Parent class: {{ macros.mdLink(node.parent, macros.mdClassPath(node), node.parent.FullyQualifiedStructuralElementName, 'class') }}
1111
{% endif %}
1212
{% if node.final %}* This class is marked as **final** and can't be subclassed
1313
{% endif %}
1414
{% if node.deprecated %}* **Warning:** this class is **deprecated**. This means that this class will likely be removed in a future version.
1515
{% endif %}
1616
{% if node.interfaces is not empty %}* This class implements:
17-
{% for interface in node.interfaces %}{% if loop.index0 > 0 %}{{ ',\n ' }}{% else %}{{ ' ' }}{% endif %}{{ macros.mdClassLink(interface, macros.mdClassPath(node), interface) }}{% endfor %}
17+
{% for interface in node.interfaces %}{% if loop.index0 > 0 %}{{ ',\n ' }}{% else %}{{ ' ' }}{% endif %}{{ macros.mdLink(interface, macros.mdClassPath(node), interface, 'class') }}{% endfor %}
1818

1919
{% endif %}
2020
{% if node.abstract %}* This class is an **Abstract class**

0 commit comments

Comments
 (0)