Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor test helpers and test files #104

Merged
merged 6 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions phpdotnet/phd/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ public static function __callStatic($name, $params)
: NULL;
}

public function __call($name, $params) {
return self::__callStatic($name, $params);
}

public static function getSupportedPackages() {
$packageList = array();
foreach(Config::package_dirs() as $dir) {
Expand Down Expand Up @@ -183,5 +187,3 @@ public static function copyright() {
}

}


3 changes: 0 additions & 3 deletions phpdotnet/phd/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,3 @@ public function setMembership($membership) {
}

}



Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace phpdotnet\phd;

class TestChunkedXHTML extends Package_Generic_ChunkedXHTML {
class TestGenericChunkedXHTML extends Package_Generic_ChunkedXHTML {
public function update($event, $val = null) {
switch($event) {
case Render::CHUNK:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace phpdotnet\phd;

class TestBigXHTML extends Package_PHP_BigXHTML {
class TestPHPBigXHTML extends Package_PHP_BigXHTML {
public function update($event, $val = null) {
switch($event) {
case Render::CHUNK:
Expand Down Expand Up @@ -40,5 +40,3 @@ public function appendData($data) {
}

}


Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace phpdotnet\phd;

class TestChunkedXHTML extends Package_PHP_ChunkedXHTML {
class TestPHPChunkedXHTML extends Package_PHP_ChunkedXHTML {
public function update($event, $val = null) {
switch($event) {
case Render::CHUNK:
Expand Down Expand Up @@ -32,5 +32,3 @@ public function writeChunk($id, $fp) {
echo "Content:" . $content . "\n";
}
}


33 changes: 33 additions & 0 deletions phpdotnet/phd/TestRender.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace phpdotnet\phd;

class TestRender extends Render {
public function __construct(
protected Reader $reader,
protected Config $config,
protected ?Format $format = null,
protected ?Index $index = null,
) {}

public function run() {
if ($this->index && $this->index::requireIndexing()) {
if (!file_exists($this->config->output_dir())) {
mkdir($this->config->output_dir(), 0755);
}
$this->attach($this->index);
$this->reader->open($this->config->xml_file());
$this->execute($this->reader);
$this->detach($this->index);
}

if ($this->format !== null) {
$this->attach($this->format);
$this->reader->open($this->config->xml_file());
$this->execute($this->reader);
}
}

public function getIndex(): ?Index {
return $this->index;
}
}
56 changes: 0 additions & 56 deletions tests/TestRender.php

This file was deleted.

24 changes: 4 additions & 20 deletions tests/xhtml/001.phpt → tests/package/generic/001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,14 @@ CALS Table rendering
<?php
namespace phpdotnet\phd;

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

$formatclass = "TestChunkedXHTML";
$xml_file = __DIR__ . "/data/001-1.xml";

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

$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);
}
$format = new TestGenericChunkedXHTML;
$render = new TestRender(new Reader, new Config, $format);

$render->run();
?>
Expand Down
24 changes: 4 additions & 20 deletions tests/xhtml/002.phpt → tests/package/generic/002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,14 @@ CALS Table rendering#002
<?php
namespace phpdotnet\phd;

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

$formatclass = "TestChunkedXHTML";
$xml_file = __DIR__ . "/data/002.xml";

$opts = array(
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
);
Config::init(["xml_file" => $xml_file]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One improvement for later would maybe to make Config a Value Object and use named params to set the config keys?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean something like a readonly Value Object with named constructor parameters? Because that sounds like something that might make juggling these configurations easier. Unfortunately the properties of Config are not setup in the beginning of rendering so that it can easily be changed to a readonly VO but with some refactoring that could be done too.

I'll make a note of this and will probably start refactoring parts of this one by one (such as Options_Parser to return an array instead of setting Config directly, Index's database to be constructor injected so it can be added to Config outside of Index as well, moving hardcoded css urls out of PHP's XHTML format so it also can be added to Config at the very beginning of the script, output_formats also set at the beginning of the script, etc.).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically yes :) having a magic dictionary array with keys is hard to reason about, could be fixed by using a static analyser array shape, but I doubt any static analysis tool is going to enjoy PhD in the state it currently is :')


$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);
}
$format = new TestGenericChunkedXHTML;
$render = new TestRender(new Reader, new Config, $format);

$render->run();
?>
Expand Down
24 changes: 4 additions & 20 deletions tests/xhtml/003.phpt → tests/package/generic/003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,14 @@ CALS Table rendering#003
<?php
namespace phpdotnet\phd;

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

$formatclass = "TestChunkedXHTML";
$xml_file = __DIR__ . "/data/003.xml";

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

$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);
}
$format = new TestGenericChunkedXHTML;
$render = new TestRender(new Reader, new Config, $format);

$render->run();
?>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,14 @@ Simplelist rendering 001 - Types and columns
<?php
namespace phpdotnet\phd;

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

$formatclass = "TestChunkedXHTML";
$xml_file = __DIR__ . "/data/simplelist.xml";

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

$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);
}
$format = new TestGenericChunkedXHTML;
$render = new TestRender(new Reader, new Config, $format);

$render->run();
?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,14 @@ Whitespace formatting 001
<?php
namespace phpdotnet\phd;

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

$formatclass = "TestChunkedXHTML";
$xml_file = __DIR__ . "/data/whitespace_formatting_001.xml";

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

$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);
}
$format = new TestGenericChunkedXHTML;
$render = new TestRender(new Reader, new Config, $format);

$render->run();
?>
Expand Down
28 changes: 7 additions & 21 deletions tests/php/bug49101-1.phpt → tests/package/php/bug49101-1.phpt
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
--TEST--
Bug #49101 - Thick border again
Bug #49101-1 - Thick border again
--FILE--
<?php
namespace phpdotnet\phd;

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

$formatclass = "TestChunkedXHTML";
$xml_file = __DIR__ . "/data/bug49101-1.xml";

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

$extra = array(
"lang_dir" => __DIR__ . "/../../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);
}
$format = new TestPHPChunkedXHTML;
$render = new TestRender(new Reader, new Config, $format);

$render->run();
?>
Expand Down Expand Up @@ -91,3 +75,5 @@ Content:


</div>


Loading
Loading