Add test for all concordance lists implementing the concordance list

interface
This commit is contained in:
Joshua Ramon Enslin 2023-06-23 19:04:37 +02:00
parent 0cd1d24a2a
commit 75f2538e16
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -0,0 +1,64 @@
<?PHP
/**
* Test to ensure that all concordance lists in this repository implement the MDImporterConcordanceListInterface interface.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
use PHPUnit\Framework\TestCase;
// Require autoloader as per MDImporter's provideEnv.php
require_once __DIR__ . '/../../../provideEnv.php';
/**
* Test to ensure that all concordance lists in this repository implement the MDImporterConcordanceListInterface interface.
*/
final class InterfaceImplementationTest extends TestCase {
/** @var string[] */
private array $_lists = [];
/**
* Quasi-constructor connects to DB.
*
* @return void
*/
protected function setUp():void {
if (($listFiles = scandir(__DIR__ . '/../src')) === false) {
throw new Exception("Failed to read /src directory");
}
foreach ($listFiles as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) === 'php') {
$this->_lists[] = pathinfo($file, PATHINFO_FILENAME);
}
}
}
/**
* Test all concordance lists for their implementation of MDImporterConcordanceListInterface.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
* @group ValidOutput
* @group HTMLOutput
* @group SafeForProduction
*
* @return void
*/
public function testListInterfaceIsImplemented():void {
foreach ($this->_lists as $list) {
if (!file_exists(__DIR__ . '/../src/' . $list . '.php')) {
throw new Exception("List file does not exist" . $list);
}
require_once __DIR__ . '/../src/' . $list . '.php';
$interfaces = class_implements(new $list);
self::assertArrayHasKey('MDImporterConcordanceListInterface', $interfaces);
}
}
}