Add bootstrapping for tests, parse additional wikidata ID format
This commit is contained in:
		
							
								
								
									
										14
									
								
								phpunit.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								phpunit.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
<?xml version="1.0"?>
 | 
			
		||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" backupGlobals="false" beStrictAboutChangesToGlobalState="true" beStrictAboutOutputDuringTests="true" bootstrap="tests/bootstrap.php" cacheResult="false" colors="true" enforceTimeLimit="true" failOnWarning="true" processIsolation="true" stopOnError="true" stopOnFailure="true" stopOnIncomplete="true" stopOnSkipped="true" stopOnRisky="true" testdox="false" timeoutForSmallTests="1" timeoutForMediumTests="10" timeoutForLargeTests="60" cacheDirectory=".phpunit.cache" backupStaticProperties="false" requireCoverageMetadata="false" beStrictAboutCoverageMetadata="false">
 | 
			
		||||
  <testsuites>
 | 
			
		||||
    <testsuite name="tests">
 | 
			
		||||
      <directory>tests/</directory>
 | 
			
		||||
    </testsuite>
 | 
			
		||||
  </testsuites>
 | 
			
		||||
  <coverage/>
 | 
			
		||||
  <source>
 | 
			
		||||
    <include>
 | 
			
		||||
      <directory suffix=".php">src</directory>
 | 
			
		||||
    </include>
 | 
			
		||||
  </source>
 | 
			
		||||
</phpunit>
 | 
			
		||||
@@ -624,6 +624,13 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
 | 
			
		||||
                'https://www.wikidata.org/entity/' => '',
 | 
			
		||||
                'https://www.wikidata.org/w/index.php?search=&search=' => '',
 | 
			
		||||
            ]);
 | 
			
		||||
 | 
			
		||||
            if (str_starts_with($id, 'https://www.wikidata.org/w/index.php?title=')) {
 | 
			
		||||
                $id = str_replace('https://www.wikidata.org/w/index.php?title=', '', $id);
 | 
			
		||||
                if (($endPos = strpos($id, '&')) !== false) {
 | 
			
		||||
                    $id = substr($id, 0, $endPos);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (substr($id, 0, 1) !== 'Q') {
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,8 @@ final class MDNodaRepositoryTest extends TestCase {
 | 
			
		||||
     */
 | 
			
		||||
    public function testValidIdsValidate():void {
 | 
			
		||||
 | 
			
		||||
        self::assertEquals("Q834961", MDNodaRepository::wikidata->validateId("https://www.wikidata.org/w/index.php?title=Q834961&oldid=2256125706"));
 | 
			
		||||
 | 
			
		||||
        self::assertEquals("XX5034943", MDNodaRepository::bne->validateId("http://datos.bne.es/persona/XX5034943"));
 | 
			
		||||
        self::assertEquals("XX5034943", MDNodaRepository::bne->validateId("https://datos.bne.es/persona/XX5034943"));
 | 
			
		||||
        self::assertEquals("XX5034943", MDNodaRepository::bne->validateId("XX5034943"));
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										34
									
								
								tests/bootstrap.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								tests/bootstrap.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
<?PHP
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Autoloader for musdb.
 | 
			
		||||
 *
 | 
			
		||||
 * @param string $className Name of the class to load.
 | 
			
		||||
 *
 | 
			
		||||
 * @return void
 | 
			
		||||
 */
 | 
			
		||||
\spl_autoload_register(function(string $className):void {
 | 
			
		||||
 | 
			
		||||
    // Try using class map as defined through /scripts/buildClassMap.php
 | 
			
		||||
 | 
			
		||||
    foreach (array_merge([__DIR__ . '/../tests',
 | 
			
		||||
        __DIR__ . '/../src',
 | 
			
		||||
        __DIR__ . '/../src/enums',
 | 
			
		||||
        __DIR__ . '/../src/classes',
 | 
			
		||||
        __DIR__ . '/../exceptions',
 | 
			
		||||
        __DIR__ . '/../../MD_STD/src',
 | 
			
		||||
        __DIR__ . '/../../MDErrorReporter',
 | 
			
		||||
        __DIR__ . '/../../MDErrorReporter/exceptions',
 | 
			
		||||
        __DIR__ . '/../../MDErrorReporter/exceptions/generic',
 | 
			
		||||
        __DIR__ . '/../../MDErrorReporter/exceptions/updates',
 | 
			
		||||
    ]) as $classDir) {
 | 
			
		||||
 | 
			
		||||
        if (\file_exists("$classDir/$className.php")) {
 | 
			
		||||
            include "$classDir/$className.php";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user