Skip to content

Commit

Permalink
Refactor test helpers and test directory structure
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
haszi committed Feb 25, 2024
1 parent 547fc20 commit c5fce08
Show file tree
Hide file tree
Showing 39 changed files with 149 additions and 373 deletions.
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;
}
}
64 changes: 0 additions & 64 deletions tests/TestRender.php

This file was deleted.

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

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

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

Config::init([
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
"lang_dir" => __PHDDIR__ . "phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
]);

$format = new TestChunkedXHTML;
$render = new TestRender($format, new Config);

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

$format = new TestGenericChunkedXHTML;
$render = new TestRender(new Reader, new Config, $format);

$render->run();
?>
Expand Down
23 changes: 5 additions & 18 deletions tests/xhtml/002.phpt → tests/package/generic/002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +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";

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

Config::init([
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
"lang_dir" => __PHDDIR__ . "phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
]);

$format = new TestChunkedXHTML;
$render = new TestRender($format, new Config);

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

$format = new TestGenericChunkedXHTML;
$render = new TestRender(new Reader, new Config, $format);

$render->run();
?>
Expand Down
23 changes: 5 additions & 18 deletions tests/xhtml/003.phpt → tests/package/generic/003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +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";

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

Config::init([
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
"lang_dir" => __PHDDIR__ . "phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
]);

$format = new TestChunkedXHTML;
$render = new TestRender($format, new Config);

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

$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,27 +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";

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

Config::init([
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
"lang_dir" => __PHDDIR__ . "phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
]);
Config::init(["xml_file" => $xml_file]);

$format = new TestChunkedXHTML;
$render = new TestRender($format, new Config);

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,27 +4,14 @@ Whitespace formatting 001
<?php
namespace phpdotnet\phd;

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

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

Config::init([
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
"lang_dir" => __PHDDIR__ . "phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
]);
Config::init(["xml_file" => $xml_file]);

$format = new TestChunkedXHTML;
$render = new TestRender($format, new Config);

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
23 changes: 6 additions & 17 deletions tests/php/bug49101-1.phpt → tests/package/php/bug49101-1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,14 @@ Bug #49101-1 - Thick border again
<?php
namespace phpdotnet\phd;

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

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

Config::init([
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
"lang_dir" => __DIR__ . "/../../phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
]);
Config::init(["xml_file" => $xml_file]);

$format = new TestChunkedXHTML;
$render = new TestRender($format, new Config);

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 @@ -88,3 +75,5 @@ Content:


</div>


23 changes: 5 additions & 18 deletions tests/php/bug49101-2.phpt → tests/package/php/bug49101-2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,14 @@ Bug #49101-2 - Thick border again - Big XHTML
<?php
namespace phpdotnet\phd;

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

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

Config::init([
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
"lang_dir" => __DIR__ . "/../../phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
]);

$format = new TestBigXHTML;
$render = new TestRender($format, new Config);

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

$format = new TestPHPBigXHTML;
$render = new TestRender(new Reader, new Config, $format);

$render->run();
?>
Expand Down
Loading

0 comments on commit c5fce08

Please sign in to comment.