This is just a shortcut for a commonly-used pattern, when you want to
create a mock that's never supposed to have methods called.
Change-Id: Ia7267e3d3108c1ff94485f7e44bf409808a762be
...array_map( [ $this, 'matches' ], $values )
) );
}
...array_map( [ $this, 'matches' ], $values )
) );
}
+
+ /**
+ * Return a PHPUnit mock that is expected to never have any methods called on it.
+ *
+ * @param string $type
+ * @return object
+ */
+ protected function createNoOpMock( $type ) {
+ $mock = $this->createMock( $type );
+ $mock->expects( $this->never() )->method( $this->anything() );
+ return $mock;
+ }
* @group Database
*/
class MovePageTest extends MediaWikiTestCase {
* @group Database
*/
class MovePageTest extends MediaWikiTestCase {
- /**
- * @param string $class
- * @return object A mock that throws on any method call
- */
- private function getNoOpMock( $class ) {
- $mock = $this->createMock( $class );
- $mock->expects( $this->never() )->method( $this->anythingBut( '__destruct' ) );
- return $mock;
- }
-
/**
* The only files that exist are 'File:Existent.jpg', 'File:Existent2.jpg', and
* 'File:Existent-file-no-page.jpg'. Calling unexpected methods causes a test failure.
/**
* The only files that exist are 'File:Existent.jpg', 'File:Existent2.jpg', and
* 'File:Existent-file-no-page.jpg'. Calling unexpected methods causes a test failure.
private function newMovePage( $old, $new, array $params = [] ) : MovePage {
$mockLB = $this->createMock( LoadBalancer::class );
$mockLB->method( 'getConnection' )
private function newMovePage( $old, $new, array $params = [] ) : MovePage {
$mockLB = $this->createMock( LoadBalancer::class );
$mockLB->method( 'getConnection' )
- ->willReturn( $params['db'] ?? $this->getNoOpMock( IDatabase::class ) );
+ ->willReturn( $params['db'] ?? $this->createNoOpMock( IDatabase::class ) );
$mockLB->expects( $this->never() )
->method( $this->anythingBut( 'getConnection', '__destruct' ) );
$mockLB->expects( $this->never() )
->method( $this->anythingBut( 'getConnection', '__destruct' ) );
),
$mockLB,
$params['nsInfo'] ?? $mockNsInfo,
),
$mockLB,
$params['nsInfo'] ?? $mockNsInfo,
- $params['wiStore'] ?? $this->getNoOpMock( WatchedItemStore::class ),
- $params['permMgr'] ?? $this->getNoOpMock( PermissionManager::class ),
+ $params['wiStore'] ?? $this->createNoOpMock( WatchedItemStore::class ),
+ $params['permMgr'] ?? $this->createNoOpMock( PermissionManager::class ),
$params['repoGroup'] ?? $this->getMockRepoGroup()
);
}
$params['repoGroup'] ?? $this->getMockRepoGroup()
);
}
new WatchedItem( $user, $targets[0], '20151212010101' ),
new WatchedItem( $user, $targets[1], null ),
];
new WatchedItem( $user, $targets[0], '20151212010101' ),
new WatchedItem( $user, $targets[1], null ),
];
- $mockDb = $this->getMockDb();
- $mockDb->expects( $this->never() )->method( $this->anything() );
+ $mockDb = $this->createNoOpMock( IDatabase::class );
$mockCache = $this->getMockCache();
$mockCache->expects( $this->at( 1 ) )
$mockCache = $this->getMockCache();
$mockCache->expects( $this->at( 1 ) )
}
public function testGetNotificationTimestampsBatch_anonymousUser() {
}
public function testGetNotificationTimestampsBatch_anonymousUser() {
+ if ( defined( 'HHVM_VERSION' ) ) {
+ $this->markTestSkipped( 'HHVM Reflection buggy' );
+ }
+
$targets = [
new TitleValue( 0, 'SomeDbKey' ),
new TitleValue( 1, 'AnotherDbKey' ),
];
$targets = [
new TitleValue( 0, 'SomeDbKey' ),
new TitleValue( 1, 'AnotherDbKey' ),
];
- $mockDb = $this->getMockDb();
- $mockDb->expects( $this->never() )->method( $this->anything() );
+ $mockDb = $this->createNoOpMock( IDatabase::class );
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( $this->anything() );
+ $mockCache = $this->createNoOpMock( HashBagOStuff::class );
$store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$mockQueueGroup = $this->getMockJobQueueGroup();
$mockQueueGroup = $this->getMockJobQueueGroup();
- $mockRevisionRecord = $this->createMock( RevisionRecord::class );
- $mockRevisionRecord->expects( $this->never() )->method( $this->anything() );
+ $mockRevisionRecord = $this->createNoOpMock( RevisionRecord::class );
$mockRevisionLookup = $this->getMockRevisionLookup( [
'getTimestampFromId' => function () {
$mockRevisionLookup = $this->getMockRevisionLookup( [
'getTimestampFromId' => function () {
$oldid = 22;
$title = new TitleValue( 0, 'SomeDbKey' );
$oldid = 22;
$title = new TitleValue( 0, 'SomeDbKey' );
- $mockRevision = $this->createMock( RevisionRecord::class );
- $mockRevision->expects( $this->never() )->method( $this->anything() );
-
- $mockNextRevision = $this->createMock( RevisionRecord::class );
- $mockNextRevision->expects( $this->never() )->method( $this->anything() );
+ $mockRevision = $this->createNoOpMock( RevisionRecord::class );
+ $mockNextRevision = $this->createNoOpMock( RevisionRecord::class );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->once() )
$mockDb = $this->getMockDb();
$mockDb->expects( $this->once() )
$mockQueueGroup = $this->getMockJobQueueGroup();
$mockQueueGroup = $this->getMockJobQueueGroup();
- $mockRevision = $this->createMock( RevisionRecord::class );
- $mockRevision->expects( $this->never() )->method( $this->anything() );
-
- $mockNextRevision = $this->createMock( RevisionRecord::class );
- $mockNextRevision->expects( $this->never() )->method( $this->anything() );
+ $mockRevision = $this->createNoOpMock( RevisionRecord::class );
+ $mockNextRevision = $this->createNoOpMock( RevisionRecord::class );
$mockRevisionLookup = $this->getMockRevisionLookup(
[
$mockRevisionLookup = $this->getMockRevisionLookup(
[
$mockQueueGroup = $this->getMockJobQueueGroup();
$mockQueueGroup = $this->getMockJobQueueGroup();
- $mockRevision = $this->createMock( RevisionRecord::class );
- $mockRevision->expects( $this->never() )->method( $this->anything() );
-
- $mockNextRevision = $this->createMock( RevisionRecord::class );
- $mockNextRevision->expects( $this->never() )->method( $this->anything() );
+ $mockRevision = $this->createNoOpMock( RevisionRecord::class );
+ $mockNextRevision = $this->createNoOpMock( RevisionRecord::class );
$mockRevisionLookup = $this->getMockRevisionLookup(
[
$mockRevisionLookup = $this->getMockRevisionLookup(
[
$mockQueueGroup = $this->getMockJobQueueGroup();
$mockQueueGroup = $this->getMockJobQueueGroup();
- $mockRevision = $this->createMock( RevisionRecord::class );
- $mockRevision->expects( $this->never() )->method( $this->anything() );
-
- $mockNextRevision = $this->createMock( RevisionRecord::class );
- $mockNextRevision->expects( $this->never() )->method( $this->anything() );
+ $mockRevision = $this->createNoOpMock( RevisionRecord::class );
+ $mockNextRevision = $this->createNoOpMock( RevisionRecord::class );
$mockRevisionLookup = $this->getMockRevisionLookup(
[
$mockRevisionLookup = $this->getMockRevisionLookup(
[
*/
class LockManagerGroupFactoryTest extends MediaWikiUnitTestCase {
public function testGetLockManagerGroup() {
*/
class LockManagerGroupFactoryTest extends MediaWikiUnitTestCase {
public function testGetLockManagerGroup() {
- $mockLbFactory = $this->createMock( LBFactory::class );
- $mockLbFactory->expects( $this->never() )->method( $this->anything() );
+ $mockLbFactory = $this->createNoOpMock( LBFactory::class );
$factory = new LockManagerGroupFactory( 'defaultDomain', [], $mockLbFactory );
$lbmUnspecified = $factory->getLockManagerGroup();
$factory = new LockManagerGroupFactory( 'defaultDomain', [], $mockLbFactory );
$lbmUnspecified = $factory->getLockManagerGroup();