From 46e5b28e3f1f750a7b9172679b88fcc51700247c Mon Sep 17 00:00:00 2001 From: Stephane Bisson Date: Thu, 7 Mar 2019 16:18:22 -0500 Subject: [PATCH] UserTest: correctly reset fake time Change-Id: I5fc64506781fbc40e81719aa03441643c38d4e54 Follows-Up: Ica3e6e7165496bdc9b8f12972cf93847ecfffa50 Bug: T216631 --- tests/phpunit/includes/user/UserTest.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/includes/user/UserTest.php b/tests/phpunit/includes/user/UserTest.php index dad7bf29e1..164b46644d 100644 --- a/tests/phpunit/includes/user/UserTest.php +++ b/tests/phpunit/includes/user/UserTest.php @@ -1472,14 +1472,18 @@ class UserTest extends MediaWikiTestCase { MWTimestamp::setFakeTime( function () use ( &$clock ) { return $clock += 1000; } ); - $user = $this->getTestUser()->getUser(); - $firstRevision = self::makeEdit( $user, 'Help:UserTest_GetEditTimestamp', 'one', 'test' ); - $secondRevision = self::makeEdit( $user, 'Help:UserTest_GetEditTimestamp', 'two', 'test' ); - // Sanity check: revisions timestamp are different - $this->assertNotEquals( $firstRevision->getTimestamp(), $secondRevision->getTimestamp() ); - - $this->assertEquals( $firstRevision->getTimestamp(), $user->getFirstEditTimestamp() ); - $this->assertEquals( $secondRevision->getTimestamp(), $user->getLatestEditTimestamp() ); + try { + $user = $this->getTestUser()->getUser(); + $firstRevision = self::makeEdit( $user, 'Help:UserTest_GetEditTimestamp', 'one', 'test' ); + $secondRevision = self::makeEdit( $user, 'Help:UserTest_GetEditTimestamp', 'two', 'test' ); + // Sanity check: revisions timestamp are different + $this->assertNotEquals( $firstRevision->getTimestamp(), $secondRevision->getTimestamp() ); + + $this->assertEquals( $firstRevision->getTimestamp(), $user->getFirstEditTimestamp() ); + $this->assertEquals( $secondRevision->getTimestamp(), $user->getLatestEditTimestamp() ); + } finally { + MWTimestamp::setFakeTime( false ); + } } /** -- 2.20.1