Skip to content

Commit

Permalink
Fix doc-en GH-3197 - Incorrect void return type appended (#100)
Browse files Browse the repository at this point in the history
* Fix doc-en GH_3197

Fix void return type appended on void parameter list and add test for this fix.
Fix tests with incorrect expected output.

* Replace hardcoded html file extension for void type with the appropriate method call

---------

Co-authored-by: haszi <[email protected]>
  • Loading branch information
haszi and haszi authored Feb 20, 2024
1 parent 5362fde commit f2ba938
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 71 deletions.
2 changes: 1 addition & 1 deletion phpdotnet/phd/Package/Generic/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ public function format_void($open, $name, $attrs, $props) {
if (isset($props['sibling']) && $props['sibling'] == 'methodname') {
return '(';
} else {
return '<span class="type"><a href="language.types.void.html" class="type void">void</a></span>';
return '<span class="type"><a href="language.types.void' . $this->getExt() . '" class="type void">void</a></span>';
}
}

Expand Down
2 changes: 0 additions & 2 deletions phpdotnet/phd/Package/PHP/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,6 @@ public function format_type_text($type, $tagname) {

public function format_void($open, $name, $attrs, $props) {
if (isset($props['sibling']) && $props['sibling'] == 'methodname') {
$this->cchunk["methodsynopsis"]["returntypes"][] = "void";
$this->cchunk["methodsynopsis"]["type_separator"][] = "";
return '';
}
return parent::format_void($open, $name, $attrs, $props);
Expand Down
10 changes: 5 additions & 5 deletions tests/php/bug49102-1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ Content:

<div class="classsynopsisinfo classsynopsisinfo_comment">/* Methods */</div>
<div class="constructorsynopsis dc-description">
<span class="methodname"><strong>__construct</strong></span>(): <span class="type"><a href="language.types.void.html" class="type void">void</a></span></div>
<span class="methodname"><strong>__construct</strong></span>()</div>

<div class="methodsynopsis dc-description"><span class="methodname"><strong>setIteratorMode</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.html" class="type int">int</a></span> <code class="parameter">$mode</code></span>): <span class="type"><a href="language.types.void.html" class="type void">void</a></span></div>


<div class="classsynopsisinfo classsynopsisinfo_comment">/* Inherited methods */</div>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::bottom</strong></span>(): <span class="type"><span class="type"><a href="language.types.mixed.html" class="type mixed">mixed</a></span><span class="type"><a href="language.types.void.html" class="type void">void</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::bottom</strong></span>(): <span class="type"><a href="language.types.mixed.html" class="type mixed">mixed</a></span></div>

<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::count</strong></span>(): <span class="type"><span class="type"><a href="language.types.integer.html" class="type int">int</a></span><span class="type"><a href="language.types.void.html" class="type void">void</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::count</strong></span>(): <span class="type"><a href="language.types.integer.html" class="type int">int</a></span></div>

<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::current</strong></span>(): <span class="type"><span class="type"><a href="language.types.mixed.html" class="type mixed">mixed</a></span><span class="type"><a href="language.types.void.html" class="type void">void</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::current</strong></span>(): <span class="type"><a href="language.types.mixed.html" class="type mixed">mixed</a></span></div>

<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::getIteratorMode</strong></span>(): <span class="type"><span class="type"><a href="language.types.integer.html" class="type int">int</a></span><span class="type"><a href="language.types.void.html" class="type void">void</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::getIteratorMode</strong></span>(): <span class="type"><a href="language.types.integer.html" class="type int">int</a></span></div>

<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::offsetExists</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.html" class="type mixed">mixed</a></span> <code class="parameter">$index</code></span>): <span class="type"><a href="language.types.boolean.html" class="type bool">bool</a></span></div>

Expand Down
43 changes: 43 additions & 0 deletions tests/php/bug_doc-en_GH-3179.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--TEST--
Bug doc-en GH-3197
--FILE--
<?php
namespace phpdotnet\phd;

require_once __DIR__ . "/../setup.php";
require_once __DIR__ . "/TestChunkedXHTML.php";

$formatclass = "TestChunkedXHTML";
$xml_file = __DIR__ . "/data/Bug_doc-en_GH-3197.xml";

$opts = array(
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
);

$extra = array(
"lang_dir" => __PHDDIR__ . "phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
);

$render = new TestRender($formatclass, $opts, $extra);

if (Index::requireIndexing() && !file_exists($opts["output_dir"])) {
mkdir($opts["output_dir"], 0755);
}

$render->run();
?>
--EXPECT--
Filename: bug_doc-en_GH-3179.html
Content:
<div id="bug_doc-en_GH-3179" class="refentry">
<div class="refsect1 unknown-1" id="refsect1-bug_doc-en_GH-3179-unknown-1">
<div class="methodsynopsis dc-description"><span class="methodname"><strong>method_name</strong></span>(): <span class="type"><a href="language.types.void.html" class="type void">void</a></span></div>

</div>

</div>
8 changes: 8 additions & 0 deletions tests/php/data/bug_doc-en_GH-3197.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<refentry xml:id="bug_doc-en_GH-3179">
<refsect1>
<methodsynopsis>
<type>void</type><methodname>method_name</methodname>
<void/>
</methodsynopsis>
</refsect1>
</refentry>
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,71 @@
</section>

<section>
<para>2. Constructor with no parameters, void (element) return type</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>public</modifier> <methodname>ClassName::__construct</methodname>
<void/>
</constructorsynopsis>
</section>

<section>
<para>3. Constructor with one parameter</para>
<para>2. Constructor with one parameter</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>private</modifier> <methodname>ClassName::__construct</methodname>
<methodparam><type>mixed</type><parameter>anything</parameter></methodparam>
</constructorsynopsis>
</section>

<section>
<para>4. Constructor with optional parameter</para>
<para>3. Constructor with optional parameter</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>protected</modifier> <methodname>ClassName::__construct</methodname>
<methodparam choice="opt"><type>int</type><parameter>count</parameter><initializer>0</initializer></methodparam>
</constructorsynopsis>
</section>

<section>
<para>5. Constructor with nullable parameter</para>
<para>4. Constructor with nullable parameter</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>public</modifier> <methodname>ClassName::__construct</methodname>
<methodparam><type class="union"><type>float</type><type>null</type></type><parameter>value</parameter></methodparam>
</constructorsynopsis>
</section>

<section>
<para>6. Constructor with nullable optional parameter</para>
<para>5. Constructor with nullable optional parameter</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>private</modifier> <methodname>ClassName::__construct</methodname>
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>options</parameter><initializer>""</initializer></methodparam>
</constructorsynopsis>
</section>

<section>
<para>7. Constructor with reference parameter</para>
<para>6. Constructor with reference parameter</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>protected</modifier> <methodname>ClassName::__construct</methodname>
<methodparam><type>array</type><parameter role="reference">reference</parameter></methodparam>
</constructorsynopsis>
</section>

<section>
<para>8. Constructor with union type parameter</para>
<para>7. Constructor with union type parameter</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>public</modifier> <methodname>ClassName::__construct</methodname>
<methodparam><type class="union"><type>iterable</type><type>resource</type><type>callable</type><type>null</type></type><parameter>option</parameter></methodparam>
</constructorsynopsis>
</section>

<section>
<para>9. Constructor with intersection type parameter</para>
<para>8. Constructor with intersection type parameter</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>public</modifier> <methodname>ClassName::__construct</methodname>
<methodparam><type class="intersection"><type>Countable</type><type>Traversable</type></type><parameter>option</parameter></methodparam>
</constructorsynopsis>
</section>

<section>
<para>10. Constructor with DNF (Disjunctive Normal Form) type parameter</para>
<para>9. Constructor with DNF (Disjunctive Normal Form) type parameter</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>public</modifier> <methodname>ClassName::__construct</methodname>
<methodparam><type class="union"><type class="intersection"><type>Countable</type><type>Traversable</type></type><type>DOMAttr</type></type><parameter>option</parameter></methodparam>
</constructorsynopsis>
</section>

<section>
<para>11. Constructor with more than three parameters</para>
<para>10. Constructor with more than three parameters</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>private</modifier> <methodname>ClassName::__construct</methodname>
<methodparam><type>int</type><parameter>count</parameter></methodparam>
Expand Down
20 changes: 6 additions & 14 deletions tests/php/data/type_rendering_methodsynopsis_return_types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,42 @@
</section>

<section>
<para>4. Function/method with one return type - void element</para>
<methodsynopsis>
<methodname>function_name</methodname>
<void/>
</methodsynopsis>
</section>

<section>
<para>5. Function/method with one return type - mixed</para>
<para>4. Function/method with one return type - mixed</para>
<methodsynopsis>
<type>mixed</type><methodname>function_name</methodname>
</methodsynopsis>
</section>

<section>
<para>6. Function/method with union return type</para>
<para>5. Function/method with union return type</para>
<methodsynopsis>
<type class="union"><type>int</type><type>float</type><type>false</type></type><methodname>function_name</methodname>
</methodsynopsis>
</section>

<section>
<para>7. Function/method with nullable return type</para>
<para>6. Function/method with nullable return type</para>
<methodsynopsis>
<type class="union"><type>object</type><type>null</type></type><methodname>function_name</methodname>
</methodsynopsis>
</section>

<section>
<para>8. Function/method with nullable union return type</para>
<para>7. Function/method with nullable union return type</para>
<methodsynopsis>
<type class="union"><type>string</type><type>array</type><type>resource</type><type>callable</type><type>iterable</type><type>true</type><type>null</type></type><methodname>function_name</methodname>
</methodsynopsis>
</section>

<section>
<para>9. Function/method with unknown return type</para>
<para>8. Function/method with unknown return type</para>
<methodsynopsis>
<type>UnknownType</type><methodname>function_name</methodname>
</methodsynopsis>
</section>
<!-- TODO: fix known class return type - need to add a class to the index
<section role="description">
<para>10. Function/method with known class return type</para>
<para>9. Function/method with known class return type</para>
<methodsynopsis>
<type>stdClass</type><methodname>function_name</methodname>
</methodsynopsis>
Expand Down
24 changes: 9 additions & 15 deletions tests/php/type_rendering_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,61 +31,55 @@ if (Index::requireIndexing() && !file_exists($opts["output_dir"])) {

$render->run();
?>
--EXPECT--
--EXPECTF--
Filename: type-rendering-methodsynopsis-return-types.html
Content:
<div id="type-rendering-methodsynopsis-return-types" class="chapter">

<div class="section">
<p class="para">1. Function/method with no return type</p>
<p class="para">%d. Function/method with no return type</p>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>function_name</strong></span>()</div>

</div>

<div class="section">
<p class="para">2. Function/method with one return type - never</p>
<p class="para">%d. Function/method with one return type - never</p>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>function_name</strong></span>(): <span class="type"><a href="language.types.never.html" class="type never">never</a></span></div>

</div>

<div class="section">
<p class="para">3. Function/method with one return type - void</p>
<p class="para">%d. Function/method with one return type - void</p>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>function_name</strong></span>(): <span class="type"><a href="language.types.void.html" class="type void">void</a></span></div>

</div>

<div class="section">
<p class="para">4. Function/method with one return type - void element</p>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>function_name</strong></span>(): <span class="type"><a href="language.types.void.html" class="type void">void</a></span></div>

</div>

<div class="section">
<p class="para">5. Function/method with one return type - mixed</p>
<p class="para">%d. Function/method with one return type - mixed</p>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>function_name</strong></span>(): <span class="type"><a href="language.types.mixed.html" class="type mixed">mixed</a></span></div>

</div>

<div class="section">
<p class="para">6. Function/method with union return type</p>
<p class="para">%d. Function/method with union return type</p>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>function_name</strong></span>(): <span class="type"><span class="type"><a href="language.types.integer.html" class="type int">int</a></span>|<span class="type"><a href="language.types.float.html" class="type float">float</a></span>|<span class="type"><a href="language.types.value.html" class="type false">false</a></span></span></div>

</div>

<div class="section">
<p class="para">7. Function/method with nullable return type</p>
<p class="para">%d. Function/method with nullable return type</p>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>function_name</strong></span>(): <span class="type"><span class="type"><a href="language.types.null.html" class="type null">?</a></span><span class="type"><a href="language.types.object.html" class="type object">object</a></span></span></div>

</div>

<div class="section">
<p class="para">8. Function/method with nullable union return type</p>
<p class="para">%d. Function/method with nullable union return type</p>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>function_name</strong></span>(): <span class="type"><span class="type"><a href="language.types.string.html" class="type string">string</a></span>|<span class="type"><a href="language.types.array.html" class="type array">array</a></span>|<span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span>|<span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span>|<span class="type"><a href="language.types.iterable.html" class="type iterable">iterable</a></span>|<span class="type"><a href="language.types.value.html" class="type true">true</a></span>|<span class="type"><a href="language.types.null.html" class="type null">null</a></span></span></div>

</div>

<div class="section">
<p class="para">9. Function/method with unknown return type</p>
<p class="para">%d. Function/method with unknown return type</p>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>function_name</strong></span>(): <span class="type">UnknownType</span></div>

</div>
Expand Down
Loading

0 comments on commit f2ba938

Please sign in to comment.