* DeprecatedHooksTest: Don't use assertContains().
* Replace uses of deprecated asserts:
- assertFileNotExists() -> assertFileDoesNotExist()
* Update hierarchy of MediaWikiPHPUnitResultPrinter, since ResultPrinter
is an interface in PHPUnit 9.
* Remove temporary forward-compat methods.
* Remove directories that don't exist from tests/phpunit/suite.xml, since
they now make PHPUnit exit:
- tests/phpunit/skins, it used to have SideBarTest, then moved to
tests/phpunit/includes/skins
- tests/phpunit/documentation, it used to have ReleaseNotesTest, then
moved to tests/phpunit/unit/documentation
* Update configuration with --migrate-configuration and reformat.
* Avoid redefining getMockBuilder() in
ActionModuleBasedHandlerTestTrait, use a @method annotation instead.
* In RCCacheEntryFactoryTest, avoid using internal PHPUnit logic for
HTML validation, and use native PHP methods instead. The code was
copied from Xml::load (moved to \Xml\Loader::load in PHPUnit 9) and
simplified for this use case.
Bug: T243600
Bug: T262076
Change-Id: I851b9158b73d0cfc315eed9d63b15c54b05895e3
98 lines
3 KiB
PHP
98 lines
3 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\HookContainer;
|
|
|
|
use MediaWikiUnitTestCase;
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
class DeprecatedHooksTest extends MediaWikiUnitTestCase {
|
|
|
|
/**
|
|
* @covers \MediaWiki\HookContainer\DeprecatedHooks::__construct
|
|
* @covers \MediaWiki\HookContainer\DeprecatedHooks::isHookDeprecated
|
|
*/
|
|
public function testIsHookDeprecated() {
|
|
$extDeprecatedHooks = [
|
|
'FooBaz' => [ 'deprecatedVersion' => '1.35', 'component' => 'ComponentFooBaz' ]
|
|
];
|
|
$deprecatedHooks = new DeprecatedHooks( $extDeprecatedHooks );
|
|
$this->assertTrue( $deprecatedHooks->isHookDeprecated( 'FooBaz' ) );
|
|
$this->assertFalse( $deprecatedHooks->isHookDeprecated( 'FooBazBar' ) );
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\HookContainer\DeprecatedHooks::markDeprecated
|
|
*/
|
|
public function testMarkDeprecatedException() {
|
|
$extDeprecatedHooks = [
|
|
'FooBaz' => [ 'deprecatedVersion' => '1.35', 'component' => 'ComponentFooBaz' ]
|
|
];
|
|
$deprecatedHooks = new DeprecatedHooks( $extDeprecatedHooks );
|
|
$this->expectExceptionMessage(
|
|
"Cannot mark hook 'FooBaz' deprecated with version 1.31. " .
|
|
"It is already marked deprecated with version 1.35"
|
|
);
|
|
$deprecatedHooks->markDeprecated( 'FooBaz', '1.31' );
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\HookContainer\DeprecatedHooks::markDeprecated
|
|
*/
|
|
public function testMarkDeprecated() {
|
|
$deprecatedHooks = new DeprecatedHooks();
|
|
$deprecatedHooks->markDeprecated( 'FooBaz', '1.31', 'ComponentFooBaz' );
|
|
$allDeprecated = $deprecatedHooks->getDeprecationInfo();
|
|
$this->assertArrayHasKey( 'FooBaz', $allDeprecated );
|
|
$this->assertEquals(
|
|
[
|
|
'deprecatedVersion' => '1.31',
|
|
'component' => 'ComponentFooBaz',
|
|
'silent' => false
|
|
],
|
|
$allDeprecated['FooBaz']
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\HookContainer\DeprecatedHooks::getDeprecationInfo
|
|
*/
|
|
public function testGetDeprecationInfo() {
|
|
$extDeprecatedHooks = [
|
|
'FooBar' => [ 'deprecatedVersion' => '1.21', 'component' => 'ComponentFooBar' ],
|
|
'FooBarBaz' => [ 'deprecatedVersion' => '1.21' ],
|
|
'SoftlyDeprecated' => [
|
|
'deprecatedVersion' => '1.21',
|
|
'component' => 'ComponentFooBar',
|
|
'silent' => true
|
|
]
|
|
];
|
|
$deprecatedHooksWrapper = TestingAccessWrapper::newFromObject( new DeprecatedHooks() );
|
|
$preRegisteredDeprecated = $deprecatedHooksWrapper->deprecatedHooks;
|
|
$deprecatedHooks = new DeprecatedHooks( $extDeprecatedHooks );
|
|
$hookDeprecationInfo = $deprecatedHooks->getDeprecationInfo( 'FooBar' );
|
|
|
|
$this->assertNull( $deprecatedHooks->getDeprecationInfo( 'FooBazBaz' ) );
|
|
$this->assertEquals(
|
|
$hookDeprecationInfo,
|
|
[
|
|
'deprecatedVersion' => '1.21',
|
|
'component' => 'ComponentFooBar',
|
|
'silent' => false,
|
|
]
|
|
);
|
|
|
|
$this->assertEquals(
|
|
$deprecatedHooks->getDeprecationInfo( 'SoftlyDeprecated' ),
|
|
[
|
|
'deprecatedVersion' => '1.21',
|
|
'component' => 'ComponentFooBar',
|
|
'silent' => true,
|
|
]
|
|
);
|
|
|
|
$this->assertCount(
|
|
count( $preRegisteredDeprecated ) + count( $extDeprecatedHooks ),
|
|
$deprecatedHooks->getDeprecationInfo()
|
|
);
|
|
}
|
|
}
|