MDImporterConcordanceLists/tests/InterfaceImplementationTest.php
2023-06-23 19:19:11 +02:00

75 lines
2.1 KiB
PHP

<?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.
*
* @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);
}
}
/**
* Ensure all tests throw the MDImporterMissingConcordance exception, if
* a new value is encountered.
*
* @return void
*/
public function testMDImporterMissingConcordanceIsThrownForNewValues():void {
foreach ($this->_lists as $list) {
$this->expectException(MDImporterMissingConcordance::class);
(new $list)::getConcordanceTarget("ThisInputShouldNotExist");
}
}
}