Skip to content

Commit

Permalink
Fix SMW_PHPUNIT_DIR (#5862)
Browse files Browse the repository at this point in the history
* Fix SMW_PHPUNIT_DIR

For some reason under MW 1.41+ is failing with finding this define,
even tho it is in bootstrap. Adding it to Setup seems to have fixed it.

* Update SetupCheckTest.php
  • Loading branch information
paladox authored Dec 20, 2024
1 parent ca34df0 commit a0b2b45
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 39 deletions.
4 changes: 4 additions & 0 deletions src/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ private function addDefaultConfigurations( &$vars, $rootDir ) {
define( 'SMW_PHPUNIT_AUTOLOADER_FILE', "$smwDir/tests/autoloader.php" );
}

if ( !defined( 'SMW_PHPUNIT_DIR' ) ) {
define( 'SMW_PHPUNIT_DIR', __DIR__ . '/../tests/phpunit' );
}

$vars['wgLogTypes'][] = 'smw';
$vars['wgFilterLogTypes']['smw'] = true;

Expand Down
1 change: 0 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
'SMW\Maintenance\updateEntityCountMap' => __DIR__ . '/../maintenance/updateEntityCountMap.php'
] );

define( 'SMW_PHPUNIT_DIR', __DIR__ . '/phpunit' );
// define( 'SMW_PHPUNIT_TABLE_PREFIX', 'sunittest_' );
// define( 'SMW_PHPUNIT_TABLE_PREFIX', '' );

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Exception/JSONFileParseExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class JSONFileParseExceptionTest extends \PHPUnit\Framework\TestCase {

public function testCanConstruct() {
$instance = new JSONFileParseException(
SMW_PHPUNIT_DIR . '/Fixtures/Exception/invalid.trailing.comma.json'
\SMW_PHPUNIT_DIR . '/Fixtures/Exception/invalid.trailing.comma.json'
);

$this->assertContains(
Expand Down
10 changes: 5 additions & 5 deletions tests/phpunit/Integration/Importer/JsonFileDirReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testGetContentList() {
$this->contentModeller,
$this->fileFetcher,
$this->file,
[ SMW_PHPUNIT_DIR . '/Fixtures/Importer/Others/ValidTextContent' ]
[ \SMW_PHPUNIT_DIR . '/Fixtures/Importer/Others/ValidTextContent' ]
);

$contents = $instance->getContentList();
Expand All @@ -69,7 +69,7 @@ public function testGetContentListOnFalseImportFormat() {
$this->contentModeller,
$this->fileFetcher,
$this->file,
[ SMW_PHPUNIT_DIR . '/Fixtures/Importer/Others/NoImportFormat' ]
[ \SMW_PHPUNIT_DIR . '/Fixtures/Importer/Others/NoImportFormat' ]
);

$this->assertEmpty(
Expand All @@ -82,7 +82,7 @@ public function testGetContentListOnMissingSections() {
$this->contentModeller,
$this->fileFetcher,
$this->file,
[ SMW_PHPUNIT_DIR . '/Fixtures/Importer/Others/MissingSections' ]
[ \SMW_PHPUNIT_DIR . '/Fixtures/Importer/Others/MissingSections' ]
);

$contents = $instance->getContentList();
Expand All @@ -98,7 +98,7 @@ public function testGetContentListWithInvalidPath() {
$this->contentModeller,
$this->fileFetcher,
$this->file,
[ SMW_PHPUNIT_DIR . '/Fixtures/Importer/Others/InvalidPath' ]
[ \SMW_PHPUNIT_DIR . '/Fixtures/Importer/Others/InvalidPath' ]
);

$this->assertEmpty(
Expand All @@ -111,7 +111,7 @@ public function testGetContentListOnInvalidJson_Error() {
$this->contentModeller,
$this->fileFetcher,
$this->file,
[ SMW_PHPUNIT_DIR . '/Fixtures/Importer/Others/InvalidJsonContent' ]
[ \SMW_PHPUNIT_DIR . '/Fixtures/Importer/Others/InvalidJsonContent' ]
);

$instance->getContentList();
Expand Down
16 changes: 8 additions & 8 deletions tests/phpunit/Integration/Localizer/CopyLocalMessagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ class CopyLocalMessagesTest extends \PHPUnit\Framework\TestCase {
private $translatedMessages;

protected function setUp(): void {
$this->canonicalMessages = file_get_contents( SMW_PHPUNIT_DIR . '/Fixtures/Localizer/en.json' );
$this->translatedMessages = file_get_contents( SMW_PHPUNIT_DIR . '/Fixtures/Localizer/test.json' );
$this->canonicalMessages = file_get_contents( \SMW_PHPUNIT_DIR . '/Fixtures/Localizer/en.json' );
$this->translatedMessages = file_get_contents( \SMW_PHPUNIT_DIR . '/Fixtures/Localizer/test.json' );
}

protected function tearDown(): void {
file_put_contents( SMW_PHPUNIT_DIR . '/Fixtures/Localizer/en.json', $this->canonicalMessages );
file_put_contents( SMW_PHPUNIT_DIR . '/Fixtures/Localizer/test.json', $this->translatedMessages );
file_put_contents( \SMW_PHPUNIT_DIR . '/Fixtures/Localizer/en.json', $this->canonicalMessages );
file_put_contents( \SMW_PHPUNIT_DIR . '/Fixtures/Localizer/test.json', $this->translatedMessages );
}

public function testCopyCanonicalMessages() {
$instance = new CopyLocalMessages(
'test.json',
SMW_PHPUNIT_DIR . '/Fixtures/Localizer'
\SMW_PHPUNIT_DIR . '/Fixtures/Localizer'
);

$this->assertEquals(
Expand All @@ -41,7 +41,7 @@ public function testCopyCanonicalMessages() {
);

$canonicalMessages = json_decode(
file_get_contents( SMW_PHPUNIT_DIR . '/Fixtures/Localizer/en.json' ),
file_get_contents( \SMW_PHPUNIT_DIR . '/Fixtures/Localizer/en.json' ),
true
);

Expand All @@ -60,7 +60,7 @@ public function testCopyCanonicalMessages() {
public function tesCopyTranslatedMessages() {
$instance = new CopyLocalMessages(
'test.json',
SMW_PHPUNIT_DIR . '/Fixtures/Localizer'
\SMW_PHPUNIT_DIR . '/Fixtures/Localizer'
);

$this->assertEquals(
Expand All @@ -72,7 +72,7 @@ public function tesCopyTranslatedMessages() {
);

$translatedMessages = json_decode(
file_get_contents( SMW_PHPUNIT_DIR . '/Fixtures/Localizer/test.json' ),
file_get_contents( \SMW_PHPUNIT_DIR . '/Fixtures/Localizer/test.json' ),
true
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function tearDown(): void {
public function testDeclarationsLoadedPartiallyFromFallback() {
$JsonContentsFileReader = new JsonContentsFileReader(
null,
SMW_PHPUNIT_DIR . '/Fixtures/Localizer/LocalLanguage/'
\SMW_PHPUNIT_DIR . '/Fixtures/Localizer/LocalLanguage/'
);

$languageContents = new LanguageContents(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ protected function setUp(): void {

$schema = new SchemaDefinition(
'fake_iterator_schema',
json_decode( file_get_contents( SMW_PHPUNIT_DIR . '/Fixtures/Schema/fake_iterator_schema.json' ), true )
json_decode( file_get_contents( \SMW_PHPUNIT_DIR . '/Fixtures/Schema/fake_iterator_schema.json' ), true )
);

$this->schemaList->add( $schema );

$schema = new SchemaDefinition(
'fake_iterator_schema_extra',
json_decode( file_get_contents( SMW_PHPUNIT_DIR . '/Fixtures/Schema/fake_iterator_schema.json' ), true )
json_decode( file_get_contents( \SMW_PHPUNIT_DIR . '/Fixtures/Schema/fake_iterator_schema.json' ), true )
);

$this->schemaList->add( $schema );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function setUp(): void {
private function newSchemaDefinition( $name ) {
return new SchemaDefinition(
$name,
json_decode( file_get_contents( SMW_PHPUNIT_DIR . "/Fixtures/Schema/$name.json" ), true )
json_decode( file_get_contents( \SMW_PHPUNIT_DIR . "/Fixtures/Schema/$name.json" ), true )
);
}

Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/Integration/Utils/FileFetcherRoundTripTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function testRoundTrip_Sort_Desc() {

public function testRoundTrip_Sort_Desc_SubDir() {
$fileFetcher = new FileFetcher(
FileFetcher::normalize( SMW_PHPUNIT_DIR . '/Fixtures/Utils/' )
FileFetcher::normalize( \SMW_PHPUNIT_DIR . '/Fixtures/Utils/' )
);

$fileFetcher->sort( 'desc' );
Expand All @@ -84,9 +84,9 @@ public function testRoundTrip_Sort_Desc_SubDir() {

$this->assertEquals(
[
[ FileFetcher::normalize( SMW_PHPUNIT_DIR . '/Fixtures/Utils/zzz.json' ) ],
[ FileFetcher::normalize( SMW_PHPUNIT_DIR . '/Fixtures/Utils/subDir/bbb.json' ) ],
[ FileFetcher::normalize( SMW_PHPUNIT_DIR . '/Fixtures/Utils/aaa.json' ) ]
[ FileFetcher::normalize( \SMW_PHPUNIT_DIR . '/Fixtures/Utils/zzz.json' ) ],
[ FileFetcher::normalize( \SMW_PHPUNIT_DIR . '/Fixtures/Utils/subDir/bbb.json' ) ],
[ FileFetcher::normalize( \SMW_PHPUNIT_DIR . '/Fixtures/Utils/aaa.json' ) ]
],
$files
);
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/Localizer/LocalMessageProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testCanConstruct() {

public function testMsg() {
$instance = new LocalMessageProvider( 'test.json', 'en' );
$instance->setLanguageFileDir( SMW_PHPUNIT_DIR . '/Fixtures/Localizer' );
$instance->setLanguageFileDir( \SMW_PHPUNIT_DIR . '/Fixtures/Localizer' );
$instance->setLanguageCode( 'ja' );
$instance->loadMessages();

Expand All @@ -39,7 +39,7 @@ public function testMsg() {

public function testMsg_Fallback() {
$instance = new LocalMessageProvider( 'test.json', 'en' );
$instance->setLanguageFileDir( SMW_PHPUNIT_DIR . '/Fixtures/Localizer' );
$instance->setLanguageFileDir( \SMW_PHPUNIT_DIR . '/Fixtures/Localizer' );
$instance->setLanguageCode( 'foo' );
$instance->loadMessages();

Expand All @@ -51,7 +51,7 @@ public function testMsg_Fallback() {

public function testMsg_WithArgs() {
$instance = new LocalMessageProvider( 'test.json', 'en' );
$instance->setLanguageFileDir( SMW_PHPUNIT_DIR . '/Fixtures/Localizer' );
$instance->setLanguageFileDir( \SMW_PHPUNIT_DIR . '/Fixtures/Localizer' );
$instance->setLanguageCode( 'ja' );
$instance->loadMessages();

Expand All @@ -63,7 +63,7 @@ public function testMsg_WithArgs() {

public function testMsg_NoValidKey() {
$instance = new LocalMessageProvider( 'test.json', 'en' );
$instance->setLanguageFileDir( SMW_PHPUNIT_DIR . '/Fixtures/Localizer' );
$instance->setLanguageFileDir( \SMW_PHPUNIT_DIR . '/Fixtures/Localizer' );
$instance->loadMessages();

$this->assertEquals(
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/Schema/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testValidate_IsValid() {
$instance = new SchemaValidator( $jsonSchemaValidator );

$info = [
SchemaDefinition::SCHEMA_VALIDATION_FILE => SMW_PHPUNIT_DIR . '/Fixtures/Schema/empty_schema.json'
SchemaDefinition::SCHEMA_VALIDATION_FILE => \SMW_PHPUNIT_DIR . '/Fixtures/Schema/empty_schema.json'
];

$this->assertEmpty(
Expand Down Expand Up @@ -93,7 +93,7 @@ public function testValidate_Error() {
$instance = new SchemaValidator( $jsonSchemaValidator );

$info = [
SchemaDefinition::SCHEMA_VALIDATION_FILE => SMW_PHPUNIT_DIR . '/Fixtures/Schema/empty_schema.json'
SchemaDefinition::SCHEMA_VALIDATION_FILE => \SMW_PHPUNIT_DIR . '/Fixtures/Schema/empty_schema.json'
];

$this->assertNotEmpty(
Expand Down
6 changes: 0 additions & 6 deletions tests/phpunit/SetupCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ class SetupCheckTest extends \PHPUnit\Framework\TestCase {
protected function setUp(): void {
parent::setUp();

// Don't know why this is undefined but it is required by
// testReadFromFile_InvalidJSON_ThrowsException()
if ( !defined( 'SMW_PHPUNIT_DIR' ) ) {
define( 'SMW_PHPUNIT_DIR', __DIR__ );
}

$this->setupFile = $this->getMockBuilder( '\SMW\SetupFile' )
->disableOriginalConstructor()
->getMock();
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Structure/PHPUnitCheckRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PHPUnitCheckRunnerTest extends \PHPUnit\Framework\TestCase {

public static function setUpBeforeClass(): void {
$fileFetcher = new FileFetcher(
SMW_PHPUNIT_DIR
\SMW_PHPUNIT_DIR
);

self::$iterator = $fileFetcher->findByExtension( 'php' );
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/Utils/TemplateEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testCode_ThrowsException() {
}

public function testLoad() {
$instance = new TemplateEngine( SMW_PHPUNIT_DIR );
$instance = new TemplateEngine( \SMW_PHPUNIT_DIR );
$instance->load( '/Fixtures/readable.file', 'Foo' );

$instance->compile( 'Foo', [] );
Expand All @@ -45,7 +45,7 @@ public function testLoad() {
}

public function testBulkLoad() {
$instance = new TemplateEngine( SMW_PHPUNIT_DIR );
$instance = new TemplateEngine( \SMW_PHPUNIT_DIR );
$instance->clearTemplates();

$instance->bulkLoad( [ '/Fixtures/readable.file' => 'Foo' ] );
Expand All @@ -58,7 +58,7 @@ public function testBulkLoad() {
}

public function testHtmlTidy() {
$instance = new TemplateEngine( SMW_PHPUNIT_DIR );
$instance = new TemplateEngine( \SMW_PHPUNIT_DIR );
$instance->clearTemplates();

$instance->setContents( __METHOD__, "{{foo}}<span>\n </span>" );
Expand Down

0 comments on commit a0b2b45

Please sign in to comment.