Replace new stdClass with more compact array syntax

It does the exact same. The resulting object is still an stdClass
instance.

Change-Id: Ief68609943ee30aa95732d24021c921dfbad166c
This commit is contained in:
Thiemo Kreuz 2021-11-02 08:59:20 +01:00 committed by Thiemo Kreuz (WMDE)
parent 0bfe17ad12
commit ee0f97378b
5 changed files with 14 additions and 14 deletions

View file

@ -477,7 +477,7 @@ class FileTest extends MediaWikiMediaTestCase {
* @covers File::getHandlerState
*/
public function testSetHandlerState() {
$obj = new stdClass;
$obj = (object)[];
$file = new class extends File {
public function __construct() {
}

View file

@ -5,7 +5,6 @@ namespace MediaWiki\Tests\User;
use MediaWiki\User\UserGroupManager;
use MediaWiki\User\UserGroupManagerFactory;
use MediaWikiIntegrationTestCase;
use stdClass;
use UserRightsProxy;
use Wikimedia\Rdbms\ILoadBalancer;
use Wikimedia\Rdbms\LBFactory;
@ -27,9 +26,10 @@ class UserRightsProxyTest extends MediaWikiIntegrationTestCase {
$dbMock = $this->createMock( MaintainableDBConnRef::class );
$row = new stdClass;
$row->user_name = 'UserRightsProxyTest';
$row->user_id = 12345;
$row = (object)[
'user_name' => 'UserRightsProxyTest',
'user_id' => 12345,
];
$dbMock->method( 'selectRow' )->willReturn( $row );
$lbMock = $this->createMock( ILoadBalancer::class );
@ -138,7 +138,7 @@ class UserRightsProxyTest extends MediaWikiIntegrationTestCase {
$userGroupManagerMock
->expects( $this->once() )
->method( 'getUserGroupMemberships' )
->willReturn( [ 'bot' => new stdClass, 'sysop' => new stdClass ] );
->willReturn( [ 'bot' => (object)[], 'sysop' => (object)[] ] );
$userGroupManagerFactoryMock = $this->createMock( UserGroupManagerFactory::class );
$userGroupManagerFactoryMock
->method( 'getUserGroupManager' )
@ -161,7 +161,7 @@ class UserRightsProxyTest extends MediaWikiIntegrationTestCase {
$userGroupManagerMock2
->expects( $this->exactly( 2 ) )
->method( 'getUserGroupMemberships' )
->willReturn( [ 'bot' => new stdClass ] );
->willReturn( [ 'bot' => (object)[] ] );
$userGroupManagerFactoryMock2 = $this->createMock( UserGroupManagerFactory::class );
$userGroupManagerFactoryMock2
->method( 'getUserGroupManager' )
@ -184,9 +184,10 @@ class UserRightsProxyTest extends MediaWikiIntegrationTestCase {
$value = 'bar';
$dbMock = $this->createMock( MaintainableDBConnRef::class );
$row = new stdClass;
$row->user_name = 'UserRightsProxyTest';
$row->user_id = 12345;
$row = (object)[
'user_name' => 'UserRightsProxyTest',
'user_id' => 12345,
];
$dbMock->method( 'selectRow' )->willReturn( $row );
$dbMock->method( 'timestamp' )->willReturn( 'timestamp' );
$dbMock->method( 'getDomainID' )->willReturn( 'foowiki' );

View file

@ -8,7 +8,6 @@ use JsonSerializable;
use MediaWiki\Json\JsonCodec;
use MediaWiki\Json\JsonConstants;
use MediaWikiUnitTestCase;
use stdClass;
use Title;
use Wikimedia\Assert\PreconditionException;
@ -136,7 +135,7 @@ class JsonCodecTest extends MediaWikiUnitTestCase {
yield 'Null' => [ null, true, null ];
yield 'Class' => [ $classInstance, false, '$' ];
yield 'Empty array' => [ [], true, null ];
yield 'Empty stdClass' => [ new stdClass(), true, null ];
yield 'Empty stdClass' => [ (object)[], true, null ];
yield 'Non-empty array' => [ [ 1, 2, 3 ], true, null ];
yield 'Non-empty map' => [ [ 'a' => 'b' ], true, null ];
yield 'Nested, serializable' => [ [ 'a' => [ 'b' => [ 'c' => 'd' ] ] ], true, null ];

View file

@ -5,7 +5,7 @@
*/
class TrivialMediaHandlerStateTest extends MediaWikiUnitTestCase {
public function testSetHandlerState() {
$obj = new stdClass;
$obj = (object)[];
$state = new TrivialMediaHandlerState;
$this->assertNull( $state->getHandlerState( 'test' ) );
$state->setHandlerState( 'test', $obj );

View file

@ -90,7 +90,7 @@ class SkinFactoryTest extends \MediaWikiUnitTestCase {
* @covers SkinFactory::makeSkin
*/
public function testMakeSkinWithValidSpec() {
$serviceInstance = new stdClass();
$serviceInstance = (object)[];
$serviceContainer = $this->createMock( ContainerInterface::class );
$serviceContainer->method( 'has' )->willReturn( true );