createMock( ILoadBalancer::class ) ); $this->addToAssertionCount( 1 ); } public function testDoQuery() { // Create a row in the category table $this->editPage( new TitleValue( NS_MAIN, 'CategoryTreeCategoryCacheTest' ), '[[Category:Exists]]' ); $categoryCache = TestingAccessWrapper::newFromObject( $this->getServiceContainer()->get( 'CategoryTree.CategoryCache' ) ); $categoryCache->doQuery( [ new TitleValue( NS_CATEGORY, 'Exists' ), new TitleValue( NS_CATEGORY, 'Missed' ), ] ); $this->assertCount( 2, $categoryCache->cache ); $this->assertArrayHasKey( 'Exists', $categoryCache->cache ); $this->assertInstanceOf( Category::class, $categoryCache->cache['Exists'] ); $this->assertArrayHasKey( 'Missed', $categoryCache->cache ); $this->assertNull( $categoryCache->cache['Missed'] ); } public function testGetCategory() { // Create a row in the category table $this->editPage( new TitleValue( NS_MAIN, 'CategoryTreeCategoryCacheTest' ), '[[Category:Exists]]' ); $categoryCache = TestingAccessWrapper::newFromObject( $this->getServiceContainer()->get( 'CategoryTree.CategoryCache' ) ); $title = new TitleValue( NS_CATEGORY, 'Exists' ); // Test for cache miss $this->assertCount( 0, $categoryCache->cache ); $this->assertInstanceOf( Category::class, $categoryCache->getCategory( $title ) ); $this->assertCount( 1, $categoryCache->cache ); // Test normal access $this->assertInstanceOf( Category::class, $categoryCache->getCategory( $title ) ); } }