当前位置: 首页>>代码示例>>PHP>>正文


PHP CacheBackendInterface::expects方法代码示例

本文整理汇总了PHP中Drupal\Core\Cache\CacheBackendInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP CacheBackendInterface::expects方法的具体用法?PHP CacheBackendInterface::expects怎么用?PHP CacheBackendInterface::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Cache\CacheBackendInterface的用法示例。


在下文中一共展示了CacheBackendInterface::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testDestruct

 /**
  * Tests the destruct method.
  *
  * @covers ::destruct
  */
 public function testDestruct()
 {
     $this->libraryDiscoveryParser->expects($this->once())->method('buildByExtension')->with('test')->will($this->returnValue($this->libraryData));
     $lock_key = 'library_info:Drupal\\Core\\Cache\\CacheCollector';
     $this->lock->expects($this->once())->method('acquire')->with($lock_key)->will($this->returnValue(TRUE));
     $this->cache->expects($this->exactly(2))->method('get')->with('library_info')->will($this->returnValue(FALSE));
     $this->cache->expects($this->once())->method('set')->with('library_info', array('test' => $this->libraryData), Cache::PERMANENT, array('library_info'));
     $this->lock->expects($this->once())->method('release')->with($lock_key);
     // This should get data and persist the key.
     $this->libraryDiscoveryCollector->get('test');
     $this->libraryDiscoveryCollector->destruct();
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:17,代码来源:LibraryDiscoveryCollectorTest.php

示例2: testGetAliasByPathUncachedMissWithAlias

 /**
  * Tests the getAliasByPath cache with an unpreloaded path with alias.
  *
  * @covers ::getAliasByPath
  * @covers ::writeCache
  */
 public function testGetAliasByPathUncachedMissWithAlias()
 {
     $path_part1 = $this->randomMachineName();
     $path_part2 = $this->randomMachineName();
     $path = '/' . $path_part1 . '/' . $path_part2;
     $cached_path = $this->randomMachineName();
     $cached_no_alias_path = $this->randomMachineName();
     $cached_alias = $this->randomMachineName();
     $new_alias = $this->randomMachineName();
     $language = $this->setUpCurrentLanguage();
     $cached_paths = array($language->getId() => array($cached_path, $cached_no_alias_path));
     $this->cache->expects($this->once())->method('get')->with($this->cacheKey)->will($this->returnValue((object) array('data' => $cached_paths)));
     // Simulate a request so that the preloaded paths are fetched.
     $this->aliasManager->setCacheKey($this->path);
     $this->aliasWhitelist->expects($this->any())->method('get')->with($path_part1)->will($this->returnValue(TRUE));
     $this->aliasStorage->expects($this->once())->method('preloadPathAlias')->with($cached_paths[$language->getId()], $language->getId())->will($this->returnValue(array($cached_path => $cached_alias)));
     $this->aliasStorage->expects($this->once())->method('lookupPathAlias')->with($path, $language->getId())->will($this->returnValue($new_alias));
     $this->assertEquals($new_alias, $this->aliasManager->getAliasByPath($path));
     // Call it twice to test the static cache.
     $this->assertEquals($new_alias, $this->aliasManager->getAliasByPath($path));
     // There is already a cache entry, so this should not write out to the
     // cache.
     $this->cache->expects($this->never())->method('set');
     $this->aliasManager->writeCache();
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:31,代码来源:AliasManagerTest.php

示例3: testBuildTreeWithoutParameters

 /**
  * Tests buildTree with simple menu_name and no parameters.
  */
 public function testBuildTreeWithoutParameters()
 {
     $language = new Language(array('id' => 'en'));
     $this->languageManager->expects($this->any())->method('getCurrentLanguage')->will($this->returnValue($language));
     // Setup query and the query result.
     $query = $this->getMock('Drupal\\Core\\Entity\\Query\\QueryInterface');
     $this->entityQueryFactory->expects($this->once())->method('get')->with('menu_link')->will($this->returnValue($query));
     $query->expects($this->once())->method('condition')->with('menu_name', 'test_menu');
     $query->expects($this->once())->method('execute')->will($this->returnValue(array(1, 2, 3)));
     $storage = $this->getMock('Drupal\\Core\\Entity\\EntityStorageInterface');
     $base = array('access' => TRUE, 'weight' => 0, 'title' => 'title');
     $menu_link = $base + array('mlid' => 1, 'p1' => 3, 'p2' => 2, 'p3' => 1);
     $links[1] = $menu_link;
     $menu_link = $base + array('mlid' => 3, 'p1' => 3, 'depth' => 1);
     $links[3] = $menu_link;
     $menu_link = $base + array('mlid' => 2, 'p1' => 3, 'p2' => 2, 'depth' => 2);
     $links[2] = $menu_link;
     $storage->expects($this->once())->method('loadMultiple')->with(array(1, 2, 3))->will($this->returnValue($links));
     $this->menuTree->setStorage($storage);
     // Ensure that static/non static caching works.
     // First setup no working caching.
     $this->cacheBackend->expects($this->at(0))->method('get')->with('links:test_menu:tree-data:en:35786c7117b4e38d0f169239752ce71158266ae2f6e4aa230fbbb87bd699c0e3')->will($this->returnValue(FALSE));
     $this->cacheBackend->expects($this->at(1))->method('set')->with('links:test_menu:tree-data:en:35786c7117b4e38d0f169239752ce71158266ae2f6e4aa230fbbb87bd699c0e3', $this->anything(), Cache::PERMANENT, array('menu' => 'test_menu'));
     // Ensure that the static caching triggered.
     $this->cacheBackend->expects($this->exactly(1))->method('get');
     $this->menuTree->buildTree('test_menu');
     $this->menuTree->buildTree('test_menu');
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:31,代码来源:MenuTreeTest.php

示例4: testDisable

 /**
  * @covers ::disable
  * @depends testSetStatus
  */
 public function testDisable()
 {
     $this->cacheBackend->expects($this->once())->method('invalidateTags')->with(array($this->entityTypeId . ':' . $this->id));
     $this->entity->setStatus(TRUE);
     $this->assertSame($this->entity, $this->entity->disable());
     $this->assertFalse($this->entity->status());
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:11,代码来源:ConfigEntityBaseUnitTest.php

示例5: testGetInfo

 /**
  * Tests the getInfo method.
  *
  * @covers ::getInfo
  * @covers ::buildInfo
  *
  * @dataProvider providerTestGetInfo
  */
 public function testGetInfo($type, $expected_info, $element_info, callable $alter_callback = NULL)
 {
     $this->moduleHandler->expects($this->once())->method('invokeAll')->with('element_info')->will($this->returnValue($element_info));
     $this->moduleHandler->expects($this->once())->method('alter')->with('element_info', $this->anything())->will($this->returnCallback($alter_callback ?: function ($info) {
         return $info;
     }));
     $this->themeManager->expects($this->once())->method('getActiveTheme')->willReturn(new ActiveTheme(['name' => 'test']));
     $this->themeManager->expects($this->once())->method('alter')->with('element_info', $this->anything())->will($this->returnCallback($alter_callback ?: function ($info) {
         return $info;
     }));
     $this->cache->expects($this->at(0))->method('get')->with('element_info_build:test')->will($this->returnValue(FALSE));
     $this->cache->expects($this->at(1))->method('get')->with('element_info')->will($this->returnValue(FALSE));
     $this->cache->expects($this->at(2))->method('set')->with('element_info');
     $this->cache->expects($this->at(3))->method('set')->with('element_info_build:test');
     $this->assertEquals($expected_info, $this->elementInfo->getInfo($type));
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:24,代码来源:ElementInfoManagerTest.php

示例6: testDeleteNothing

 /**
  * @covers ::delete()
  * @covers ::doDelete()
  */
 public function testDeleteNothing()
 {
     $this->moduleHandler->expects($this->never())->method($this->anything());
     $this->configFactory->expects($this->never())->method('get');
     $this->cacheBackend->expects($this->never())->method('invalidateTags');
     $this->entityStorage->delete(array());
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:11,代码来源:ConfigEntityStorageTest.php

示例7: testGetAliasByPathUncachedMissWithAlias

 /**
  * Tests the getAliasByPath cache with an unpreloaded path with alias.
  *
  * @covers ::getAliasByPath
  * @covers ::writeCache
  */
 public function testGetAliasByPathUncachedMissWithAlias()
 {
     $path_part1 = $this->randomMachineName();
     $path_part2 = $this->randomMachineName();
     $path = $path_part1 . '/' . $path_part2;
     $cached_path = $this->randomMachineName();
     $cached_no_alias_path = $this->randomMachineName();
     $cached_alias = $this->randomMachineName();
     $new_alias = $this->randomMachineName();
     $language = $this->setUpCurrentLanguage();
     $cached_paths = array($language->getId() => array($cached_path, $cached_no_alias_path));
     $this->cache->expects($this->once())->method('get')->with($this->cacheKey)->will($this->returnValue((object) array('data' => $cached_paths)));
     // Simulate a request so that the preloaded paths are fetched.
     $this->aliasManager->setCacheKey($this->path);
     $this->aliasWhitelist->expects($this->any())->method('get')->with($path_part1)->will($this->returnValue(TRUE));
     $this->aliasStorage->expects($this->once())->method('preloadPathAlias')->with($cached_paths[$language->getId()], $language->getId())->will($this->returnValue(array($cached_path => $cached_alias)));
     $this->aliasStorage->expects($this->once())->method('lookupPathAlias')->with($path, $language->getId())->will($this->returnValue($new_alias));
     $this->assertEquals($new_alias, $this->aliasManager->getAliasByPath($path));
     // Call it twice to test the static cache.
     $this->assertEquals($new_alias, $this->aliasManager->getAliasByPath($path));
     // This needs to write out the cache.
     $expected_new_cache = array($language->getId() => array($cached_path, $path, $cached_no_alias_path));
     $this->cache->expects($this->once())->method('set')->with($this->cacheKey, $expected_new_cache, (int) $_SERVER['REQUEST_TIME'] + 60 * 60 * 24);
     $this->aliasManager->writeCache();
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:31,代码来源:AliasManagerTest.php

示例8: testGenerateNoCache

 /**
  * Tests the generate method with no cache returned.
  */
 public function testGenerateNoCache()
 {
     // Set expectations for the mocked cache backend.
     $expected_cid = 'user_permissions_hash:administrator,authenticated';
     $this->cache->expects($this->once())->method('get')->with($expected_cid)->will($this->returnValue(FALSE));
     $this->cache->expects($this->once())->method('set')->with($expected_cid, $this->isType('string'));
     $this->permissionsHash->generate($this->account_1);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:11,代码来源:PermissionsHashTest.php

示例9: testPostDelete

 /**
  * @covers ::postDelete
  */
 public function testPostDelete()
 {
     $this->cacheBackend->expects($this->once())->method('invalidateTags')->with(array($this->entityTypeId . ':' . $this->values['id'], $this->entityTypeId . '_list'));
     $storage = $this->getMock('\\Drupal\\Core\\Entity\\EntityStorageInterface');
     $storage->expects($this->once())->method('getEntityType')->willReturn($this->entityType);
     $entities = array($this->values['id'] => $this->entity);
     $this->entity->postDelete($storage, $entities);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:11,代码来源:EntityUnitTest.php

示例10: testGetFieldMapFromCache

 /**
  * @covers ::getFieldMap
  */
 public function testGetFieldMapFromCache()
 {
     $expected = array('test_entity_type' => array('id' => array('type' => 'integer', 'bundles' => array('first_bundle', 'second_bundle')), 'by_bundle' => array('type' => 'string', 'bundles' => array('second_bundle'))));
     $this->setUpEntityManager();
     $this->cacheBackend->expects($this->once())->method('get')->with('entity_field_map')->will($this->returnValue((object) array('data' => $expected)));
     // Call the field map twice to make sure the static cache works.
     $this->assertEquals($expected, $this->entityManager->getFieldMap());
     $this->assertEquals($expected, $this->entityManager->getFieldMap());
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:12,代码来源:EntityManagerTest.php

示例11: testPostDelete

 /**
  * @covers ::postDelete
  */
 public function testPostDelete()
 {
     $this->cacheBackend->expects($this->once())->method('invalidateTags')->with(array($this->entityTypeId => array($this->values['id']), $this->entityTypeId . 's' => TRUE));
     $storage = $this->getMock('\\Drupal\\Core\\Entity\\EntityStorageInterface');
     $entity = $this->getMockBuilder('\\Drupal\\Core\\Entity\\Entity')->setConstructorArgs(array($this->values, $this->entityTypeId))->setMethods(array('onSaveOrDelete'))->getMock();
     $entity->expects($this->once())->method('onSaveOrDelete');
     $entities = array($this->values['id'] => $entity);
     $this->entity->postDelete($storage, $entities);
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:12,代码来源:EntityUnitTest.php

示例12: testGetContextualLinkPluginsByGroupWithCache

 /**
  * Tests the getContextualLinkPluginsByGroup method with a prefilled cache.
  */
 public function testGetContextualLinkPluginsByGroupWithCache()
 {
     $definitions = array('test_plugin1' => array('id' => 'test_plugin1', 'class' => '\\Drupal\\Core\\Menu\\ContextualLinkDefault', 'group' => 'group1', 'route_name' => 'test_route'), 'test_plugin2' => array('id' => 'test_plugin2', 'class' => '\\Drupal\\Core\\Menu\\ContextualLinkDefault', 'group' => 'group1', 'route_name' => 'test_route2'));
     $this->cacheBackend->expects($this->once())->method('get')->with('contextual_links_plugins:en:group1')->will($this->returnValue((object) array('data' => $definitions)));
     $result = $this->contextualLinkManager->getContextualLinkPluginsByGroup('group1');
     $this->assertEquals($definitions, $result);
     // Ensure that the static cache works, so no second cache get is executed.
     $result = $this->contextualLinkManager->getContextualLinkPluginsByGroup('group1');
     $this->assertEquals($definitions, $result);
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:13,代码来源:ContextualLinkManagerTest.php

示例13: testGetInfo

 /**
  * @covers ::getInfo
  */
 public function testGetInfo()
 {
     $token_info = array('types' => array('foo' => array('name' => $this->randomMachineName())));
     $this->language->expects($this->atLeastOnce())->method('getId')->will($this->returnValue($this->randomMachineName()));
     $this->languageManager->expects($this->once())->method('getCurrentLanguage')->with(LanguageInterface::TYPE_CONTENT)->will($this->returnValue($this->language));
     // The persistent cache must only be hit once, after which the info is
     // cached statically.
     $this->cache->expects($this->once())->method('get');
     $this->cache->expects($this->once())->method('set')->with('token_info:' . $this->language->getId(), $token_info);
     $this->moduleHandler->expects($this->once())->method('invokeAll')->with('token_info')->will($this->returnValue($token_info));
     $this->moduleHandler->expects($this->once())->method('alter')->with('token_info', $token_info);
     // Get the information for the first time. The cache should be checked, the
     // hooks invoked, and the info should be set to the cache should.
     $this->token->getInfo();
     // Get the information for the second time. The data must be returned from
     // the static cache, so the persistent cache must not be accessed and the
     // hooks must not be invoked.
     $this->token->getInfo();
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:22,代码来源:TokenTest.php

示例14: testGetAllEqualsToGetNull

 /**
  * Tests that getting all data has same results as getting data with NULL
  * logic.
  *
  * @covers ::getAll
  */
 public function testGetAllEqualsToGetNull()
 {
     $expected_views_data = $this->viewsDataWithProvider();
     $this->setupMockedModuleHandler();
     // Setup a warm cache backend for a single table.
     $this->cacheBackend->expects($this->once())->method('get')->with("views_data:en");
     $this->cacheBackend->expects($this->once())->method('set')->with('views_data:en', $expected_views_data);
     // Initialize the views data cache and repeat with no specified table. This
     // should only load the cache entry for all tables.
     for ($i = 0; $i < 5; $i++) {
         $this->assertSame($expected_views_data, $this->viewsData->getAll());
         $this->assertSame($expected_views_data, $this->viewsData->get());
     }
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:20,代码来源:ViewsDataTest.php

示例15: testResetImplementations

 /**
  * Test internal implementation cache reset.
  *
  * @covers ::resetImplementations()
  */
 public function testResetImplementations()
 {
     // Prime caches
     $this->moduleHandler->getImplementations('hook');
     $this->moduleHandler->getHookInfo();
     // Reset all caches internal and external.
     $this->cacheBackend->expects($this->once())->method('delete')->with('hook_info');
     $this->cacheBackend->expects($this->exactly(2))->method('set')->with($this->logicalOr('module_implements', 'hook_info'));
     $this->moduleHandler->resetImplementations();
     // Request implementation and ensure hook_info and module_implements skip
     // local caches.
     $this->cacheBackend->expects($this->exactly(2))->method('get')->with($this->logicalOr('module_implements', 'hook_info'));
     $this->moduleHandler->getImplementations('hook');
 }
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:19,代码来源:ModuleHandlerTest.php


注:本文中的Drupal\Core\Cache\CacheBackendInterface::expects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。