X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fdeferred%2FCdnCacheUpdateTest.php;h=2eaa5e2f49128e6ee0ba13a46478fd5bb0f39d28;hb=7c07aa3f730daaade60e5546c2a7b3979382edde;hp=de77ad5071883bfa19a521a1c0fd93d14fbef715;hpb=640892e0fd6e4acc0407f84d81dc7bf9b651592f;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/deferred/CdnCacheUpdateTest.php b/tests/phpunit/includes/deferred/CdnCacheUpdateTest.php index de77ad5071..2eaa5e2f49 100644 --- a/tests/phpunit/includes/deferred/CdnCacheUpdateTest.php +++ b/tests/phpunit/includes/deferred/CdnCacheUpdateTest.php @@ -1,25 +1,58 @@ setMwGlobals( 'wgCommandLineMode', false ); - $urls1 = array(); + $urls1 = []; $title = Title::newMainPage(); $urls1[] = $title->getCanonicalURL( '?x=1' ); $urls1[] = $title->getCanonicalURL( '?x=2' ); $urls1[] = $title->getCanonicalURL( '?x=3' ); - $update1 = new CdnCacheUpdate( $urls1 ); + $update1 = $this->newCdnCacheUpdate( $urls1 ); DeferredUpdates::addUpdate( $update1 ); - $urls2 = array(); + $urls2 = []; $urls2[] = $title->getCanonicalURL( '?x=2' ); $urls2[] = $title->getCanonicalURL( '?x=3' ); $urls2[] = $title->getCanonicalURL( '?x=4' ); - $update2 = new CdnCacheUpdate( $urls2 ); + $update2 = $this->newCdnCacheUpdate( $urls2 ); DeferredUpdates::addUpdate( $update2 ); $wrapper = TestingAccessWrapper::newFromObject( $update1 ); $this->assertEquals( array_merge( $urls1, $urls2 ), $wrapper->urls ); + + $update = null; + DeferredUpdates::clearPendingUpdates(); + DeferredUpdates::addCallableUpdate( function () use ( $urls1, $urls2, &$update ) { + $update = $this->newCdnCacheUpdate( $urls1 ); + DeferredUpdates::addUpdate( $update ); + DeferredUpdates::addUpdate( $this->newCdnCacheUpdate( $urls2 ) ); + DeferredUpdates::addUpdate( + $this->newCdnCacheUpdate( $urls2 ), DeferredUpdates::PRESEND ); + } ); + DeferredUpdates::doUpdates(); + + $wrapper = TestingAccessWrapper::newFromObject( $update ); + $this->assertEquals( array_merge( $urls1, $urls2 ), $wrapper->urls ); + + $this->assertEquals( DeferredUpdates::pendingUpdatesCount(), 0, 'PRESEND update run' ); + } + + /** + * @param array $urls + * @return CdnCacheUpdate + */ + private function newCdnCacheUpdate( array $urls ) { + return $this->getMockBuilder( CdnCacheUpdate::class ) + ->setConstructorArgs( [ $urls ] ) + ->setMethods( [ 'doUpdate' ] ) + ->getMock(); } }