Skip to content

Commit

Permalink
Refactor test helpers and test files (#104)
Browse files Browse the repository at this point in the history
* Add Format as an optional constructor dependency to TestRender

Add Format as an optional constructor dependency to TestRender.
Check format's methods conditionally.
Refactor tests to inject formats.

* Add Config as a constructor dependency to TestRender

Add Config as a constructor dependency to TestRender.
Refactor tests to inject Config.

* Add Index as an optional constructor dependency to TestRender

* TestRender to extend Render

* Config to allow calling instance methods

* Refactor test helpers and test directory structure

Refactor TestRender to use only constructor injected objects.
Rename test format helper classes to indicate which package they belong to.
Move TestRender and all format helper classes into the phpdotnet phd directory to enable autoloading.
Remove all unnecessary lines from setup.php.
Restructure test directory to follow the structure of the tested classes.

---------

Co-authored-by: haszi <haszika80@gmail.com>
  • Loading branch information
haszi and haszi authored Feb 26, 2024
1 parent 2793dde commit b703f50
Show file tree
Hide file tree
Showing 40 changed files with 149 additions and 405 deletions.
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]);

$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.
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

0 comments on commit b703f50

Please sign in to comment.