Skip to content

Commit 2b41825

Browse files
authored
Fix run-tests.php after a php-src change (#266)
1 parent 9f7a92f commit 2b41825

10 files changed

Lines changed: 70 additions & 23 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ run-tests.php
1010
**/tests/**/*.diff
1111
**/tests/**/*.out*
1212
**/tests/**/*.php
13+
!tests/helpers.php
1314
**/tests/**/*.exp
1415
**/tests/**/*.log
1516
**/tests/**/*.sh

‎phpdotnet/phd/Package/PHP/Web.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public function header($id) {
201201
"up" => $up,
202202
"prev" => $prev,
203203
"next" => $next,
204-
"alternatives" => $this->cchunk["alternatives"],
204+
"alternatives" => $this->cchunk["alternatives"] ?? [],
205205
"source" => $this->sourceInfo($id),
206206
);
207207
$history = $this->history ?? [];

‎tests/GH-225.phpt‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ all
88
<?php
99
namespace phpdotnet\phd;
1010

11-
if (!\file_exists(__DIR__ . "/../output/")) {
12-
\mkdir(__DIR__ . "/../output/", 0777, true);
13-
}
11+
require_once __DIR__ . "/helpers.php";
12+
ensureOutputFolder();
1413

1514
if (\file_exists(__DIR__ . "/../phd.config.php")) {
1615
\unlink(__DIR__ . "/../phd.config.php");
@@ -27,14 +26,9 @@ require_once __DIR__ . "/../render.php";
2726
--CLEAN--
2827
<?php
2928
\unlink(__DIR__ . "/../phd.config.php");
30-
$iterator = new \RecursiveIteratorIterator(
31-
new \RecursiveDirectoryIterator(__DIR__ . "/../output/", \FilesystemIterator::SKIP_DOTS),
32-
\RecursiveIteratorIterator::CHILD_FIRST
33-
);
34-
foreach ($iterator as $file) {
35-
$file->isDir() ? \rmdir($file->getPathname()) : \unlink($file->getPathname());
36-
}
37-
\rmdir(__DIR__ . "/../output/");
29+
30+
require_once __DIR__ . "/helpers.php";
31+
\phpdotnet\phd\removeOutputFolder();
3832
?>
3933
--EXPECTF--
4034
%s[%d:%d:%d - Heads up ]%s Loaded config from existing file

‎tests/helpers.php‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
namespace phpdotnet\phd;
3+
4+
function ensureOutputFolder(): void
5+
{
6+
if (!\file_exists(\dirname(__DIR__) . "/output/")) {
7+
\mkdir(\dirname(__DIR__) . "/output/", 0777, true);
8+
}
9+
}
10+
11+
function removeOutputFolder(): void
12+
{
13+
$folder = \dirname(__DIR__) . "/output/";
14+
if (!\file_exists($folder)) {
15+
return;
16+
}
17+
18+
$iterator = new \RecursiveIteratorIterator(
19+
new \RecursiveDirectoryIterator($folder, \FilesystemIterator::SKIP_DOTS),
20+
\RecursiveIteratorIterator::CHILD_FIRST
21+
);
22+
foreach ($iterator as $file) {
23+
$file->isDir() ? \rmdir($file->getPathname()) : \unlink($file->getPathname());
24+
}
25+
\rmdir($folder);
26+
}

‎tests/options/default_handler_007.phpt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Default options handler 007 - Save config (short option) and quit (short option)
33
--ARGS--
44
--docbook tests/options/default_handler_007.phpt -S -Q
5+
--CONFLICTS--
6+
all
57
--SKIPIF--
68
<?php
79
if (file_exists(__DIR__ . "/../../phd.config.php")) {
@@ -12,11 +14,17 @@ if (file_exists(__DIR__ . "/../../phd.config.php")) {
1214
<?php
1315
namespace phpdotnet\phd;
1416

17+
require_once __DIR__ . "/../helpers.php";
18+
ensureOutputFolder();
19+
1520
require_once __DIR__ . "/../../render.php";
1621
?>
1722
--CLEAN--
1823
<?php
1924
unlink(__DIR__ . "/../../phd.config.php");
25+
26+
require_once __DIR__ . "/../helpers.php";
27+
\phpdotnet\phd\removeOutputFolder();
2028
?>
2129
--EXPECTF--
2230
%s[%d:%d:%d - Heads up ]%s Writing the config file

‎tests/options/default_handler_008.phpt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@ if (file_exists(__DIR__ . "/../../phd.config.php")) {
1414
<?php
1515
namespace phpdotnet\phd;
1616

17+
require_once __DIR__ . "/../helpers.php";
18+
ensureOutputFolder();
19+
1720
require_once __DIR__ . "/../../render.php";
1821
?>
1922
--CLEAN--
2023
<?php
2124
unlink(__DIR__ . "/../../phd.config.php");
25+
26+
require_once __DIR__ . "/../helpers.php";
27+
\phpdotnet\phd\removeOutputFolder();
2228
?>
2329
--EXPECTF--
2430
%s[%d:%d:%d - Heads up ]%s Writing the config file

‎tests/render/data/sources.xml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<sources>
3+
<file id="index" lang="en" path="index.xml"/>
4+
</sources>

‎tests/render/data/version.xml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<versions>
3+
<function name="strlen" from="PHP 4, PHP 5, PHP 7, PHP 8"/>
4+
</versions>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<entities xmlns = "http://docbook.org/ns/docbook"
4+
xmlns:xlink = "http://www.w3.org/1999/xlink"
5+
translate = "yes">
6+
7+
<entity name="acronym.expansion.API">Application Programming Interface</entity>
8+
9+
</entities>

‎tests/render/render_001.phpt‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,21 @@
22
Render 001 - Smoke test render.php
33
--ARGS--
44
--memoryindex --forceindex --package PHP --format php --docbook tests/render/data/render_001.xml
5+
--CONFLICTS--
6+
all
57
--FILE--
68
<?php
79
namespace phpdotnet\phd;
810

9-
if (!\file_exists(__DIR__ . "/../../output/")) {
10-
\mkdir(__DIR__ . "/../../output/", 0777, true);
11-
}
11+
require_once __DIR__ . "/../helpers.php";
12+
ensureOutputFolder();
1213

1314
require_once __DIR__ . "/../../render.php";
1415
?>
1516
--CLEAN--
1617
<?php
17-
$iterator = new \RecursiveIteratorIterator(
18-
new \RecursiveDirectoryIterator(__DIR__ . "/../../output/", \FilesystemIterator::SKIP_DOTS),
19-
\RecursiveIteratorIterator::CHILD_FIRST
20-
);
21-
foreach ($iterator as $file) {
22-
$file->isDir() ? \rmdir($file->getPathname()) : \unlink($file->getPathname());
23-
}
24-
\rmdir(__DIR__ . "/../../output/");
18+
require_once __DIR__ . "/../helpers.php";
19+
\phpdotnet\phd\removeOutputFolder();
2520
?>
2621
--EXPECTF--
2722
%s[%d:%d:%d - Indexing ]%s Indexing...

0 commit comments

Comments
 (0)