Skip to content

Commit

Permalink
phpunit: Fix trivial dynamic property usages in tests
Browse files Browse the repository at this point in the history
Dynamic property creation is deprecated in PHP 8.2 (E_DEPRECATED).
Migrate some trivial cases in tests to use explicitly declared fields
instead, and remove the unused lastLog field from
MediaWikiLoggerPHPUnitExtension.

Notably this does not yet address MediaWikiIntegrationTestCase using
dynamic properties to associate ephemeral data with DB connections used
for tests.

Bug: T314099
Change-Id: I55453c0d254012b69c6843c54cfa8345fa5744fa
  • Loading branch information
mszabo-wikia committed Jul 28, 2022
1 parent 816897e commit 85017a3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
1 change: 0 additions & 1 deletion tests/phpunit/MediaWikiLoggerPHPUnitExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class MediaWikiLoggerPHPUnitExtension implements
* @inheritDoc
*/
public function executeBeforeTest( string $test ): void {
$this->lastTestLogs = null;
$this->originalSpi = LoggerFactory::getProvider();
$this->spi = new LogCapturingSpi( $this->originalSpi );
LoggerFactory::registerProvider( $this->spi );
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/mocks/content/DummyContentForTesting.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class DummyContentForTesting extends AbstractContent {

public const MODEL_ID = "testing";

private $data;

public function __construct( $data ) {
parent::__construct( self::MODEL_ID );

Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/suites/ParserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct( $runner, $fileName, ParserTest $test, ParserTestMod
[ "$mode" ],
basename( $fileName ) . ': ' . $test->testName );
$this->ptTest = $test;
$this->ptTestMode = $mode;
$this->ptMode = $mode;
$this->ptRunner = $runner;
$this->skipMessage = $skipMessage;
}
Expand All @@ -60,10 +60,10 @@ public function testParse() {
$this->markTestSkipped( $this->skipMessage );
}
$this->ptRunner->getRecorder()->setTestCase( $this );
$result = $this->ptRunner->runTest( $this->ptTest, $this->ptTestMode );
$result = $this->ptRunner->runTest( $this->ptTest, $this->ptMode );
if ( $result === false ) {
// Test intentionally skipped.
$result = new ParserTestResult( $this->ptTest, $this->ptTestMode, "SKIP", "SKIP" );
$result = new ParserTestResult( $this->ptTest, $this->ptMode, "SKIP", "SKIP" );
}
$this->assertEquals( $result->expected, $result->actual );
}
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/suites/ParserTestTopLevelSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
class ParserTestTopLevelSuite extends TestSuite {
use SuiteEventsTrait;

/** @var PhpunitTestRecorder */
private $ptRecorder;

/** @var ParserTestRunner */
private $ptRunner;

Expand Down

0 comments on commit 85017a3

Please sign in to comment.