class TestDiscoveryCacheContextTest
@group simpletest @group legacy
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\AssertHelperTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\PhpunitCompatibilityTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\simpletest\Kernel\Cache\Context\TestDiscoveryCacheContextTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of TestDiscoveryCacheContextTest
File
-
core/
modules/ simpletest/ tests/ src/ Kernel/ Cache/ Context/ TestDiscoveryCacheContextTest.php, line 13
Namespace
Drupal\Tests\simpletest\Kernel\Cache\ContextView source
class TestDiscoveryCacheContextTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'simpletest',
];
/**
* Tests that test context hashes are unique.
*
* @expectedDeprecation Drupal\simpletest\TestDiscovery is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\TestDiscovery instead. See https://www.drupal.org/node/2949692
*/
public function testContext() {
// Mock test discovery.
$discovery = $this->getMockBuilder(TestDiscovery::class)
->setMethods([
'getTestClasses',
])
->disableOriginalConstructor()
->getMock();
// Set getTestClasses() to return different results on subsequent calls.
// This emulates changed tests in the filesystem.
$discovery->expects($this->any())
->method('getTestClasses')
->willReturnOnConsecutiveCalls([
'group1' => [
'Test',
],
], [
'group2' => [
'Test2',
],
]);
// Make our cache context object.
$cache_context = new TestDiscoveryCacheContext($discovery, $this->container
->get('private_key'));
// Generate a context hash.
$context_hash = $cache_context->getContext();
// Since the context stores the hash, we have to reset it.
$hash_ref = new \ReflectionProperty($cache_context, 'hash');
$hash_ref->setAccessible(TRUE);
$hash_ref->setValue($cache_context, NULL);
// And then assert that we did not generate the same hash for different
// content.
$this->assertNotSame($context_hash, $cache_context->getContext());
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
TestDiscoveryCacheContextTest::$modules | public static | property | |
TestDiscoveryCacheContextTest::testContext | public | function | Tests that test context hashes are unique. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.