X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Flibs%2Fobjectcache%2FMultiWriteBagOStuffTest.php;h=4a9f6cc9aca5341c3fe701b6acb8a5b33c29449d;hb=cf0ebed65ad14dc9a48b0d69e0d77fc5f4f83e92;hp=6df74d6c39d0ded9618741d6a9b6a9e99e954f64;hpb=4b73a8b6fbb6da651af850a7d667e6e8d59e6fce;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php b/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php index 6df74d6c39..4a9f6cc9ac 100644 --- a/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php +++ b/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php @@ -23,6 +23,10 @@ class MultiWriteBagOStuffTest extends MediaWikiTestCase { ] ); } + /** + * @covers MultiWriteBagOStuff::set + * @covers MultiWriteBagOStuff::doWrite + */ public function testSetImmediate() { $key = wfRandomString(); $value = wfRandomString(); @@ -34,6 +38,9 @@ class MultiWriteBagOStuffTest extends MediaWikiTestCase { $this->assertEquals( $value, $this->cache2->get( $key ), 'Written to tier 2' ); } + /** + * @covers MultiWriteBagOStuff + */ public function testSyncMerge() { $key = wfRandomString(); $value = wfRandomString(); @@ -69,23 +76,65 @@ class MultiWriteBagOStuffTest extends MediaWikiTestCase { $dbw->commit(); } + /** + * @covers MultiWriteBagOStuff::set + */ public function testSetDelayed() { $key = wfRandomString(); - $value = wfRandomString(); + $value = (object)[ 'v' => wfRandomString() ]; + $expectValue = clone $value; // XXX: DeferredUpdates bound to transactions in CLI mode $dbw = wfGetDB( DB_MASTER ); $dbw->begin(); $this->cache->set( $key, $value ); + // Test that later changes to $value don't affect the saved value (e.g. T168040) + $value->v = 'bogus'; + // Set in tier 1 - $this->assertEquals( $value, $this->cache1->get( $key ), 'Written to tier 1' ); + $this->assertEquals( $expectValue, $this->cache1->get( $key ), 'Written to tier 1' ); // Not yet set in tier 2 $this->assertEquals( false, $this->cache2->get( $key ), 'Not written to tier 2' ); $dbw->commit(); // Set in tier 2 - $this->assertEquals( $value, $this->cache2->get( $key ), 'Written to tier 2' ); + $this->assertEquals( $expectValue, $this->cache2->get( $key ), 'Written to tier 2' ); + } + + /** + * @covers MultiWriteBagOStuff::makeKey + */ + public function testMakeKey() { + $cache1 = $this->getMockBuilder( HashBagOStuff::class ) + ->setMethods( [ 'makeKey' ] )->getMock(); + $cache1->expects( $this->once() )->method( 'makeKey' ) + ->willReturn( 'special' ); + + $cache2 = $this->getMockBuilder( HashBagOStuff::class ) + ->setMethods( [ 'makeKey' ] )->getMock(); + $cache2->expects( $this->never() )->method( 'makeKey' ); + + $cache = new MultiWriteBagOStuff( [ 'caches' => [ $cache1, $cache2 ] ] ); + $this->assertSame( 'special', $cache->makeKey( 'a', 'b' ) ); + } + + /** + * @covers MultiWriteBagOStuff::makeGlobalKey + */ + public function testMakeGlobalKey() { + $cache1 = $this->getMockBuilder( HashBagOStuff::class ) + ->setMethods( [ 'makeGlobalKey' ] )->getMock(); + $cache1->expects( $this->once() )->method( 'makeGlobalKey' ) + ->willReturn( 'special' ); + + $cache2 = $this->getMockBuilder( HashBagOStuff::class ) + ->setMethods( [ 'makeGlobalKey' ] )->getMock(); + $cache2->expects( $this->never() )->method( 'makeGlobalKey' ); + + $cache = new MultiWriteBagOStuff( [ 'caches' => [ $cache1, $cache2 ] ] ); + + $this->assertSame( 'special', $cache->makeGlobalKey( 'a', 'b' ) ); } }