-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Playing around with a new way to organize functional tests.
- Loading branch information
Showing
166 changed files
with
1,123 additions
and
1,372 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,135 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\RST\Functional; | ||
|
||
use Doctrine\RST\Configuration; | ||
use Doctrine\RST\Formats\Format; | ||
use Doctrine\RST\Kernel; | ||
use Doctrine\RST\Parser; | ||
use Gajus\Dindent\Indenter; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Finder\Finder; | ||
use function array_map; | ||
use function basename; | ||
use function explode; | ||
use function file_exists; | ||
use function file_get_contents; | ||
use function implode; | ||
use function in_array; | ||
use function rtrim; | ||
use function str_replace; | ||
use function strpos; | ||
use function trim; | ||
|
||
class FunctionalTest extends TestCase | ||
{ | ||
private const RENDER_DOCUMENT_FILES = ['main-directive']; | ||
|
||
/** | ||
* @dataProvider getFunctionalTests | ||
*/ | ||
public function testFunctional( | ||
string $file, | ||
Parser $parser, | ||
string $renderMethod, | ||
string $format, | ||
string $rst, | ||
string $expected | ||
) : void { | ||
$expectedLines = explode("\n", $expected); | ||
$firstLine = $expectedLines[0]; | ||
|
||
if (strpos($firstLine, 'Exception:') === 0) { | ||
$exceptionClass = str_replace('Exception: ', '', $firstLine); | ||
$this->expectException($exceptionClass); | ||
|
||
$expectedExceptionMessage = $expectedLines; | ||
unset($expectedExceptionMessage[0]); | ||
$expectedExceptionMessage = implode("\n", $expectedExceptionMessage); | ||
|
||
$this->expectExceptionMessage($expectedExceptionMessage); | ||
} | ||
|
||
$document = $parser->parse($rst); | ||
|
||
$rendered = $document->$renderMethod(); | ||
|
||
if ($format === Format::HTML) { | ||
$indenter = new Indenter(); | ||
$rendered = $indenter->indent($rendered); | ||
} | ||
|
||
self::assertSame( | ||
$this->trimTrailingWhitespace($expected), | ||
$this->trimTrailingWhitespace($rendered) | ||
); | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function getFunctionalTests() : array | ||
{ | ||
$finder = new Finder(); | ||
$finder | ||
->files() | ||
->in(__DIR__ . '/tests') | ||
->name('*.rst'); | ||
|
||
$tests = []; | ||
|
||
foreach ($finder as $file) { | ||
$rst = $file->getContents(); | ||
$filename = $file->getFilename(); | ||
$basename = basename($filename, '.rst'); | ||
|
||
$dir = $file->getPathInfo(); | ||
|
||
$formats = [Format::HTML, Format::LATEX]; | ||
|
||
foreach ($formats as $format) { | ||
$formatPath = $dir . '/' . $basename . '.' . $format; | ||
|
||
if (! file_exists($formatPath)) { | ||
continue; | ||
} | ||
|
||
$expected = file_get_contents($formatPath); | ||
|
||
if ($expected === false) { | ||
continue; | ||
} | ||
|
||
$configuration = new Configuration(); | ||
$configuration->setFileExtension($format); | ||
|
||
$kernel = new Kernel($configuration); | ||
$parser = new Parser($kernel); | ||
|
||
$environment = $parser->getEnvironment(); | ||
$environment->setCurrentDirectory(__DIR__ . '/tests/' . $basename); | ||
|
||
$renderMethod = in_array($basename, self::RENDER_DOCUMENT_FILES, true) | ||
? 'renderDocument' | ||
: 'render'; | ||
|
||
$tests[] = [$basename, $parser, $renderMethod, $format, $rst, trim($expected)]; | ||
} | ||
} | ||
|
||
return $tests; | ||
} | ||
|
||
private function trimTrailingWhitespace(string $string) : string | ||
{ | ||
$lines = explode("\n", $string); | ||
|
||
$lines = array_map(static function (string $line) { | ||
return rtrim($line); | ||
}, $lines); | ||
|
||
return trim(implode("\n", $lines)); | ||
} | ||
} |
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 @@ | ||
<p>@Anchor Section</p> |
File renamed without changes.
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,8 @@ | ||
<div class="section" id="anchors"> | ||
<h1> | ||
Anchors | ||
</h1> | ||
<a id="lists"></a> | ||
|
||
<p><a href="#lists">go to lists</a></p> | ||
</div> |
File renamed without changes.
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,3 @@ | ||
\chapter{Anchors} | ||
\label{lists} | ||
\ref{#lists} |
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 @@ | ||
<p>I love <a href="http://www.github.com/">GitHub</a></p> |
2 changes: 0 additions & 2 deletions
2
tests/HTML/files/anonymous.rst → .../Functional/tests/anonymous/anonymous.rst
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
|
||
I love GitHub__ | ||
|
||
.. __: http://www.github.com/ | ||
|
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 @@ | ||
I love \href{http://www.github.com/}{GitHub} |
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 @@ | ||
|
File renamed without changes.
35 changes: 35 additions & 0 deletions
35
tests/Functional/tests/class-directive/class-directive.html
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,35 @@ | ||
<p class="special-paragraph1">Test special-paragraph1 1.</p> | ||
<p>Test special-paragraph1 2.</p> | ||
<p class="special-paragraph2">Test special-paragraph2 1.</p> | ||
<p class="special-paragraph2">Test special-paragraph2 2.</p> | ||
<div class="note"> | ||
<p class="special-paragraph3">Test</p> | ||
</div> | ||
<ul class="special-list"> | ||
<li class="dash">Test list item 1.</li> | ||
<li class="dash">Test list item 2.</li> | ||
</ul> | ||
<p class="rot-gelb-blau grun-2008">Weird class names.</p> | ||
<p class="level1">Level 1</p> | ||
<blockquote class="level1"> | ||
<p class="level2">Level2 1</p> | ||
<p class="level2">Level2 2</p> | ||
</blockquote> | ||
<dl class="special-definition-list"> | ||
<dt>term 1</dt> | ||
<dd>Definition 1 </dd> | ||
</dl> | ||
<table class="special-table"> | ||
<thead> | ||
<tr> | ||
<th>First col</th> | ||
<th>Second col</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td>Second row</td> | ||
<td>Other col</td> | ||
</tr> | ||
</tbody> | ||
</table> |
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
tests/Functional/tests/code-block-lastline/code-block-lastline.html
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,3 @@ | ||
<pre><code class="">A | ||
B C | ||
</code></pre> |
5 changes: 5 additions & 0 deletions
5
tests/Functional/tests/code-block-lastline/code-block-lastline.rst
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,5 @@ | ||
.. code-block:: | ||
A | ||
B | ||
C |
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,4 @@ | ||
<pre><code class="c++">#include <iostream> using namespace std; int main(void) | ||
{ cout << "Hello world!" << endl; | ||
} | ||
</code></pre> |
1 change: 0 additions & 1 deletion
1
tests/HTML/files/code-block.rst → ...unctional/tests/code-block/code-block.rst
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
.. code-block:: c++ | ||
|
||
#include <iostream> | ||
|
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,4 @@ | ||
<pre><code class="java">protected void f() | ||
{ | ||
} | ||
</code></pre> |
1 change: 0 additions & 1 deletion
1
tests/HTML/files/code-java.rst → .../Functional/tests/code-java/code-java.rst
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
.. code-block:: java | ||
protected void f() | ||
|
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,3 @@ | ||
<pre><code class="">* Testing | ||
* Hey | ||
</code></pre> |
1 change: 0 additions & 1 deletion
1
tests/HTML/files/code-list.rst → .../Functional/tests/code-list/code-list.rst
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
.. This should not be interpreted as a list | ||
.. code-block:: | ||
|
4 changes: 4 additions & 0 deletions
4
tests/Functional/tests/code-with-whitespace/code-with-whitespace.html
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,4 @@ | ||
<hr /> | ||
<blockquote> | ||
<p>Test code block with whitespace.</p> | ||
</blockquote> |
3 changes: 3 additions & 0 deletions
3
tests/Functional/tests/code-with-whitespace/code-with-whitespace.rst
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,3 @@ | ||
:: | ||
|
||
Test code block with whitespace. |
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,3 @@ | ||
<p>Code block:</p> | ||
<pre><code class="">This is a code block You hou! | ||
</code></pre> |
1 change: 0 additions & 1 deletion
1
tests/HTML/files/code.rst → tests/Functional/tests/code/code.rst
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
Code block:: | ||
|
||
This is a code block | ||
|
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,8 @@ | ||
Code block: | ||
\lstset{language=} | ||
\begin{lstlisting} | ||
This is a code block | ||
|
||
You hou! | ||
|
||
\end{lstlisting} |
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 @@ | ||
<p>... This is not a comment!</p> |
2 changes: 0 additions & 2 deletions
2
tests/HTML/files/comment-3.rst → .../Functional/tests/comment-3/comment-3.rst
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 |
---|---|---|
@@ -1,4 +1,2 @@ | ||
|
||
.. This is a comment! | ||
... This is not a comment! | ||
|
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,2 @@ | ||
<p>Text before</p> | ||
<p>Text after</p> |
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,3 @@ | ||
Text before | ||
.. Testing comment | ||
Text after |
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 @@ | ||
|
File renamed without changes.
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,6 @@ | ||
<div class="section" id="hello-world"> | ||
<h1> | ||
Hello world | ||
</h1> | ||
<p>Hey!</p> | ||
</div> |
2 changes: 1 addition & 1 deletion
2
tests/HTML/files/crlf.rst → tests/Functional/tests/crlf/crlf.rst
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Hello world | ||
=========== | ||
|
||
Hey! | ||
Hey! |
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 @@ | ||
<p>Testing page!</p> |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
.. stylesheet:: style.css | ||
|
||
Testing page! |
Oops, something went wrong.