aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit
diff options
context:
space:
mode:
authorDaimona Eaytoy <daimona.wiki@gmail.com>2019-12-14 13:45:35 +0100
committerKrinkle <krinklemail@gmail.com>2019-12-15 00:27:54 +0000
commit7b946ffb4b7bdafa659941e6a73ea9d4b012df3f (patch)
treeae5a0dd06a2c4d8417aa149e6a869b9e70ffda90 /tests/phpunit
parent2e02e7fdb1a0439ea621104ccf6cc77dde3075c7 (diff)
downloadmediawikicore-7b946ffb4b7bdafa659941e6a73ea9d4b012df3f.tar.gz
mediawikicore-7b946ffb4b7bdafa659941e6a73ea9d4b012df3f.zip
Fixes for PHPUnit 8 compat in DB suite
Once again, this fixes all issues aside from assertArraySubset. Bug: T192167 Change-Id: I45c91dc1cf23f04140576dc66233558bb6021324
Diffstat (limited to 'tests/phpunit')
-rw-r--r--tests/phpunit/includes/GlobalFunctions/GlobalTest.php3
-rw-r--r--tests/phpunit/includes/OutputPageTest.php12
-rw-r--r--tests/phpunit/includes/RevisionDbTestBase.php2
-rw-r--r--tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php4
-rw-r--r--tests/phpunit/includes/Storage/PageUpdaterTest.php4
-rw-r--r--tests/phpunit/includes/api/ApiStashEditTest.php2
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryTest.php2
-rw-r--r--tests/phpunit/includes/auth/AuthManagerTest.php9
-rw-r--r--tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php4
-rw-r--r--tests/phpunit/includes/block/BlockManagerTest.php3
-rw-r--r--tests/phpunit/includes/parser/ParserMethodsTest.php4
-rw-r--r--tests/phpunit/includes/poolcounter/PoolWorkArticleViewTest.php2
-rw-r--r--tests/phpunit/includes/user/UserTest.php6
13 files changed, 30 insertions, 27 deletions
diff --git a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
index b7255dc6f33b..cfc98264a387 100644
--- a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
+++ b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
@@ -1,6 +1,7 @@
<?php
use MediaWiki\Logger\LegacyLogger;
+use Wikimedia\TestingAccessWrapper;
/**
* @group Database
@@ -702,7 +703,7 @@ class GlobalTest extends MediaWikiTestCase {
*/
public function testWfForeignMemcKey() {
$cache = ObjectCache::getLocalClusterInstance();
- $keyspace = $this->readAttribute( $cache, 'keyspace' );
+ $keyspace = TestingAccessWrapper::newFromObject( $cache )->keyspace;
$this->assertEquals(
wfForeignMemcKey( $keyspace, '', 'foo', 'bar' ),
$cache->makeKey( 'foo', 'bar' )
diff --git a/tests/phpunit/includes/OutputPageTest.php b/tests/phpunit/includes/OutputPageTest.php
index 97a6be8ade63..1e14f49ea16c 100644
--- a/tests/phpunit/includes/OutputPageTest.php
+++ b/tests/phpunit/includes/OutputPageTest.php
@@ -765,11 +765,11 @@ class OutputPageTest extends MediaWikiTestCase {
$str = OutputPage::buildBacklinkSubtitle( $title, $query )->text();
foreach ( $contains as $substr ) {
- $this->assertContains( $substr, $str );
+ $this->assertStringContainsString( $substr, $str );
}
foreach ( $notContains as $substr ) {
- $this->assertNotContains( $substr, $str );
+ $this->assertStringNotContainsString( $substr, $str );
}
}
@@ -791,11 +791,11 @@ class OutputPageTest extends MediaWikiTestCase {
$str = $op->getSubtitle();
foreach ( $contains as $substr ) {
- $this->assertContains( $substr, $str );
+ $this->assertStringContainsString( $substr, $str );
}
foreach ( $notContains as $substr ) {
- $this->assertNotContains( $substr, $str );
+ $this->assertStringNotContainsString( $substr, $str );
}
}
@@ -1207,10 +1207,10 @@ class OutputPageTest extends MediaWikiTestCase {
}
foreach ( $expectedNormal as $i => $name ) {
- $this->assertContains( $name, $catLinks['normal'][$i] );
+ $this->assertStringContainsString( $name, $catLinks['normal'][$i] );
}
foreach ( $expectedHidden as $i => $name ) {
- $this->assertContains( $name, $catLinks['hidden'][$i] );
+ $this->assertStringContainsString( $name, $catLinks['hidden'][$i] );
}
}
diff --git a/tests/phpunit/includes/RevisionDbTestBase.php b/tests/phpunit/includes/RevisionDbTestBase.php
index 637f65d4cd9a..0a78a18c57ce 100644
--- a/tests/phpunit/includes/RevisionDbTestBase.php
+++ b/tests/phpunit/includes/RevisionDbTestBase.php
@@ -1327,7 +1327,7 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
$this->assertIsString( $rev->getTimestamp() );
$this->assertTrue( strlen( $rev->getTimestamp() ) == strlen( 'YYYYMMDDHHMMSS' ) );
- $this->assertContains( substr( $testTimestamp, 0, 10 ), $rev->getTimestamp() );
+ $this->assertStringContainsString( substr( $testTimestamp, 0, 10 ), $rev->getTimestamp() );
}
/**
diff --git a/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php b/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php
index 7bb1504f1fad..0904a7e42de8 100644
--- a/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php
+++ b/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php
@@ -248,7 +248,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
$mainSlot->getContent()->serialize(),
'PST should apply.'
);
- $this->assertContains( $sysop->getName(), $mainSlot->getContent()->serialize() );
+ $this->assertStringContainsString( $sysop->getName(), $mainSlot->getContent()->serialize() );
$auxSlot = $updater->getRawSlot( 'aux' );
$this->assertInstanceOf( SlotRecord::class, $auxSlot );
@@ -304,7 +304,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
// parser-output for null-edit uses the original author's name
$html = $updater1->getRenderedRevision()->getRevisionParserOutput()->getText();
- $this->assertNotContains( $sysopName, $html, '{{REVISIONUSER}}' );
+ $this->assertStringNotContainsString( $sysopName, $html, '{{REVISIONUSER}}' );
$this->assertStringNotContainsString( '{{REVISIONUSER}}', $html, '{{REVISIONUSER}}' );
$this->assertStringNotContainsString( '~~~', $html, 'signature ~~~' );
$this->assertStringContainsString( '(' . $userName . ')', $html, '{{REVISIONUSER}}' );
diff --git a/tests/phpunit/includes/Storage/PageUpdaterTest.php b/tests/phpunit/includes/Storage/PageUpdaterTest.php
index 592d5e8cadd3..c2f7d8c700b6 100644
--- a/tests/phpunit/includes/Storage/PageUpdaterTest.php
+++ b/tests/phpunit/includes/Storage/PageUpdaterTest.php
@@ -612,10 +612,10 @@ class PageUpdaterTest extends MediaWikiTestCase {
$text = $rev->getContent( SlotRecord::MAIN )->serialize();
if ( $subst ) {
- $this->assertContains( $expected, $text, 'In Wikitext' );
+ $this->assertStringContainsString( $expected, $text, 'In Wikitext' );
}
- $this->assertContains( $expected, $html, 'In HTML' );
+ $this->assertStringContainsString( $expected, $html, 'In HTML' );
}
}
diff --git a/tests/phpunit/includes/api/ApiStashEditTest.php b/tests/phpunit/includes/api/ApiStashEditTest.php
index a5c39c4b50c9..d4842fd189c3 100644
--- a/tests/phpunit/includes/api/ApiStashEditTest.php
+++ b/tests/phpunit/includes/api/ApiStashEditTest.php
@@ -402,7 +402,7 @@ class ApiStashEditTest extends ApiTestCase {
$wrapper = TestingAccessWrapper::newFromObject( $cache );
- $this->assertEquals( $ttl, $wrapper->bag[$key][HashBagOStuff::KEY_EXP] - time(), '', 1 );
+ $this->assertEqualsWithDelta( $ttl, $wrapper->bag[$key][HashBagOStuff::KEY_EXP] - time(), 1 );
}
public function signatureProvider() {
diff --git a/tests/phpunit/includes/api/query/ApiQueryTest.php b/tests/phpunit/includes/api/query/ApiQueryTest.php
index 132f0db30460..7367fccdcf6c 100644
--- a/tests/phpunit/includes/api/query/ApiQueryTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryTest.php
@@ -170,6 +170,6 @@ class ApiQueryTest extends ApiTestCase {
$this->assertArrayHasKey( 'query', $data[0] );
$this->assertArrayHasKey( 'export', $data[0]['query'] );
// This response field contains an XML document even if no pages were exported
- $this->assertNotContains( $title->getPrefixedText(), $data[0]['query']['export'] );
+ $this->assertStringNotContainsString( $title->getPrefixedText(), $data[0]['query']['export'] );
}
}
diff --git a/tests/phpunit/includes/auth/AuthManagerTest.php b/tests/phpunit/includes/auth/AuthManagerTest.php
index 0ac5fffbc2ef..dca02f45b4bd 100644
--- a/tests/phpunit/includes/auth/AuthManagerTest.php
+++ b/tests/phpunit/includes/auth/AuthManagerTest.php
@@ -769,9 +769,12 @@ class AuthManagerTest extends \MediaWikiTestCase {
$this->assertSame( AuthenticationResponse::PASS, $ret->status );
$this->assertSame( $user->getName(), $ret->username );
$this->assertSame( $user->getId(), $this->request->getSessionData( 'AuthManager:lastAuthId' ) );
- $this->assertEquals(
- time(), $this->request->getSessionData( 'AuthManager:lastAuthTimestamp' ),
- 'timestamp ±1', 1
+ // FIXME: Avoid relying on implicit amounts of time elapsing.
+ $this->assertEqualsWithDelta(
+ time(),
+ $this->request->getSessionData( 'AuthManager:lastAuthTimestamp' ),
+ 1,
+ 'timestamp ±1'
);
$this->assertNull( $this->request->getSession()->getSecret( 'AuthManager::authnState' ) );
$this->assertSame( $user->getId(), $this->request->getSession()->getUser()->getId() );
diff --git a/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
index 18d7d8e32a74..5fc25edac6a3 100644
--- a/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
+++ b/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
@@ -576,7 +576,7 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestC
{
$mailed = true;
$this->assertSame( $user->getEmail(), $to[0]->address );
- $this->assertContains( $req->password, $body );
+ $this->assertStringContainsString( $req->password, $body );
return false;
} );
$provider->providerChangeAuthenticationData( $req );
@@ -707,7 +707,7 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestC
{
$mailed = true;
$this->assertSame( 'test@localhost.localdomain', $to[0]->address );
- $this->assertContains( $req->password, $body );
+ $this->assertStringContainsString( $req->password, $body );
return false;
} );
diff --git a/tests/phpunit/includes/block/BlockManagerTest.php b/tests/phpunit/includes/block/BlockManagerTest.php
index 28081239c340..28c7739324bb 100644
--- a/tests/phpunit/includes/block/BlockManagerTest.php
+++ b/tests/phpunit/includes/block/BlockManagerTest.php
@@ -493,10 +493,9 @@ class BlockManagerTest extends MediaWikiTestCase {
$blockManager->setBlockCookie( $block, $response );
$cookies = $response->getCookies();
- $this->assertEquals(
+ $this->assertEqualsWithDelta(
$now + $expectedExpiryDelta,
$cookies['BlockID']['expire'],
- '',
60 // Allow actual to be up to 60 seconds later than expected
);
}
diff --git a/tests/phpunit/includes/parser/ParserMethodsTest.php b/tests/phpunit/includes/parser/ParserMethodsTest.php
index 86ba287f50da..7f8e4a66fcba 100644
--- a/tests/phpunit/includes/parser/ParserMethodsTest.php
+++ b/tests/phpunit/includes/parser/ParserMethodsTest.php
@@ -371,11 +371,11 @@ class ParserMethodsTest extends MediaWikiLangTestCase {
$parser->parse( $text, $title, $po, true, true, $revId );
$html = $parser->getOutput()->getText();
- $this->assertContains( $expectedInHtml, $html, 'In HTML' );
+ $this->assertStringContainsString( $expectedInHtml, $html, 'In HTML' );
if ( $expectedInPst !== null ) {
$pst = $parser->preSaveTransform( $text, $title, $po->getUser(), $po );
- $this->assertContains( $expectedInPst, $pst, 'After Pre-Safe Transform' );
+ $this->assertStringContainsString( $expectedInPst, $pst, 'After Pre-Safe Transform' );
}
}
diff --git a/tests/phpunit/includes/poolcounter/PoolWorkArticleViewTest.php b/tests/phpunit/includes/poolcounter/PoolWorkArticleViewTest.php
index 82477fd0f0e7..e59e3f047bd7 100644
--- a/tests/phpunit/includes/poolcounter/PoolWorkArticleViewTest.php
+++ b/tests/phpunit/includes/poolcounter/PoolWorkArticleViewTest.php
@@ -137,7 +137,7 @@ class PoolWorkArticleViewTest extends MediaWikiTestCase {
$expected = strval( $callback( $rev ) );
$output = $work->getParserOutput();
- $this->assertContains( $expected, $output->getText() );
+ $this->assertStringContainsString( $expected, $output->getText() );
}
public function testDoWorkMissingPage() {
diff --git a/tests/phpunit/includes/user/UserTest.php b/tests/phpunit/includes/user/UserTest.php
index a968ba44e0b5..1d1d9fac6328 100644
--- a/tests/phpunit/includes/user/UserTest.php
+++ b/tests/phpunit/includes/user/UserTest.php
@@ -848,11 +848,11 @@ class UserTest extends MediaWikiTestCase {
$this->assertArrayHasKey( 'wm_infinite_blockBlockID', $cookies );
$expOneDay = wfTimestamp() + ( 24 * 60 * 60 );
// Check for expiry dates in a 10-second window, to account for slow testing.
- $this->assertEquals(
+ $this->assertEqualsWithDelta(
$expOneDay,
$cookies['wm_infinite_blockBlockID']['expire'],
- 'Expiry date',
- 5.0
+ 5.0,
+ 'Expiry date'
);
// 3. Change the block's expiry (to 2 hours), and the cookie's should be changed also.